Skip to Content
Cloud Engineering Academy
2. AWS Networking & Infrastructure

Route tables and the internet gateway

Read any VPC route table like a network engineer, predict which route a packet takes with longest-prefix matching, attach an internet gateway safely, and explain a route decision with a C# tool.

beginner⏱ 1 h 15 min🟢 FreeSAA-C03SOA-C03SCS-C03

Assumes: AWS CLI v2 · AWS SDK for .NET v4 (AWSSDK.EC2 4.1.4) · .NET 10 LTS · CDK v2 (Amazon.CDK.Lib 2.277.0) · Terraform AWS provider v6 · Region us-east-1. Verified against official sources on 2026-11-18.

Learning objectives

By the end of this lesson you can:

  • Read a route table: destination, target, state, origin and propagation, and explain the local route.
  • Predict the route a packet uses with longest-prefix match and the tie-break rules (static, prefix list, propagated).
  • Explain what an internet gateway does (including one-to-one NAT for public IPv4) and the four conditions for an instance to reach the internet.
  • Add an internet gateway, an IPv6 egress-only internet gateway and routes with the console, CLI, CDK and Terraform.
  • Describe gateway route tables (ingress routing) and routes more specific than local for inspection appliances.
  • Run a C# "route explainer" that tells you which route a subnet would use for any destination address.

Prerequisites

Why this matters in banking

During an incident call, "the payments service can't reach the core banking API" is usually a routing question before it is anything else. The engineer who can open the route table, find the destination, apply longest-prefix match in their head and say "traffic to 10.8.4.20 goes to the Transit Gateway, but the return route on the other side is missing" ends the call in five minutes. The engineer who cannot keeps restarting containers.

Routes are also the strongest network control you have. A security group can be loosened by one bad rule; a subnet with no route to the internet cannot reach the internet whatever its security groups say. Harbourline's security architecture therefore reviews route changes with the same care as firewall changes, and the network team owns the route tables in the shared network account.

The idea in plain language

Every VPC has an invisible implied router. A route table is the rule book that router follows for traffic leaving a subnet: "for packets going here, send them there". Each subnet is associated with exactly one route table.

Analogy: a route table is the signpost at the end of a corridor in the branch building. "Floors 1–10 (the whole building): take the stairs" is the local route. "Everything else: main entrance" is the default route to the internet gateway. If a sign says "Head office, 10.8.0.0/16: use the private tunnel", that more specific sign wins over "everything else" for anyone carrying a parcel for head office.

Anatomy of a route

ColumnMeaningExample
DestinationA CIDR block (IPv4 or IPv6) or a prefix list ID0.0.0.0/0, 10.8.0.0/16, pl-63a5400a
TargetWhere matching packets golocal, igw-…, nat-…, tgw-…, pcx-…, vpce-…, eni-…, eigw-…, vgw-…
Stateactive or blackhole (target deleted or unavailable)A deleted NAT gateway leaves a blackhole
OriginWho created it: CreateRouteTable (the local route), CreateRoute (you), EnableVgwRoutePropagation (learned from VPN/Direct Connect)
PropagatedWhether a gateway added it dynamicallyYes for BGP-learned on-premises ranges

The local route

Every route table has a local route for each VPC CIDR block (IPv4 and IPv6). It means "deliver inside the VPC". You cannot delete it. This is why every subnet can reach every other subnet in a VPC unless security groups or NACLs say otherwise. You can add a route that is more specific than local — for example 10.20.64.0/20 → eni-… of a firewall — to force traffic between two subnets through an inspection appliance.

How a route is chosen

  1. Longest prefix wins. For a packet to 10.8.4.20, a route for 10.8.4.0/24 beats 10.8.0.0/16, which beats 0.0.0.0/0. IPv4 and IPv6 are matched independently.
  2. If the destinations are identical, AWS prefers static routes (internet gateway, NAT gateway, network interface, gateway endpoint, Transit Gateway, peering, Gateway Load Balancer endpoint) over prefix-list routes, and prefix-list routes over propagated ones (Direct Connect BGP, then VPN static, then VPN BGP).
  3. No match → dropped. There is no implicit default route in a custom route table.

