Internet gateway and route tables
The internet gateway that gives a VPC internet access, route tables and the local route, and what makes a subnet public.
Internet gateway (IGW)
An internet gateway allows resources (such as EC2 instances) in a VPC to connect to the internet.
- It scales horizontally and is highly available and redundant: there's nothing to size.
- It must be created separately from a VPC.
- One VPC can only be attached to one IGW, and vice versa.
- Internet gateways on their own don't allow internet access… route tables must also be edited.
Route tables
- A route table decides where traffic from a subnet goes. Each subnet is associated with one route table (the VPC's main route table if none is chosen).
- Every route table has the local route (the VPC CIDR →
local), so all subnets in a VPC can reach each other. - Public subnet: add
0.0.0.0/0 → igw-…(and::/0for IPv6). - Private subnet: no route to the IGW (usually
0.0.0.0/0 → nat-…for outbound access, see NAT). - Instances in the public subnet also need a public IPv4 (auto-assigned or an Elastic IP) to talk to the internet.
- The most specific route wins:
10.0.1.0/24beats10.0.0.0/16.
Real-world examples
- A web tier in public subnets with a route to the IGW, and an app tier in private subnets with only the local route and a route to a NAT gateway.
Exam tips
- "Instance in a public subnet can't reach the internet" → check the route
0.0.0.0/0 → IGW, a public IP, security groups and NACLs. - "Make a subnet public" → route table with
0.0.0.0/0to an internet gateway.
Common traps
- "Attaching an IGW makes every subnet public." Only subnets whose route table points to it.
- "Attach two IGWs to a VPC." One per VPC.
Hands-on lab: make a subnet public
Goal: add an internet gateway and a public route table to the VPC from the previous lab.
Costs money
Internet gateways and route tables are free. If you launch a test instance, a t3.micro costs about $0.01 an hour plus about $0.005 an hour for its public IPv4 address. Use the same Region as before.
Create and attach the IGW
Internet gateways → Create: saa-igw, then Actions → Attach to VPC → saa-vpc.
Create the public route table
Route tables → Create: saa-public-rt in saa-vpc. Edit routes → Add route 0.0.0.0/0 → saa-igw. Subnet associations → saa-public-a.
Auto-assign public IPs
Select saa-public-a → Actions → Edit subnet settings → tick Enable auto-assign public IPv4 address.
Expected result: saa-public-a uses saa-public-rt with a route to the IGW; saa-private-a still uses the main route table with only the local route.
Clean up: delete the route table, detach and delete the IGW, then delete saa-vpc.
AWS documentation
VPC and subnets
The default VPC, VPC limits and allowed CIDR ranges, public and private subnets across Availability Zones, and the five IP addresses AWS reserves in every subnet.
Bastion hosts
Bastion hosts for SSH access to instances in private subnets, the security group rules they need, and the newer alternatives.