NAT instance and NAT gateway
How NAT gives private subnets outbound internet access, the outdated NAT instance, the managed NAT gateway and its high availability, the Regional NAT gateway, and the comparison.
NAT instance
NAT = Network Address Translation. A NAT instance is an EC2 instance that performs the translation.
- Allows EC2 instances in private subnets to connect to the internet (outbound only: the internet can't start connections to them).
- Must be launched in a public subnet.
- Must disable the EC2 setting source / destination check (it forwards traffic that isn't for itself).
- Must have an Elastic IP attached to it.
- Route tables must be configured to route traffic from private subnets to the NAT instance.
Comments:
- A pre-configured Amazon Linux NAT AMI was available, but it reached the end of standard support on 31 December 2020.
- Not highly available / resilient out of the box: it needs an ASG in multiple AZs and a resilient user-data script.
- Internet traffic bandwidth depends on the EC2 instance type.
- The customer must manage security groups and rules:
- inbound: allow HTTP/HTTPS traffic coming from private subnets; allow SSH from the admin's home network (through the internet gateway);
- outbound: allow HTTP/HTTPS traffic to the internet.
NAT gateway
A NAT gateway is AWS-managed NAT: higher bandwidth, high availability, no administration.
- Pay per hour for usage and per GB of data processed.
- A NAT gateway is created in a specific Availability Zone and uses an Elastic IP.
- It can't be used by EC2 instances in the same subnet (only from other subnets).
- Requires an IGW (private subnet → NAT gateway → IGW).
- 5 Gbps of bandwidth with automatic scaling up to 100 Gbps.
- No security groups to manage or required.
High availability
- A NAT gateway is resilient within a single Availability Zone.
- Multiple NAT gateways in multiple AZs are needed for fault tolerance.
- There's no cross-AZ failover needed: if an AZ goes down, its instances are down too and don't need NAT.
Regional NAT gateway
A Regional NAT gateway (the slides call it RNAT) is a highly available NAT gateway associated with the VPC, instead of one AZ.
- It has its own route table (to the IGW).
- It removes the need for per-AZ deployments: one NAT gateway shared across AZs.
- The VPC doesn't need public subnets to host it.
- It automatically detects resources in a new AZ and expands to it.
- It's charged per hour for each AZ it's active in, plus per GB.
- Regional NAT gateways are for public internet access only; for private NAT (to other VPCs or on premises), use zonal NAT gateways.
NAT gateway vs NAT instance
NAT gateway:
- availability: highly available within an AZ (create one per AZ, or use a Regional NAT gateway);
- bandwidth: up to 100 Gbps;
- maintenance: managed by AWS;
- cost: per hour and amount of data processed;
- no security groups; can't be used as a bastion host.
NAT instance:
- availability: failover between instances is scripted by the customer;
- bandwidth: depends on the EC2 instance type;
- maintenance: managed by the customer (software, OS patches…);
- cost: per hour, EC2 instance type and size, plus network;
- security groups apply; can be used as a bastion host.
Both support public and private IPv4.
Real-world examples
- A company runs app servers in private subnets in three AZs, with a NAT gateway in each AZ so the servers can download OS updates. Later it switches to one Regional NAT gateway and deletes the public NAT subnets.
Exam tips
- "Private instances need outbound internet (patches, APIs), no inbound" → NAT gateway.
- "Highly available NAT" → one NAT gateway per AZ, each AZ's private subnets routing to their own (or a Regional NAT gateway).
- "NAT instance not working" → disable source/destination check, Elastic IP, route table, security groups.
- "Least operational overhead" → NAT gateway, not NAT instance.
- "IPv6 outbound only" → egress-only internet gateway, not NAT (see IPv6).
Common traps
- "One NAT gateway serves all AZs with no risk." A zonal NAT gateway fails with its AZ.
- "Attach a security group to the NAT gateway." It doesn't support security groups.
- "Put the NAT gateway in the private subnet." A (zonal, public) NAT gateway sits in a public subnet.
Check yourself
A NAT gateway costs about $0.045 an hour plus $0.045 per GB, so instead:
Create a second NAT gateway in a public subnet in AZ B and route AZ B's private subnets to it (or replace both with a Regional NAT gateway).
AWS documentation
Bastion hosts
Bastion hosts for SSH access to instances in private subnets, the security group rules they need, and the newer alternatives.
NACLs vs security groups
Network ACLs as stateless subnet firewalls, rule numbers and order, the default NACL, ephemeral ports, and how NACLs differ from security groups.