The internet gateway

An internet gateway (IGW) is the VPC's door to the internet. Facts worth memorising:

  • It is horizontally scaled and redundant: it is not a box in one AZ, it does not constrain bandwidth, and you never size it.
  • One IGW per VPC at a time; one VPC per IGW.
  • It is free. You pay for data transfer out to the internet and for public IPv4 addresses (USD 0.005 per address per hour), not for the gateway.
  • For IPv4 it performs one-to-one NAT: the instance only knows its private address; the IGW swaps it for the instance's public IPv4 or Elastic IP on the way out and back on the way in.
  • For IPv6, addresses are globally unique, so no NAT happens. For outbound-only IPv6, use an egress-only internet gateway (eigw-…), the IPv6 equivalent of a NAT gateway (and free apart from data transfer).

For an EC2 instance to talk to the internet over IPv4, all four must be true:

  1. An IGW is attached to the VPC.
  2. The subnet's route table has a route to the IGW covering the destination.
  3. The instance has a public IPv4 address or Elastic IP.
  4. Security groups and network ACLs allow the traffic (both directions for NACLs).

Remove any one and the path breaks — which is useful when you are designing which ones to remove.

What problem route tables solve

Route tables let one VPC hold several trust zones with different ways in and out, and let you insert controls (NAT, firewalls, endpoints, Transit Gateway) without changing application code. Applications just open a connection; routing decides the path.

Gateway route tables (ingress routing)

Normally a route table is associated with subnets. A gateway route table is associated with an internet gateway or virtual private gateway instead (an edge association). It decides where traffic entering the VPC through that gateway goes first. Banks use it to send all inbound internet traffic through an inspection appliance or a Gateway Load Balancer endpoint before it reaches the public subnet. You will meet this pattern again with Elastic Load Balancing (Gateway Load Balancer) and in this module's Network Firewall lesson.

Limits and sharp edges (checked 2026-11-18)

QuotaDefaultAdjustable
Route tables per VPC200 (includes the main table)Yes
Non-propagated routes per route table500 (separately for IPv4 and IPv6)Yes, up to 1,000
Propagated routes per route table100No — advertise a summary or default route instead
Internet gateways per Region5 (rises with the VPC quota)Yes
Egress-only internet gateways per Region5Yes
Elastic IP addresses per Region5Yes
  • A prefix list counts at its maximum size against the route quota, not its current number of entries.
  • Routes are not transitive through peering or gateways. A route to a peering connection does not let traffic continue to whatever the peer can reach. That is the reason Transit Gateway exists (VPC peering and Transit Gateway, lesson 12 of this module).
  • Return traffic needs a route too. On the far side (on-premises, another VPC) there must be a route back to your CIDR. Asymmetric or missing return routes are the most common hybrid connectivity fault.

Microsoft / Azure comparison

You know (Microsoft/Azure)AWS equivalentWhat's different
System routes in a VNetlocal route (plus nothing else in a custom VPC)Azure adds a default internet system route; a custom AWS VPC has no internet route until you add one
User-defined route (UDR) tableRoute tableOne route table per subnet in both; AWS also has a "main" table for unassociated subnets
Next hop type InternetTarget igw-…You must create and attach the IGW object first
Next hop VirtualApplianceTarget eni-… or a Gateway Load Balancer endpoint vpce-…Routes more specific than local are allowed for east-west inspection
Next hop VirtualNetworkGateway + BGP propagationTarget vgw-…/tgw-… with route propagationPropagated routes are marked and have lower priority than static ones on ties
Service tags in routesManaged prefix lists (pl-…)AWS-managed prefix lists exist for S3, DynamoDB, CloudFront origin-facing ranges and more
Public IP SKUPublic IPv4 / Elastic IPEvery public IPv4 address bills hourly, attached or not
Effective routes blade (Network Watcher)Subnet → Route table tab; VPC Reachability AnalyzerReachability Analyzer explains a full path including SGs and NACLs

