- Allow outbound-only internet access for a private EC2 instance (no public IP).
- Use a NAT Gateway in a public subnet to provide internet egress for the private subnet.
- VPC: 10.0.0.0/16
- Private Subnet: 10.0.1.0/24 (EC2 instance without public IP)
- Public Subnet: 10.0.2.0/24 (NAT Gateway + Elastic IP + IGW route)
- Internet Gateway (IGW) attached to the VPC
- Public Route Table (0.0.0.0/0 -> IGW) associated to the public subnet
- Private Route Table (0.0.0.0/0 -> NAT Gateway) associated to the private subnet
Prerequisites
- AWS account with permissions to create VPCs, subnets, EC2 instances, IGWs, NAT Gateways, Elastic IPs, and route tables.
- Optionally: AWS CLI configured if you prefer command-line steps.
- Create the VPC
- Create a VPC using CIDR
10.0.0.0/16(no IPv6 needed for this demo).
- Create the private subnet and launch the EC2 instance
- Private Subnet:
10.0.1.0/24 - Launch an EC2 instance in the private subnet:
- AMI: Amazon Linux (or preferred AMI)
- Instance name:
PrivateServer - Subnet: Private Subnet (
10.0.1.0/24) - Public IPv4 address: Disable / Do not auto-assign
- Security Group: default (or configure as needed)

This instance has no public IPv4 address, so it cannot be reached directly from the internet. With a NAT Gateway, it can still initiate outbound connections to the internet.
- Create an Internet Gateway (IGW)
- Create an IGW and attach it to your VPC:
- Create Internet Gateway
- Attach Internet Gateway to VPC

- Create a public subnet
- Public Subnet:
10.0.2.0/24 - This subnet will host the NAT Gateway and the Elastic IP.
- Create route tables and associate subnets
- Public Route Table
- Add route:
0.0.0.0/0-> Internet Gateway (igw-xxxxx) - Associate with: Public Subnet (
10.0.2.0/24)
- Add route:
- Private Route Table
- Do NOT add
0.0.0.0/0-> IGW (keeps subnet private) - Associate with: Private Subnet (
10.0.1.0/24)
- Do NOT add
- Create the NAT Gateway
- Console: NAT Gateways -> Create NAT Gateway
- Name:
my-nat-gateway - Subnet: Public Subnet (
10.0.2.0/24) - Elastic IP: Allocate Elastic IP (EIP) and associate it with the NAT Gateway
- Name:
- Wait for the NAT Gateway to reach state
Available(EIP allocation and provisioning can take a short time).
- Update the private route table to use the NAT Gateway
- Private Route Table -> Routes -> Edit routes
- Add route:
0.0.0.0/0-> NAT Gateway (nat-xxxxxxxx) - Save changes
- Add route:
Available before relying on it for outbound traffic.
Testing connectivity
- Access the private instance via:
- a Bastion host in the public subnet, or
- AWS Systems Manager Session Manager (recommended): https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html
- From the private instance, run a simple outbound test:
NAT Gateways are Availability Zone-scoped. A NAT Gateway deployed in one AZ serves subnets in that AZ but is not resilient across AZ failures. In production, deploy a NAT Gateway in each AZ and configure routing (or per-AZ route tables) so instances use the NAT Gateway in their AZ to avoid a single point of failure.
- The Elastic IP associated with the NAT Gateway is the public address used for outbound connections from private instances.
- NAT Gateways are managed AWS services and incur:
- An hourly NAT Gateway charge
- A per-GB data processing charge Review pricing before enabling NAT Gateways in production.
- For cost-optimized or specialized scenarios you can consider NAT instances (self-managed) but they require maintenance and scaling logic. NAT Gateways are easier to manage and scale automatically.
- Deploy a NAT Gateway in each Availability Zone.
- Use per-AZ route tables or routing rules so each private subnet uses the NAT Gateway in its AZ.
- Monitor NAT Gateway metrics and costs.
- AWS NAT Gateway documentation: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html
- AWS VPC documentation: https://docs.aws.amazon.com/vpc/latest/userguide/what-is-amazon-vpc.html
- AWS Systems Manager Session Manager: https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html