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.
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
localroute. - 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
localfor inspection appliances. - Run a C# "route explainer" that tells you which route a subnet would use for any destination address.
Prerequisites
- Public, private and isolated subnets — the three-tier layout and its three route tables.
- Networking refresher — CIDR prefixes and how
/16and/24relate. - Tools: AWS CLI v2 (
learn-sandboxprofile), .NET 10 SDK.
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
localroute. "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
| Column | Meaning | Example |
|---|---|---|
| Destination | A CIDR block (IPv4 or IPv6) or a prefix list ID | 0.0.0.0/0, 10.8.0.0/16, pl-63a5400a |
| Target | Where matching packets go | local, igw-…, nat-…, tgw-…, pcx-…, vpce-…, eni-…, eigw-…, vgw-… |
| State | active or blackhole (target deleted or unavailable) | A deleted NAT gateway leaves a blackhole |
| Origin | Who created it: CreateRouteTable (the local route), CreateRoute (you), EnableVgwRoutePropagation (learned from VPN/Direct Connect) | |
| Propagated | Whether a gateway added it dynamically | Yes 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
- Longest prefix wins. For a packet to
10.8.4.20, a route for10.8.4.0/24beats10.8.0.0/16, which beats0.0.0.0/0. IPv4 and IPv6 are matched independently. - 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).
- 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:
- An IGW is attached to the VPC.
- The subnet's route table has a route to the IGW covering the destination.
- The instance has a public IPv4 address or Elastic IP.
- 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)
| Quota | Default | Adjustable |
|---|---|---|
| Route tables per VPC | 200 (includes the main table) | Yes |
| Non-propagated routes per route table | 500 (separately for IPv4 and IPv6) | Yes, up to 1,000 |
| Propagated routes per route table | 100 | No — advertise a summary or default route instead |
| Internet gateways per Region | 5 (rises with the VPC quota) | Yes |
| Egress-only internet gateways per Region | 5 | Yes |
| Elastic IP addresses per Region | 5 | Yes |
- 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 equivalent | What's different |
|---|---|---|
| System routes in a VNet | local 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) table | Route table | One route table per subnet in both; AWS also has a "main" table for unassociated subnets |
Next hop type Internet | Target igw-… | You must create and attach the IGW object first |
Next hop VirtualAppliance | Target eni-… or a Gateway Load Balancer endpoint vpce-… | Routes more specific than local are allowed for east-west inspection |
Next hop VirtualNetworkGateway + BGP propagation | Target vgw-…/tgw-… with route propagation | Propagated routes are marked and have lower priority than static ones on ties |
| Service tags in routes | Managed prefix lists (pl-…) | AWS-managed prefix lists exist for S3, DynamoDB, CloudFront origin-facing ranges and more |
| Public IP SKU | Public IPv4 / Elastic IP | Every public IPv4 address bills hourly, attached or not |
| Effective routes blade (Network Watcher) | Subnet → Route table tab; VPC Reachability Analyzer | Reachability 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. Destination0.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
localroute. - 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 @pRead 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:
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.
<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>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
IPAddress.TryParse(args[1], out var destination)— validates input early; works for IPv4 and IPv6.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.association.main = truewith the subnet'sVpcId— finds the main table, exactly as AWS does for unassociated subnets.IPNetwork.Parse(...)—System.Net.IPNetwork(built into .NET 8 and later) parses CIDR strings and offersContains(IPAddress)andPrefixLength. No third-party IP library needed.PrefixListCidrsAsync— a route topl-…(for example the S3 gateway endpoint route) covers every CIDR in the list.GetManagedPrefixListEntriesreturns them, paged withNextToken.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..OrderByDescending(c => c.Network.PrefixLength).ThenBy(c => c.Rank)— longest prefix match, then tie-break. Two lines of LINQ capture the routing algorithm.c.Network.BaseAddress.AddressFamily == destination.AddressFamily— IPv4 and IPv6 tables are separate; an IPv4 route can never match an IPv6 address.TargetOf(...)— a route has exactly one target property set;GatewayIdcoverslocal,igw-,vgw-and gateway-endpointvpce-targets.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:AttachInternetGatewayandec2:CreateInternetGatewayto 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_tablewithroute = []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 → igwroute 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):
| Destination | Target | Why |
|---|---|---|
10.40.0.0/16 | local | The payments VPC itself |
pl-… (S3) | vpce-… | Gateway endpoint: statements and reports to S3, private and free |
10.8.0.0/16 | tgw-… | On-premises core banking, through Transit Gateway and Direct Connect |
10.32.0.0/12 | tgw-… | Other Harbourline VPCs, filtered by Transit Gateway route tables |
0.0.0.0/0 | tgw-… | 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
/24route 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/0covers IPv6 → it doesn't; IPv6 needs::/0→ treat IPv6 routing as a separate table.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
RouteAlreadyExists on create-route | Same destination already present | Use replace-route to change the target |
InvalidGatewayID.NotFound | IGW not attached to this VPC, or wrong Region | aws ec2 describe-internet-gateways and attach it |
Resource.AlreadyAssociated when attaching an IGW | VPC already has an IGW | One IGW per VPC; reuse the existing one |
Route state blackhole | Target deleted (NAT gateway, ENI, peering) | Replace or delete the route |
| Public instance has no internet access | No public IP, no IGW route, or SG/NACL blocks | Check all four conditions; Reachability Analyzer shows which one fails |
DependencyViolation on detach-internet-gateway | Public IPs/Elastic IPs still mapped in the VPC | Release Elastic IPs, delete NAT gateways and public load balancers first |
| Route quota exceeded when adding a prefix-list route | Prefix list counted at its max size | Lower 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 tableExercises
- 🟢 Guided: Attach
hl-m02-igw, add the default route to the public table, and run the route explainer for one subnet of each tier against8.8.8.8and10.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 for10.20.130.5from 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
- Public subnet →
8.8.8.8:0.0.0.0/0 → igw. →10.20.130.5:local(the /16 beats /0). - App subnet →
8.8.8.8: no match, dropped (no NAT yet). →10.20.130.5:local. - Data subnet →
8.8.8.8: dropped. →10.20.130.5:local.
Why: only the public table has a default route; every table has local, which is why all tiers can talk inside the VPC and security groups must do the filtering.
AWS accepts routes more specific than local only when the target is a network interface, a Gateway Load Balancer endpoint, a NAT gateway or similar middlebox target in the same VPC ⚠ VERIFY the exact list of allowed targets in the "subnet routing" documentation. A route to an internet gateway for a destination inside the VPC is rejected, because an IGW cannot deliver to private VPC addresses. Why it matters: the feature exists for east-west inspection ("send app → data traffic through a firewall"), not to break the local route.
AZ-specific failures point to an AZ-specific component. Check: (1) the AZ b app subnet's route table — does its 0.0.0.0/0 point at a NAT gateway in AZ b? Is it blackhole? (2) describe-nat-gateways — is the AZ b NAT gateway failed or deleted, or out of ports (CloudWatch ErrorPortAllocation)? (3) if egress goes through a Transit Gateway, is the AZ b attachment subnet's route or the inspection appliance in AZ b healthy? (4) Did the partner allow-list only AZ a's NAT Elastic IP? Why: each zonal NAT gateway has its own public IP and its own route; "nothing was deployed" often means something was deleted or a partner changed its firewall.
Knowledge check
Answer: The peering connection, because /24 is the longest matching prefix. 10.8.9.1 would go to the Transit Gateway, and 52.95.110.1 to the NAT gateway.
Answer: The static route. Prefix-list routes also beat propagated routes when the prefixes are equal. More specific prefixes always win first.
Answer: No to both. It is free and horizontally scaled. You pay for data transfer out and for public IPv4 addresses.
Answer: Outbound-only IPv6. It lets resources start IPv6 connections to the internet and receive replies, but blocks connections started from the internet. It is the IPv6 counterpart of a NAT gateway (without address translation).
Answer: A route table associated with an internet gateway or virtual private gateway (an edge association). It controls where traffic entering the VPC goes first — typically to a firewall appliance or Gateway Load Balancer endpoint.
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
localin 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
A bank must inspect all traffic arriving from the internet with a third-party firewall before it reaches web servers in public subnets. The firewall fleet sits behind a Gateway Load Balancer. What routing change achieves this?
A. Add a route 0.0.0.0/0 → GWLB endpoint to the public subnets' route table
B. Associate a gateway route table with the internet gateway that routes the public subnets' CIDRs to the Gateway Load Balancer endpoint, and route the public subnets' 0.0.0.0/0 to the same endpoint
C. Attach a security group to the internet gateway
D. Add a network ACL that allows only port 443
Answer: B. Ingress routing (an edge-associated gateway route table) sends inbound traffic to the endpoint first; the matching outbound route keeps the flow symmetric. A only affects outbound traffic. C is impossible — IGWs do not take security groups. D filters ports but does not inspect.
After a cost-cleanup script ran, instances in private subnets lost internet access. The route table shows 0.0.0.0/0 with state blackhole. What happened and what is the fix?
A. The internet gateway was detached; reattach it B. The NAT gateway targeted by the route was deleted; create a NAT gateway (or endpoints) and replace the route's target C. The security group was deleted; recreate it D. The subnet ran out of IP addresses
Answer: B. A blackhole route means its target no longer exists; for private subnets the default route normally targets a NAT gateway. A would affect public subnets' routes. C and D do not change route state.
A VPC route table contains 10.0.0.0/8 → tgw-… (static) and 10.50.0.0/16 → vgw-… (propagated from a VPN). Where is traffic to 10.50.3.3 sent?
A. Transit Gateway, because static routes beat propagated routes B. Virtual private gateway, because its route is the longest matching prefix C. Both, using ECMP D. Dropped, because the routes conflict
Answer: B. Longest prefix is evaluated first; static-over-propagated only breaks ties between identical prefixes. C does not apply to VPC route tables in this way. D — overlapping routes are normal.
A dual-stack application subnet has ::/0 → igw-… and instances have IPv6 addresses. The team believes the instances are "private" because they have no public IPv4. What is the risk and the recommended change?
A. No risk — IPv6 traffic is always NATed B. Instances are directly reachable over IPv6 if security groups allow it; replace the route target with an egress-only internet gateway C. Replace the IGW with a NAT gateway for IPv6 D. Disable IPv6 DNS resolution
Answer: B. IPv6 addresses are globally routable; with an IGW route, inbound connections are possible. An egress-only IGW permits outbound-only IPv6. A is wrong — no NAT happens for IPv6 at an IGW. C — NAT gateways do NAT64, not IPv6-to-IPv6 egress filtering. D changes nothing about reachability.
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
localroute 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
- Configure route tables
- How route priority works
- Enable internet access using an internet gateway
- Egress-only internet gateways
- What is Reachability Analyzer?
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.
Public, private and isolated subnets
Build a three-tier subnet layout across two Availability Zones, explain exactly what makes a subnet public, private or isolated, and audit any VPC's subnets with a C# tool.
NAT gateway and egress
Give private subnets outbound-only internet access with a NAT gateway, calculate exactly what it costs, choose between zonal and regional NAT, and design NAT-free alternatives — with a C# tool that estimates your NAT bill from CloudWatch.