3.3
Internet Gateway and Route Tables
How a packet leaves a subnet: route lookup, longest prefix match, what makes a subnet public, and the classic misconfigurations.
24 min Reading + animations
Tip: tap or hover any dotted-underlined term to see what it means.
By the end of this lesson you will be able to
- Explain what the VPC router does and how a route table decides where each packet goes.
- Apply the longest prefix match rule to any route table, including tricky overlaps.
- Describe the internet gateway: what it is, its limits, and the address translation it performs.
- State exactly what makes a subnet public, and why the instance also needs a public address.
- Troubleshoot “my instance has no internet” with a fixed checklist, for public and private subnets.
#Every packet goes to the VPC router first
Inside a VPC there is no box you install called “the router”. Instead, every subnet has an implicit VPC router, a managed function that AWS runs for you. Its address is the subnet’s base + 1 (for 10.0.0.0/24 that is 10.0.0.1, one of the five reserved addresses from lesson 3.2), and every instance uses it as its default gateway.
Whenever an instance sends a packet to an address outside its own subnet, the packet goes to the VPC router. The router looks at the destination address and consults one thing: the route table associated with the source subnet.
#Route tables
A route table is a list of rules. Each route has two parts:
- Destination: a CIDR block (
10.1.0.0/16,0.0.0.0/0…), meaning “packets going to addresses in this range…” - Target: where to send them: the local VPC, an internet gateway (
igw-…), a NAT gateway (nat-…), a VPN gateway (vgw-…), a peering connection (pcx-…), a transit gateway (tgw-…), a VPC endpoint (vpce-…), or a network interface (eni-…).
How route tables attach to subnets:
| Rule | Detail |
|---|---|
| Main route table | Created with the VPC. Any subnet you do not explicitly associate uses it. |
| Custom route tables | You create as many as you need, for example one for public subnets and one per AZ for private subnets. |
| One table per subnet | A subnet is associated with exactly one route table at a time. |
| Many subnets per table | One route table can serve many subnets. |
| The local route | Every route table contains VPC CIDR → local. It is added automatically and cannot be deleted, so every subnet in a VPC can always reach every other subnet (firewalls permitting). |
#Longest prefix match
A destination address often matches several routes. 0.0.0.0/0 matches everything, after all. The rule that decides is simple and absolute:
The route with the longest prefix (the most specific match) wins. The order of routes in the table does not matter.
How the VPC router picks a path
One instance, four destinations. For each packet the router finds every route that matches and uses the most specific one.
Scenario
Route table of the app subnet
| Destination | Target |
|---|---|
| 10.0.0.0/16 | local |
| 10.1.0.0/16 | pcx-0b2c (peering) |
| 192.168.0.0/16 | vgw-0a1b (VPN) |
| 0.0.0.0/0 | igw-0f9e |
The app server sends to the database at 10.0.20.5. Every packet leaving an instance goes first to the VPC router at the subnet’s base + 1 (10.0.10.1).
Points from the animation:
10.0.20.5matches both10.0.0.0/16and0.0.0.0/0;/16wins, so VPC-internal traffic always stays local.- More specific routes override broader ones, which is how you send one range through a VPN or peering connection while everything else goes to the internet.
- The same rule is dangerous: a single overly specific route pointing at the wrong target quietly diverts just that traffic.
#The internet gateway
An internet gateway (IGW) is the door between a VPC and the public internet.
| Property | Detail |
|---|---|
| Managed and highly available | AWS runs it redundantly across the Region; it is not a single box that can fail. |
| Scales horizontally | No bandwidth limit of its own and no capacity to choose. |
| Created separately | You create an IGW and then attach it to a VPC. |
| One-to-one | A VPC can have at most one IGW attached, and an IGW can attach to only one VPC. |
| Free | The gateway itself costs nothing; you pay for data transferred out to the internet. |
| Address translation | It performs one-to-one NAT between each instance’s private IPv4 address and its public IPv4 address. |
That last row matters. An instance’s operating system only ever has its private address; run ip addr on a Linux instance with a public IP and you will not find the public one. The internet gateway holds the mapping and rewrites addresses as packets pass through:
Through the internet gateway, and the ways it breaks
A web server in a public subnet. Watch the internet gateway swap private and public addresses, then break each link in the chain.
Scenario
Route 0.0.0.0/0 → IGW, public IP 203.0.113.25, rules allow HTTP.
Packet coming in
Source IP
198.51.100.20
Destination IP
203.0.113.25
A visitor opens http://203.0.113.25. On the internet the packet is addressed to the server’s public IP.
#What makes a subnet public
A subnet is public when its route table has a route 0.0.0.0/0 → igw-…. A subnet without that route is private. That is the whole definition.
For an individual instance to actually talk to the internet, two more things must hold:
- It needs a public IPv4 address or an Elastic IP (lesson 3.6). Subnets have an “auto-assign public IPv4 address” setting that controls whether new instances get one automatically.
- The security group and network ACL must allow the traffic (lesson 3.5).
Self-checkQuestion
A subnet’s route table contains 10.0.0.0/16 → local and 0.0.0.0/0 → igw-123. An instance in it has a public IP. What is true?
#Troubleshooting checklist
When an instance cannot reach the internet (or the internet cannot reach it), walk this list in order. The exam uses it constantly.
Instance in a public subnet:
- Public address: does the instance have a public IPv4 address or an Elastic IP?
- Internet gateway: is an IGW attached to the VPC?
- Route table: does the subnet’s route table send
0.0.0.0/0to that IGW (and is the routeactive, notblackhole)? - Security group: does it allow the traffic (inbound rule for the port; outbound is open by default)?
- Network ACL: does it allow the traffic in both directions, including the return traffic on ephemeral ports?
Instance in a private subnet:
- NAT gateway: is there a NAT gateway in a public subnet (whose own route table points to the IGW)?
- Route table: does the private subnet’s route table send
0.0.0.0/0to that NAT gateway? - Then the same security group and network ACL checks.
#Try it yourself
Turn a fresh subnet into a public one with the CLI (replace the IDs with yours from lesson 3.2):
IGW=$(aws ec2 create-internet-gateway --query InternetGateway.InternetGatewayId --output text)
aws ec2 attach-internet-gateway --internet-gateway-id $IGW --vpc-id $VPC
RT=$(aws ec2 create-route-table --vpc-id $VPC --query RouteTable.RouteTableId --output text)
aws ec2 create-route --route-table-id $RT --destination-cidr-block 0.0.0.0/0 --gateway-id $IGW
aws ec2 associate-route-table --route-table-id $RT --subnet-id $SUBNET
# New instances in this subnet get a public IPv4 automatically
aws ec2 modify-subnet-attribute --subnet-id $SUBNET --map-public-ip-on-launch
# Look at the result: note the local route you never created, and the State column
aws ec2 describe-route-tables --route-table-ids $RT \
--query "RouteTables[].Routes[].[DestinationCidrBlock,GatewayId,State]" --output table
VPC Reachability Analyzer (in the VPC console) can trace a path between two resources hop by hop and tell you which route, security group or network ACL blocks it, which is the checklist above, automated.
#Summary
Key takeaways
- Every subnet has an implicit VPC router at base + 1. Traffic leaving a subnet is routed by that subnet’s route table.
- A route is destination CIDR → target (local, igw, nat, vgw, pcx, tgw, vpce, eni). Each subnet uses exactly one route table; unassociated subnets use the main route table.
- The local route (VPC CIDR → local) is in every table and cannot be deleted.
- Longest prefix match decides: the most specific matching route wins; table order is irrelevant.
- An internet gateway: managed, highly available, no bandwidth limit, free, one per VPC, and it does one-to-one NAT between private and public IPv4. The instance itself only knows its private IP.
- Public subnet = route
0.0.0.0/0 → IGW. The instance also needs a public IP or Elastic IP, and both firewalls must allow the traffic. - Private subnets get outbound internet through a NAT gateway in a public subnet, never directly from the IGW.
Answer on your own first, then read the explanation, even when you got it right.
Self-checkQuestion
A route table has 0.0.0.0/0 → igw-1 and 172.16.0.0/12 → vgw-1. Where does a packet to 172.20.4.4 go?
Self-checkQuestion
An instance in a public subnet with a public IP cannot be reached on port 443, and the browser shows a timeout. The route table and internet gateway are correct. What should you check next?
Self-checkQuestion
An instance lives in subnet 10.0.8.0/22. Which address does it use as its default gateway?
Self-checkQuestion
A team creates a new subnet and does not associate it with any route table. Which route table does it use?
Self-checkQuestion
Which statement about route table associations is correct?
Self-checkQuestion
Which two statements about the local route are true?
Choose 2
Self-checkQuestion
Which two can be the target of a route in a VPC route table?
Choose 2
Self-checkQuestion
An engineer insists that the 0.0.0.0/0 route must be listed last, otherwise it will catch traffic meant for the VPC. What is actually true?
Self-checkQuestion
A route table contains 10.0.0.0/16 → local, 10.50.0.0/16 → pcx-1, 10.50.7.0/24 → tgw-1 and 0.0.0.0/0 → nat-1. Where does a packet to 10.50.7.20 go?
Self-checkQuestion
Which single property makes a subnet a public subnet?
Self-checkQuestion
Which two statements about an internet gateway are true?
Choose 2
Self-checkQuestion
A company has three VPCs and wants to attach one shared internet gateway to all of them to keep things simple. What happens?
Self-checkQuestion
Which statement about the cost of an internet gateway is correct?
Self-checkQuestion
A developer runs ip addr on an EC2 instance whose console shows public IPv4 203.0.113.25, but sees only 10.0.0.10. What explains this?
Self-checkQuestion
Which is NOT required for an EC2 instance to be reachable from the internet over IPv4?
Self-checkQuestion
An operator sees the route 0.0.0.0/0 → igw-0abc with State: blackhole. What does this mean?
Self-checkQuestion
A solutions architect wants a tool that traces the path between two resources in a VPC hop by hop and names the route, security group or network ACL that blocks it, without sending real traffic. Which tool fits?
Self-checkQuestion
A company expects heavy traffic and plans to attach a second internet gateway to its VPC for more throughput. What should the solutions architect say?
Self-checkQuestion
A solutions architect creates a new subnet in a custom VPC, adds 0.0.0.0/0 → igw to its route table and launches an instance with default settings. The instance cannot be reached from the internet, and its details show no public IPv4 address. What is the most likely cause, and the fix?
Self-checkQuestion
A security review finds that every subnet a team creates automatically has a route to the internet gateway, although the team never edits route tables. What is the cause, and the best fix?
Self-checkQuestion
A company runs application servers in private subnets. They must download operating system patches from the internet but must not be reachable from the internet. Which solution meets the requirement?
Self-checkQuestion
Instances in a private subnet cannot download updates. A NAT gateway exists in a public subnet, and the private subnet’s route table sends 0.0.0.0/0 to it. The public subnet’s route table has only the local route. What is wrong?
Self-checkQuestion
Users reach a web server in a public subnet: its logs show their requests arriving, but users never receive responses. The route table has 0.0.0.0/0 → igw, and the security group allows inbound TCP 443. What is the most likely cause?
Self-checkQuestion
Instances in two different subnets of the same VPC cannot communicate. Which is NOT a possible cause?
Self-checkQuestion
An EC2 instance in a public subnet cannot reach the internet. Which two problems could each cause this on their own?
Choose 2
Self-checkQuestion
A company must inspect all inbound internet traffic with a security appliance before it reaches its public subnets. Which routing feature makes this possible?
Self-checkQuestion
A route table has 10.0.0.0/16 → local, 192.168.0.0/16 → vgw-1 (VPN to the office) and 0.0.0.0/0 → igw-1. Someone adds 192.168.5.0/24 → igw-1 by mistake. What happens to traffic for 192.168.5.9 and for 192.168.6.9?
Self-checkQuestion
A VPC is peered with another VPC that uses 10.20.0.0/16. The company wants traffic to that range to use the peering connection pcx-1, and everything else to go to the internet. Which routes are needed besides the local route?
Self-checkQuestion
A VPC has a public subnet and a private subnet in each of two Availability Zones, with one NAT gateway per zone. Which two route table designs are correct?
Choose 2
Self-checkQuestion
A web server has a public IP, and its security group and network ACL allow HTTP. Its subnet uses the main route table, which has only the local route. A visitor on the internet sends a request. What happens?