IPv6 in a VPC
What IPv6 is and how its addresses are written, IPv6 in a VPC and dual stack, IPv4 troubleshooting, the egress-only internet gateway and IPv6 routing.
What is IPv6?
- IPv4 was designed to provide 4.3 billion addresses (they'll be exhausted soon).
- IPv6 is the successor of IPv4.
- IPv6 is designed to provide 3.4 × 10³⁸ unique IP addresses.
- Every IPv6 address in AWS is public and internet-routable (no private range).
- Format:
x.x.x.x.x.x.x.xwritten as 8 groups separated by colons, where eachxis hexadecimal (0000toffff). - Examples:
2001:db8:3333:4444:5555:6666:7777:8888;2001:db8:3333:4444:cccc:dddd:eeee:ffff;::→ all 8 segments are zero;2001:db8::→ the last 6 segments are zero;::1234:5678→ the first 6 segments are zero;2001:db8::1234:5678→ the middle 4 segments are zero.
IPv6 in a VPC
- IPv4 can't be disabled for a VPC and its subnets (it's the default addressing).
- A VPC can enable IPv6 (public IP addresses) to operate in dual-stack mode.
- EC2 instances get at least a private internal IPv4 and a public IPv6.
- They can communicate using either IPv4 or IPv6 to the internet through an internet gateway.
IPv6-only subnets (no IPv4 CIDR) can also be created in a dual-stack VPC, but the VPC itself always keeps IPv4.
IPv4 troubleshooting
- So, if an EC2 instance can't be launched in a subnet:
- it's not because it can't get an IPv6 (the space is very large);
- it's because there are no available IPv4 addresses in the subnet.
- Solution: add a new IPv4 CIDR to the VPC and create a subnet in it.
Egress-only internet gateway
An egress-only internet gateway:
- is used for IPv6 only (similar to a NAT gateway, but for IPv6);
- allows instances in a VPC outbound connections over IPv6, while preventing the internet from initiating an IPv6 connection to the instances;
- the route tables must be updated.
IPv6 routing
Public subnet route table:
10.0.0.0/16→ local;2001:db8:1234:1a00::/56→ local;0.0.0.0/0→ igw-id;::/0→ igw-id.
Private subnet route table:
10.0.0.0/16→ local;2001:db8:1234:1a00::/56→ local;0.0.0.0/0→ nat-gateway-id (IPv4 outbound);::/0→ eigw-id (IPv6 outbound).
Exam tips
- "Can't launch instances, subnet has IPv6" → the subnet ran out of IPv4 addresses; add an IPv4 CIDR.
- "Private instances need outbound-only IPv6" → egress-only internet gateway.
- "Outbound-only IPv4" → NAT gateway.
Common traps
- "Disable IPv4 in the VPC to use only IPv6." IPv4 can't be disabled for the VPC.
- "Use a NAT gateway for IPv6 outbound." Use an egress-only internet gateway.
Check yourself
Create an egress-only internet gateway and add ::/0 → eigw-… to the private subnet's route table.
AWS documentation
AWS Direct Connect
AWS Direct Connect for a dedicated private connection to AWS, virtual interfaces, the Direct Connect gateway, dedicated and hosted connections, encryption, resiliency, and a VPN as backup.
Networking costs
Data transfer costs within an AZ, between AZs and between Regions, minimizing egress, S3 data transfer pricing, NAT gateway vs gateway endpoint, and the public IPv4 charge.