Architecture

Security-boundary view: route tables are where trust zones are physically separated. Only hl-m02-public-rt points at the internet gateway; the app table's only ways out are gateway endpoints (governed by endpoint policies) and, for IPv6, an outbound-only gateway; the data table has none. Changes to these tables should be as tightly controlled as firewall changes, and VPC Flow Logs plus Reachability Analyzer prove the result.

Step-by-step implementation

Create and attach an internet gateway

Create hl-m02-igw and attach it to hl-m02-vpc. Attaching alone changes nothing: no route points at it yet.

Add the default route to the public route table only

0.0.0.0/0 → igw-… in hl-m02-public-rt. The two public subnets are now public; the others are untouched because they use different tables.

Check the main route table is still local-only

The main table is the fallback for unassociated subnets. It must not get the IGW route.

Explain a few destinations

Run the route explainer for a public and a data subnet against 8.8.8.8, 10.20.130.5 and an S3 address. Compare the chosen routes with your own prediction.

Optional: add IPv6 and an egress-only gateway

Associate an Amazon-provided IPv6 /56 with the VPC, give the app subnets /64s, create an egress-only internet gateway and add ::/0 → eigw-… to the app table. App resources can now start IPv6 connections out, but nothing can start one in.

AWS Console instructions

  • VPC → Internet gateways → Create internet gateway. Name hl-m02-igw, add the four mandatory tags → Create. Then Actions → Attach to VPC → hl-m02-vpc.
  • VPC → Route tables → hl-m02-public-rt → Routes tab → Edit routes → Add route. Destination 0.0.0.0/0, Target Internet Gateway → hl-m02-igw → Save changes.
  • Check the main table: Route tables, filter by VPC, the one with Main = Yes should show only the local route.
  • VPC → Subnets → select a subnet → Route table tab shows the effective routes for that subnet.
  • Gateway route table: Route tables → select a table → Edge associations → Edit edge associations → choose the internet gateway. (Only do this when you have an appliance to route to.)
  • Reachability Analyzer: VPC → Network Analysis → Reachability Analyzer → Create and analyze path — source hl-m02-igw, destination a network interface in a data subnet. Expect Not reachable with an explanation that no route exists ⚠ VERIFY exact menu label. Each analysis costs USD 0.10.

AWS CLI

$p = "--profile", "learn-sandbox", "--region", "us-east-1"
$tags = "{Key=Project,Value=cea-lab},{Key=Lab,Value=m02-secure-vpc},{Key=Environment,Value=learn},{Key=Owner,Value=alex}"
$vpcId = aws ec2 describe-vpcs --filters Name=tag:Name,Values=hl-m02-vpc @p --query "Vpcs[0].VpcId" --output text

# 1. Create and attach the internet gateway
$igwId = aws ec2 create-internet-gateway @p `
  --tag-specifications "ResourceType=internet-gateway,Tags=[{Key=Name,Value=hl-m02-igw},$tags]" `
  --query InternetGateway.InternetGatewayId --output text
aws ec2 attach-internet-gateway --internet-gateway-id $igwId --vpc-id $vpcId @p

# 2. Default route in the PUBLIC table only
$publicRt = aws ec2 describe-route-tables @p `
  --filters Name=vpc-id,Values=$vpcId Name=tag:Name,Values=hl-m02-public-rt `
  --query "RouteTables[0].RouteTableId" --output text
aws ec2 create-route --route-table-id $publicRt --destination-cidr-block 0.0.0.0/0 --gateway-id $igwId @p

# 3. Print every route table in the VPC with its routes
aws ec2 describe-route-tables --filters Name=vpc-id,Values=$vpcId @p `
  --query "RouteTables[].{Name:Tags[?Key=='Name']|[0].Value,Routes:Routes[].[DestinationCidrBlock||DestinationPrefixListId||DestinationIpv6CidrBlock,GatewayId||NatGatewayId||TransitGatewayId||NetworkInterfaceId,State]}" `
  --output json

