View a markdown version of this page

Add internet access to a subnet - Amazon Virtual Private Cloud
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Add internet access to a subnet

Note

You can apply internet protection to your VPC by using automated internet firewall. A managed firewall is applied at your internet gateway to inspect all traffic that enters or leaves your VPCs, without changing your routes. For more information, see Automated Internet Firewall in the Amazon Network Firewall Developer Guide.

The following describes how to support internet access from a subnet in a nondefault VPC using an internet gateway. You must create the internet gateway, attach it to the VPC, and configure routing for the subnet.

After you configure internet access for your subnet, you must ensure that resources in the subnet can access the internet. For example, your EC2 instances must have a public IPv4 or IPv6 address, and the security groups for your instances must allow specific traffic to and from the internet.

Alternatively, to provide your instances with internet access without assigning them a public IP address, use a NAT device instead. For more information, see NAT devices.

To remove internet access, you can detach the internet gateway from your VPC and then delete it. For more information, see Delete an internet gateway.

Step 1: Create an internet gateway

Use the following procedure to create an internet gateway.

To create an internet gateway using the console
  1. Open the Amazon VPC console at https://console.amazonaws.cn/vpc/.

  2. In the navigation pane, choose Internet gateways.

  3. Choose Create internet gateway.

  4. (Optional) Enter a name for your internet gateway.

  5. (Optional) To add a tag, choose Add new tag and enter the tag key and value.

  6. Choose Create internet gateway.

  7. (Optional) To attach the internet gateway to a VPC now, choose Attach to a VPC from the banner at the top of the screen, select an available VPC, and then choose Attach internet gateway. Otherwise, you can attach your internet gateway to a VPC at another time.

To create an internet gateway using the command line

Step 2: Attach the internet gateway to the VPC

To use an internet gateway, you must attach it to a VPC.

To attach an internet gateway to a VPC using the console
  1. Open the Amazon VPC console at https://console.amazonaws.cn/vpc/.

  2. In the navigation pane, choose Internet gateways.

  3. Select the check box for the internet gateway.

  4. To attach it, choose Actions, Attach to VPC, select an available VPC, and choose Attach internet gateway.

  5. To detach it, choose Actions, Detach from VPC and choose Detach internet gateway. When prompted for confirmation, choose Detach internet gateway.

To attach an internet gateway to a VPC using the command line

Step 3: Add a route to the subnet route table

The route table for the subnet must have a route that sends internet traffic to the internet gateway.

To configure the subnet route table using the console
  1. Open the Amazon VPC console at https://console.amazonaws.cn/vpc/.

  2. In the navigation pane, choose Route tables.

  3. Select the route table for the subnet. By default, a subnet uses the main route table for the VPC. Alternatively, you can create a route table and then associate the subnet with the new route table.

  4. On the Routes tab, choose Edit routes and then choose Add route.

  5. Enter 0.0.0.0/0 for Destination and select the internet gateway for Target.

  6. Choose Save changes.

To configure the subnet route table using the command line

Add firewall inspection to your internet gateway

After you create and attach an internet gateway, you can use automated internet firewall to inspect the traffic that enters and leaves your VPCs through the internet gateway, and to apply managed network address translation (NAT). You set up and manage automated internet firewall centrally in Network Security Manager, and it does not require changes to your route tables. For more information, see Getting started with Automated Internet Firewall in the Amazon Network Firewall Developer Guide.

Note

Automated internet firewall is available in public preview in all Amazon commercial Regions. During the preview, it doesn't work with Regional NAT, noNAT ingress routing, or ingress-only VPC Block Public Access. During the preview, it also does not perform NAT64 for IPv6 traffic that is destined for an IPv4 destination. It also does not support Amazon EC2 Mac instances or the following machine learning instance types: p4d, p4de, p6-b200, p6-b300, p6e-gb200, trn2, trn2u, and g7e.