Internet Gateway
Overview
An Internet Gateway (IGW) is the horizontally scaled, redundant, highly available VPC component that connects your VPC to the internet. It does two jobs: it provides a target in your route tables for internet-routable traffic, and it performs one-to-one network address translation (NAT) for instances that have a public IPv4 address.
Your instances only know their private IP address. When an instance with a public IPv4 sends traffic out, the IGW swaps the private source address for the public one; for return traffic it swaps it back. IPv6 addresses are already globally unique, so no translation is needed.
An IGW is free, has no bandwidth limit and no availability risk for you to manage. Its sibling, the Egress-only Internet Gateway, gives IPv6 workloads outbound-only internet access, similar to what a NAT Gateway does for IPv4.
Key Concepts
- An IGW is attached to one VPC, and a VPC can have only one IGW at a time.
- It is regional, highly available and managed by AWS — no instances to patch, no scaling, no hourly charge.
- Three ingredients make an instance internet-reachable: IGW attached, route 0.0.0.0/0 (and ::/0) -> IGW, and a public IPv4/Elastic IP or IPv6 address.
- The IGW performs static one-to-one NAT between the instance's private IPv4 and its public/Elastic IP.
- Security groups and NACLs must still allow the traffic — the IGW itself does no filtering.
- An Egress-only Internet Gateway allows outbound-only IPv6; it is stateful and blocks inbound connections initiated from the internet.
- Since Feb 2024 AWS charges for all public IPv4 addresses (about $0.005 per hour each), whether in use or idle.
- Private instances reach the internet for outbound traffic via a NAT Gateway that itself sits behind the IGW.
Detailed Notes
What the Internet Gateway does
The IGW is not an appliance you see or size. It is a logical VPC resource that:
- Appears as a route target (
igw-xxxxxxxx). - Translates public IPv4 <-> private IPv4 for instances/ENIs that have a public IP.
- Passes IPv6 traffic unchanged.
It scales automatically and imposes no bandwidth constraints on your traffic.
Making a subnet internet-capable: the four steps
| Step | Action | Common mistake |
|---|---|---|
| 1 | Create and attach the IGW to the VPC | Created but left detached |
| 2 | Add 0.0.0.0/0 -> igw to the subnet's route table | Edited the main table, not the subnet's table |
| 3 | Give the ENI a public IPv4 / Elastic IP (or IPv6) | Auto-assign disabled |
| 4 | Allow traffic in security group and NACL | NACL blocks return ephemeral ports |
IGW_ID=$(aws ec2 create-internet-gateway --query 'InternetGateway.InternetGatewayId' --output text)
aws ec2 attach-internet-gateway --internet-gateway-id $IGW_ID --vpc-id vpc-0abc123
aws ec2 create-route --route-table-id rtb-0pub --destination-cidr-block 0.0.0.0/0 --gateway-id $IGW_ID
aws ec2 create-route --route-table-id rtb-0pub --destination-ipv6-cidr-block ::/0 --gateway-id $IGW_ID
Public IPv4 addressing options
| Type | Behaviour | Cost |
|---|---|---|
| Auto-assigned public IP | From AWS pool; released on stop, kept on reboot | Charged per hour (since 2024) |
| Elastic IP (EIP) | Static, owned by your account; remap between instances | Charged per hour whether attached or idle |
| BYOIP | Bring your own public range to AWS | IPv4 hourly charge applies |
| IPv6 | Globally unique, no NAT; assigned from the VPC /56 | No address charge |
Default limit: 5 Elastic IPs per Region (adjustable). Because IPv4 is now billed hourly and scarce, prefer IPv6, ALB/CloudFront in front, and private instances behind a NAT Gateway.
Egress-only Internet Gateway (IPv6)
IPv6 addresses are public by design, so any IPv6 instance in a subnet routed to the IGW is reachable from the internet if the security group allows it. When you want outbound-only access:
- Create an egress-only internet gateway for the VPC.
- In the private subnet's route table add ::/0 -> eigw-xxxx.
- Instances can initiate outbound IPv6 connections and receive replies; internet hosts cannot initiate inbound connections.
| Feature | IGW | Egress-only IGW | NAT Gateway |
|---|---|---|---|
| IP version | IPv4 + IPv6 | IPv6 only | IPv4 (NAT64 for IPv6->IPv4) |
| Direction | Both | Outbound only | Outbound only |
| Cost | Free | Free (data processing none) | Hourly + per GB |
| Stateful | n/a (translation) | Yes | Yes |
Public vs. private subnet decision
An instance in a subnet routed to the IGW without a public IP still cannot reach the internet, because there is nothing to translate its private address into. Likewise, a public IP on an instance in a subnet without an IGW route is unreachable. Both conditions are needed.
Limits and facts
- One IGW per VPC, and an IGW can attach to only one VPC at a time.
- You cannot detach an IGW while any resource in the VPC still has a public IP mapped (EIP or auto-assigned) — release or disassociate them first.
- The IGW supports IPv4 and IPv6 in the same attachment.
- Traffic between instances in the same VPC uses private addresses over the local route and never crosses the IGW, even if both have public IPs (when using private DNS names).
- Traffic to AWS public service endpoints in the same Region (such as S3) via public IPs stays on the AWS network but still uses the IGW; VPC endpoints avoid the IGW entirely.
Troubleshooting "cannot reach my EC2 from the internet"
- Is the IGW attached (state available)?
- Does the subnet route table have 0.0.0.0/0 -> IGW?
- Does the instance have a public IPv4/EIP?
- Does the security group allow the inbound port from the source?
- Does the NACL allow inbound and the outbound ephemeral port range?
- Is the OS firewall blocking the port?
Real World Example
Scenario — a SaaS start-up exposes its web app and runs an IPv6 telemetry fleet.
The company hosts a customer web app behind an Application Load Balancer in two public subnets, with a single Internet Gateway on the VPC. Only the ALB (and the NAT Gateways) are in public subnets; web servers sit in private subnets with no public IPs, so the IGW translates only the ALB nodes' addresses.
A separate fleet of IoT data collectors runs in private dual-stack subnets. They must upload telemetry to an external partner that supports IPv6, but security forbids any inbound connection from the internet. The engineers create an Egress-only Internet Gateway and add ::/0 -> eigw to the private route table. Collectors connect out over IPv6, return traffic flows in automatically, and nothing on the internet can start a connection to them.
By moving the telemetry traffic to IPv6, they also remove the need for extra NAT Gateway capacity and cut public IPv4 charges for hundreds of instances, saving thousands of dollars a year.
Architecture Diagram
The IGW serves public subnets in both directions; the egress-only IGW serves private IPv6 outbound traffic.
- 1Internet users reach the ALB in the public subnet; the IGW maps the ALB's public address to its private address.
- 2ALB forwards requests to private web servers over the local route.
- 3Private IPv4 outbound traffic goes to the NAT Gateway, which sends it through the IGW using its Elastic IP.
- 4Private IPv6 outbound traffic uses ::/0 -> egress-only IGW; internet hosts cannot initiate connections back.
Best Practices
- ✓Attach the IGW only when needed and keep data and application tiers in subnets without an IGW route.
- ✓Use ALB, CloudFront or API Gateway as the public entry point instead of giving instances public IPs.
- ✓Prefer IPv6 with an Egress-only IGW for outbound-only workloads to avoid NAT and public IPv4 charges.
- ✓Release unused Elastic IPs — idle and in-use public IPv4 addresses are both billed.
- ✓Use SSM Session Manager rather than public SSH/RDP; never open 22/3389 to 0.0.0.0/0.
- ✓Restrict security groups to the minimum ports; the IGW does not filter anything for you.
- ✓Use Flow Logs and AWS Config rules to detect instances with unintended public IPs or open security groups.
- ✓Use VPC endpoints for AWS service traffic instead of routing through the IGW.
Common Interview Questions
Exam Tips
SAA-C03 focus
- Internet access needs IGW + route 0.0.0.0/0 + public/Elastic IP + SG/NACL allow. Questions often hide one missing item.
- IGW is free, redundant and has no throughput limit; NAT Gateway is not free.
- IPv6 outbound-only from private subnets -> Egress-only Internet Gateway; IPv4 outbound-only -> NAT Gateway.
- One IGW per VPC.
- Auto-assigned public IPs change on stop/start; use an Elastic IP when a fixed address is required.
- Public IPv4 addresses are billed hourly (in use or idle) — a cost-optimisation angle for IPv6 or consolidating behind ALB.
- Private instances should reach the internet through a NAT Gateway in a public subnet, never by attaching public IPs.
- Traffic to S3/DynamoDB without the internet -> gateway VPC endpoint; no IGW or NAT needed.
Finished this lesson?
0 of 64 lessons done · 0% of the course