# 4. Which subnets have no explicit association (they use the main table)?
$assoc = aws ec2 describe-route-tables --filters Name=vpc-id,Values=$vpcId @p `
  --query "RouteTables[].Associations[].SubnetId" --output text
aws ec2 describe-subnets --filters Name=vpc-id,Values=$vpcId @p --query "Subnets[].SubnetId" --output text |
  ForEach-Object { $_ -split "\s+" } | Where-Object { $_ -and ($assoc -notmatch $_) }

# 5. AWS-managed prefix lists (for example S3 in us-east-1) and their entries
aws ec2 describe-managed-prefix-lists @p --filters Name=owner-id,Values=AWS `
  --query "PrefixLists[].[PrefixListId,PrefixListName,MaxEntries]" --output table

# 6. Optional IPv6: Amazon-provided /56 and an egress-only internet gateway
# aws ec2 associate-vpc-cidr-block --vpc-id $vpcId --amazon-provided-ipv6-cidr-block @p
# $eigw = aws ec2 create-egress-only-internet-gateway --vpc-id $vpcId @p --query EgressOnlyInternetGateway.EgressOnlyInternetGatewayId --output text
# aws ec2 create-route --route-table-id <app-rt> --destination-ipv6-cidr-block ::/0 --egress-only-internet-gateway-id $eigw @p

Read step 3's output top-down for each table and say aloud where 8.8.8.8, 10.20.130.5 and 10.8.4.20 would go. That habit is the whole skill.

Infrastructure as Code

The L2 Vpc construct from the previous lesson already creates the IGW and the public default routes. When you need explicit control — for example a route to an on-premises range through a Transit Gateway — add L1 routes:

RoutesStack.cs
using Amazon.CDK;
using Amazon.CDK.AWS.EC2;
using Constructs;

namespace Harbourline.Networking.Examples;

public sealed class RoutesStack : Stack
{
    public RoutesStack(Construct scope, string id, IVpc vpc, string transitGatewayId, IStackProps? props = null)
        : base(scope, id, props)
    {
        // Send the on-premises core banking range from every app subnet to the Transit Gateway.
        var appSubnets = vpc.SelectSubnets(new SubnetSelection { SubnetGroupName = "app" });
        for (var i = 0; i < appSubnets.Subnets.Length; i++)
        {
            _ = new CfnRoute(this, $"OnPremRoute{i}", new CfnRouteProps
            {
                RouteTableId = appSubnets.Subnets[i].RouteTable.RouteTableId,
                DestinationCidrBlock = "10.8.0.0/16",
                TransitGatewayId = transitGatewayId,
            });
        }

        // Expose which route table each data subnet uses, for the CI assertion tests.
        var dataSubnets = vpc.SelectSubnets(new SubnetSelection { SubnetGroupName = "data" });
        for (var i = 0; i < dataSubnets.Subnets.Length; i++)
        {
            _ = new CfnOutput(this, $"DataRouteTable{i}", new CfnOutputProps
            {
                Value = dataSubnets.Subnets[i].RouteTable.RouteTableId,
            });
        }
    }
}

The lab's CDK tests (labs/m02-secure-vpc/tests/…Cdk.Tests) use Template.FromStack(...) assertions to prove that no AWS::EC2::Route with a GatewayId or NatGatewayId targets a data-tier route table. That is a route-table unit test: it fails the pull request before anything reaches AWS.

Complete code

A route explainer: give it a subnet ID and a destination address; it loads the subnet's effective route table, expands prefix lists, applies longest-prefix match plus the tie-break rules, and prints the winning route and why.

RouteExplainer.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="AWSSDK.EC2" Version="4.1.4" />
    <PackageReference Include="AWSSDK.SSO" Version="4.1.0.2" />
    <PackageReference Include="AWSSDK.SSOOIDC" Version="4.1.0.2" />
  </ItemGroup>
