Skip to content

Internet Gateway and Routing ​

This article covers the internet gateway, which connects an isolated VPC to the internet, and the route table, which decides where packets go.

Internet Gateway (IGW) ​

An internet gateway is the entrance between a VPC and the internet. Only one can be attached to each VPC, and it also handles translating between an instance's private IP and public IP. If you only create an IGW and don't attach it to the VPC, it does nothing.

Route Table ​

A route table is a table that says "send packets headed for this destination over there." Each subnet is associated with one route table, and a packet follows the route that most specifically matches its destination.

DestinationTargetMeaning
10.0.0.0/16localTraffic within the VPC goes directly (created automatically)
0.0.0.0/0Internet gatewayEvery other address goes to the internet

0.0.0.0/0 is the default route, meaning "everything else." Without this route, requests only circulate inside the VPC and can't get out to the internet.

In B3-1, I created a new route table, added the 0.0.0.0/0 → IGW route, and associated it with the public subnet. If any one of attaching the IGW, adding the route, or associating the subnet is missing, the connection fails.

NAT Gateway ​

A NAT gateway is a device that lets servers in a private subnet make only outgoing requests (installing packages, calling external APIs). It does not accept connections initiated from outside.

CategoryInternet gatewayNAT gateway
DirectionBoth inbound and outboundOnly from inside going out
Attached toVPCPublic subnet (pointed to by the private subnet's route)
CostNoneHourly charge + per amount of data processed

B3-1 had no private subnet, so no NAT gateway was created. The goal was to learn networking basics, and NAT gateways are not part of the free tier, so it was left out.

Interview Questions ​

Q. You created an internet gateway, but the server still can't be reached from outside. What do you check? ​

This checks whether you think having an IGW is enough, or whether you understand the whole path.

First, check whether the IGW is attached to the VPC. Next, check whether the route table associated with the subnet has a 0.0.0.0/0 → IGW route, and whether that route table is actually associated with that subnet. If the routing is correct, move down in this order: the instance's public IP, the security group's inbound rules, then the server process.

Follow-up Questions ​

  • How is an internet gateway different from a NAT gateway? → An IGW connects both inbound and outbound traffic, while a NAT gateway only allows a private subnet's outbound traffic.

Source: Codyssey-B1/B3-1