Ben walks you through setting up a NAT gateway

nat-gateway-vpc-private-subnet-ben

I want my EC2 instances in a private subnet of a virtual private cloud (VPC) to communicate securely over the Internet for things like software updates and package downloads. How do I set up a NAT gateway for this purpose?

You can create a NAT gateway for EC2 instances in a private VPC subnet to connect securely over the Internet. Because the subnet is private, the IP addresses assigned to the instances cannot be used in public. Instead, it is necessary to use network address translation (NAT) to map the private IP addresses to a public address for requests, and then map the public IP address back to private addresses for the response.

Follow these steps to create a NAT gateway:

Prerequisites:

  • Create a public VPC subnet to host the NAT gateway. The route table for the subnet should contain a route to the Internet through an Internet gateway.
  • Provision an unattached Elastic IP address (EIP) to your account. You’ll need to associate this IP address with the NAT gateway.
  • Update the route table of the private subnet hosting the EC2 instances that need Internet access. The route table should be updated to direct Internet-bound traffic to the NAT gateway.

After ensuring that prerequisites are met, follow these steps:

  1. Sign in to the AWS Management Console.
  2. Open the Amazon VPC console.
  3. Choose NAT Gateway from the navigation bar on the left.
  4. Choose Create NAT Gateway and then select the public subnet and EIP that you have provisioned for the NAT gateway.
  5. After you create the NAT gateway, make note of the associated ID, which will resemble "nat-xxxxxxx".
  6. Choose the Route Tables link on the left hand side, and then choose the route table associated with your NAT gateway. Update this route table so that 0.0.0.0/0 points to the ID of the NAT gateway that you created.

From one of the EC2 instances in your private subnet, open a command prompt or shell and ping amazon.com to verify Internet connectivity.


Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2016-06-06