</Project>
Program.cs
using System.Net;
using Amazon;
using Amazon.EC2;
using Amazon.EC2.Model;

// Usage:  $env:AWS_PROFILE = "learn-sandbox"; dotnet run -- subnet-0123456789abcdef0 10.20.130.5
if (args.Length != 2 || !IPAddress.TryParse(args[1], out var destination))
{
    Console.Error.WriteLine("Usage: RouteExplainer <subnet-id> <destination-ip>");
    return 2;
}

var subnetId = args[0];
using var ec2 = new AmazonEC2Client(RegionEndpoint.USEast1);

// 1. Find the effective route table: explicit association first, otherwise the VPC's main table.
var subnet = (await ec2.DescribeSubnetsAsync(new DescribeSubnetsRequest { SubnetIds = [subnetId] })).Subnets![0];
var explicitTables = await ec2.DescribeRouteTablesAsync(new DescribeRouteTablesRequest
{
    Filters = [new Filter { Name = "association.subnet-id", Values = [subnetId] }],
});
var table = explicitTables.RouteTables?.FirstOrDefault();
var isMain = false;
if (table is null)
{
    var mainTables = await ec2.DescribeRouteTablesAsync(new DescribeRouteTablesRequest
    {
        Filters =
        [
            new Filter { Name = "vpc-id", Values = [subnet.VpcId] },
            new Filter { Name = "association.main", Values = ["true"] },
        ],
    });
    table = mainTables.RouteTables![0];
    isMain = true;
}

Console.WriteLine($"Subnet {subnetId} uses {table.RouteTableId}{(isMain ? " (MAIN table, implicit)" : "")}");

// 2. Turn every route into one or more (network, route) candidates. Prefix lists expand to many CIDRs.
var candidates = new List<(IPNetwork Network, Route Route, int Rank)>();
foreach (var route in table.Routes ?? [])
{
    if (route.DestinationCidrBlock is { } v4)
    {
        candidates.Add((IPNetwork.Parse(v4), route, RankOf(route)));
    }
    else if (route.DestinationIpv6CidrBlock is { } v6)
    {
        candidates.Add((IPNetwork.Parse(v6), route, RankOf(route)));
    }
    else if (route.DestinationPrefixListId is { } pl)
    {
        foreach (var cidr in await PrefixListCidrsAsync(ec2, pl))
        {
            candidates.Add((IPNetwork.Parse(cidr), route, RankOf(route)));
        }
    }
}

// 3. Longest prefix first; on equal prefixes the lower rank wins (static < prefix list < propagated).
var matches = candidates
    .Where(c => c.Network.BaseAddress.AddressFamily == destination.AddressFamily && c.Network.Contains(destination))
    .OrderByDescending(c => c.Network.PrefixLength)
    .ThenBy(c => c.Rank)
    .ToList();

if (matches.Count == 0)
{
    Console.WriteLine($"No route matches {destination}: the packet is DROPPED by the VPC router.");
    return 1;
}

var winner = matches[0];
Console.WriteLine($"Destination {destination} -> {TargetOf(winner.Route)} via {Describe(winner)}");
if (winner.Route.State == RouteState.Blackhole)
{
    Console.WriteLine("  BLACKHOLE: the target no longer exists, so the packet is dropped.");
}

foreach (var loser in matches.Skip(1))
{
    Console.WriteLine($"  also matched, lost: {Describe(loser)} -> {TargetOf(loser.Route)}");
}

if (destination.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6 && !matches.Any(m => m.Network.PrefixLength == 0))
{
    Console.WriteLine("  Note: IPv6 routes are separate from IPv4; a 0.0.0.0/0 route does not cover IPv6.");
}

return 0;

static int RankOf(Route r) =>
    r.Origin == RouteOrigin.EnableVgwRoutePropagation ? 2 :
    r.DestinationPrefixListId is not null ? 1 : 0;

static string Describe((IPNetwork Network, Route Route, int Rank) c) =>
    $"{c.Network} ({(c.Route.DestinationPrefixListId is { } pl ? $"prefix list {pl}, " : "")}{c.Route.Origin}, {c.Route.State})";

static string TargetOf(Route r) =>
    r.GatewayId ?? r.NatGatewayId ?? r.TransitGatewayId ?? r.VpcPeeringConnectionId ??
    r.NetworkInterfaceId ?? r.EgressOnlyInternetGatewayId ?? r.InstanceId ?? r.LocalGatewayId ??
    r.CarrierGatewayId ?? r.CoreNetworkArn ?? "(unknown target)";

static async Task<List<string>> PrefixListCidrsAsync(IAmazonEC2 ec2, string prefixListId)
{
    var cidrs = new List<string>();
    string? token = null;
    do
    {
        var page = await ec2.GetManagedPrefixListEntriesAsync(new GetManagedPrefixListEntriesRequest
        {
            PrefixListId = prefixListId,
            NextToken = token,
        });
        cidrs.AddRange((page.Entries ?? []).Select(e => e.Cidr));
        token = page.NextToken;
    }
    while (!string.IsNullOrEmpty(token));

    return cidrs;
}

Example runs against the lab VPC after this lesson's steps:

> dotnet run -- subnet-0a1… 8.8.8.8
Subnet subnet-0a1… uses rtb-01f…
Destination 8.8.8.8 -> igw-0c9… via 0.0.0.0/0 (CreateRoute, active)

> dotnet run -- subnet-0c3… 8.8.8.8
Subnet subnet-0c3… uses rtb-07a…
No route matches 8.8.8.8: the packet is DROPPED by the VPC router.

> dotnet run -- subnet-0a1… 10.20.130.5
Subnet subnet-0a1… uses rtb-01f…
Destination 10.20.130.5 -> local via 10.20.0.0/16 (CreateRouteTable, active)
  also matched, lost: 0.0.0.0/0 (CreateRoute, active) -> igw-0c9…

Code explained line by line

  1. IPAddress.TryParse(args[1], out var destination) — validates input early; works for IPv4 and IPv6.
  2. Filter { Name = "association.subnet-id", ... } — asks EC2 for the table explicitly associated with this subnet. An empty result means the subnet uses the main table.
  3. association.main = true with the subnet's VpcId — finds the main table, exactly as AWS does for unassociated subnets.
  4. IPNetwork.Parse(...) — System.Net.IPNetwork (built into .NET 8 and later) parses CIDR strings and offers Contains(IPAddress) and PrefixLength. No third-party IP library needed.
  5. PrefixListCidrsAsync — a route to pl-… (for example the S3 gateway endpoint route) covers every CIDR in the list. GetManagedPrefixListEntries returns them, paged with NextToken.
  6. RankOf(...) — encodes the tie-break: static routes (rank 0) beat prefix-list routes (1), which beat propagated routes (2), only when prefixes are the same length. This is a simplification: within propagated routes AWS further prefers Direct Connect BGP over VPN static over VPN BGP.
  7. .OrderByDescending(c => c.Network.PrefixLength).ThenBy(c => c.Rank) — longest prefix match, then tie-break. Two lines of LINQ capture the routing algorithm.
  8. c.Network.BaseAddress.AddressFamily == destination.AddressFamily — IPv4 and IPv6 tables are separate; an IPv4 route can never match an IPv6 address.
  9. TargetOf(...) — a route has exactly one target property set; GatewayId covers local, igw-, vgw- and gateway-endpoint vpce- targets.
  10. RouteState.Blackhole — reported because a matching blackhole route still wins the match; the packet is then dropped rather than falling back to a less specific route.

The tool explains routing only. Security groups and NACLs can still block a routed packet — Reachability Analyzer checks all of them together.

Security considerations

  • Treat route changes as firewall changes. Restrict ec2:CreateRoute, ec2:ReplaceRoute, ec2:AttachInternetGateway and ec2:CreateInternetGateway to the network pipeline role; an SCP can deny IGW creation in workload accounts entirely.
  • Keep the main route table local-only and associate every subnet explicitly (Terraform's aws_default_route_table with route = [] enforces it).
  • Never fix "can't reach the internet" by adding an IGW route to a private or data table. Find out what the workload actually needs (usually AWS APIs → endpoints).
  • Use IPv6 deliberately. IPv6 addresses are globally routable: a ::/0 → igw route plus a permissive security group makes a resource reachable from the internet with no NAT in between. Use egress-only IGWs for outbound-only IPv6.
  • Log and verify. Flow Logs show what actually flowed; Reachability Analyzer and Network Access Analyzer prove what could flow.

⚠ Learning shortcut — not for production

In this lab you add the internet gateway and routes by hand in your own account. At Harbourline, workload accounts have no internet gateways at all: inbound internet traffic arrives in a central ingress VPC (owned by the network team, with AWS WAF and inspection), and the workload route tables live in a network account and are shared to application teams. Changes go through pull requests on the network IaC repository, with automated checks like the CDK assertion tests and this route explainer.

Banking use case

Harbourline's payments app subnets in eu-west-2 have this route table (simplified):

DestinationTargetWhy
10.40.0.0/16localThe payments VPC itself
pl-… (S3)vpce-…Gateway endpoint: statements and reports to S3, private and free
10.8.0.0/16tgw-…On-premises core banking, through Transit Gateway and Direct Connect
10.32.0.0/12tgw-…Other Harbourline VPCs, filtered by Transit Gateway route tables
0.0.0.0/0tgw-…Internet egress through a central egress VPC with AWS Network Firewall

Note what is missing: no IGW and no NAT gateway in the workload VPC. Every way out is a Transit Gateway route, so the network team controls and inspects all of it centrally (segmentation and egress control). When an incident ticket says "payments can't reach 10.8.4.20", the first step is the route explainer: it picks 10.8.0.0/16 → tgw, so the investigation moves to the Transit Gateway route table and the on-premises return route.

Common mistakes

  • Adding the IGW route to the main route table → every unassociated subnet becomes public → explicit associations and a local-only main table.
  • Forgetting that a more specific route wins → a /24 route to a peering connection silently takes traffic you expected to go to the Transit Gateway → read the whole table, not just the default route.
  • Deleting a NAT gateway or peering connection but not its routes → blackhole routes drop traffic with no error → clean up routes and alert on blackholes.
  • Assuming peering or VPN routes are transitive → traffic stops at the first hop → use Transit Gateway or explicit routes on each side.
  • Missing return route on the other side → SYN goes out, SYN-ACK never comes back → check both directions.
  • Assuming 0.0.0.0/0 covers IPv6 → it doesn't; IPv6 needs ::/0 → treat IPv6 routing as a separate table.

Troubleshooting

SymptomLikely causeFix
RouteAlreadyExists on create-routeSame destination already presentUse replace-route to change the target
InvalidGatewayID.NotFoundIGW not attached to this VPC, or wrong Regionaws ec2 describe-internet-gateways and attach it
Resource.AlreadyAssociated when attaching an IGWVPC already has an IGWOne IGW per VPC; reuse the existing one
Route state blackholeTarget deleted (NAT gateway, ENI, peering)Replace or delete the route
Public instance has no internet accessNo public IP, no IGW route, or SG/NACL blocksCheck all four conditions; Reachability Analyzer shows which one fails
DependencyViolation on detach-internet-gatewayPublic IPs/Elastic IPs still mapped in the VPCRelease Elastic IPs, delete NAT gateways and public load balancers first
Route quota exceeded when adding a prefix-list routePrefix list counted at its max sizeLower the prefix list's max entries or summarise routes

Cost and cleanup

Cost: USD 0 for route tables, routes, the internet gateway and the egress-only internet gateway. Reachability Analyzer is USD 0.10 per analysis if you try it. Costs start only when something has a public IPv4 address or sends data out.

Keep the VPC if you continue to the next lesson. To remove what this lesson added:

$p = "--profile", "learn-sandbox", "--region", "us-east-1"

# Remove the default route, then detach and delete the internet gateway
aws ec2 delete-route --route-table-id $publicRt --destination-cidr-block 0.0.0.0/0 @p
aws ec2 detach-internet-gateway --internet-gateway-id $igwId --vpc-id $vpcId @p
aws ec2 delete-internet-gateway --internet-gateway-id $igwId @p

# If you created the optional egress-only gateway
# aws ec2 delete-egress-only-internet-gateway --egress-only-internet-gateway-id $eigw @p

# Check: no Elastic IPs left behind (they bill even when unattached)
aws ec2 describe-addresses @p --query "Addresses[].[PublicIp,AllocationId,AssociationId]" --output table

Exercises

  • 🟢 Guided: Attach hl-m02-igw, add the default route to the public table, and run the route explainer for one subnet of each tier against 8.8.8.8 and 10.20.130.5. Record the six results and explain each.
  • 🟡 Challenge: Add a route 10.20.128.0/20 → <the IGW> to the public table (in the sandbox only) and predict what the explainer will say for 10.20.130.5 from a public subnet. Then try it — AWS will reject or accept it? Explain why, and remove it.
  • 🔴 Live problem: "Since this morning, payments in AZ b can't reach the sanctions-screening partner; AZ a is fine. Nothing was deployed." You have read-only access. Describe your investigation and the most likely causes.

Assignment

Add tools/route-explainer/ to your repository with the program, a README that explains longest-prefix match and the tie-break order in your own words, and three captured runs (public, app and data subnet). Bonus: add an --all flag that explains a list of "critical destinations" from a JSON file, so you can run it after every network change.

Solutions

Knowledge check

Interview questions

  • "Walk me through how a packet leaves an EC2 instance for the internet." — The instance sends to its private IP's default gateway (the implied router); the subnet's route table matches 0.0.0.0/0 → igw; the IGW swaps the private source address for the instance's public IPv4; the reply comes back to the public IP and is translated back. SGs and NACLs are checked on the way.
  • "Why isn't VPC peering transitive?" — Routing in a VPC only delivers to targets directly attached to it; a peering connection doesn't forward traffic onwards to the peer's own peers, VPNs or gateways. For hub-and-spoke you use Transit Gateway.
  • "How would you force traffic between two subnets through a firewall?" — Add routes more specific than local in both subnets' route tables pointing to the firewall's ENI or Gateway Load Balancer endpoint, symmetrically, so both directions are inspected.
  • "What does a blackhole route mean?" — The route's target no longer exists. Traffic matching it is dropped; it does not fall back to a less specific route.

Certification practice

Completion checklist

  • I can read a route table and predict the route for any address
  • I attached an internet gateway and added the default route to the public table only
  • I confirmed the main route table is local-only
  • I ran the route explainer for each tier
  • I removed the IGW (or kept the VPC for the next lesson) and checked for leftover Elastic IPs

Key takeaways

  • Each subnet follows exactly one route table; the local route connects everything inside the VPC.
  • Longest prefix wins; static beats prefix-list beats propagated only on equal prefixes; no match means drop.
  • The internet gateway is free, scaled and redundant; it does one-to-one NAT for public IPv4 and nothing for IPv6.
  • Internet access needs four things: an attached IGW, a route, a public address, and permissive SG/NACL rules.
  • Route tables are a security control: keep the main table local-only and treat route changes as firewall changes.

Further reading

Next: NAT gateway and egress.

Independent learning resource — not affiliated with, endorsed or sponsored by Amazon Web Services. AWS and related marks are trademarks of Amazon.com, Inc. or its affiliates. All banking data in examples is fictional. Sample architectures are for learning and are not automatically compliant with GDPR, PCI DSS or any banking regulation.

On this page