This topic describes how to configure SNAT on an Internet NAT gateway. SNAT allows Elastic Compute Service (ECS) instances that are not assigned public IP addresses to access the Internet.
Scenario

In this scenario, you can configure SNAT on an Internet NAT gateway. SNAT allows ECS instances in a VPC to access the Internet when the ECS instances are not assigned public IP addresses.
Prerequisites
- An Alibaba Cloud account is created. For more information, see Create an Alibaba Cloud account.
- A VPC and a vSwitch are created. ECS instances are deployed in the vSwitch. For more information, see Create a VPC with an IPv4 CIDR block.
- The VPC must meet the following requirements:
- A custom route whose destination CIDR block is 0.0.0.0/0 does not exist in the VPC. If the custom route exists, delete it.
- If you want to configure SNAT as a Resource Access Management (RAM) user, make sure that the RAM user is authorized to access the VPC. Otherwise, contact the Alibaba Cloud account owner to acquire the permissions.
Procedure

Step 1: Create an Internet NAT gateway
- Log on to the NAT Gateway console.
- On the Internet NAT Gateway page, click Create NAT Gateway.
- If this is the first time you create a NAT gateway, you must create a service-linked role. In the Create Service-Linked Role section of the Internet NAT Gateway page, click Create Service-Linked Role. After the service-linked role is created, you can create NAT gateways.
- On the buy page, set the following parameters and click Buy Now.
Parameter Description Billing Method By default, Pay-As-You-Go is selected. You can pay for resources after you use them. For more information, see Billing of Internet NAT gateways.
Region Select the region where you want to create the Internet NAT gateway.
VPC Select the VPC for which you want to create the Internet NAT gateway. After the Internet NAT gateway is created, you cannot change the VPC to which the Internet NAT gateway belongs.
Associate vSwitch Select the vSwitch to which the Internet NAT gateway belongs.
Billing Method By default, Pay-By-CU is selected. You are charged based on the resources that you use. For more information, see Billing of Internet NAT gateways. Billing Cycle By default, By Hour is selected. Fees are calculated on an hourly basis. If you use an Internet NAT gateway for less than 1 hour, the usage duration is rounded up to 1 hour. Instance Name Enter a name for the Internet NAT gateway. The name must be 2 to 128 characters in length and can contain digits, underscores (_), and hyphens (-). The name must start with a letter.
Access Mode Select whether to enable SNAT for the resources in the specified VPC. Supported options:
- SNAT for All VPC Resources: After the Internet NAT gateway is created, all resources in the VPC can access the Internet by using the SNAT feature of the NAT gateway.
If you select SNAT for All VPC Resources, you must also specify an EIP.
- Configure Later: If you select this option, SNAT is disabled. You can configure SNAT on the Internet NAT gateway in the console after you complete the payment.
If you select Configure Later, only the Internet NAT gateway is created. No SNAT entry is created.
- SNAT for All VPC Resources: After the Internet NAT gateway is created, all resources in the VPC can access the Internet by using the SNAT feature of the NAT gateway.
- On the Confirm page, confirm the information, select the Terms of Service check box, and then click Confirm. When the message Order complete. appears, the Internet NAT gateway is created.

Step 2: Associate an EIP with the Internet NAT gateway
An Internet NAT gateway can run as expected only when it is associated with an EIP. After you create an Internet NAT gateway, you can associate EIPs with the Internet NAT gateway to meet your business requirements.
- Log on to the NAT Gateway console.
- In the top navigation bar, select the region where you want to create the NAT gateway.
- On the Internet NAT Gateway page, find the Internet NAT gateway that you want to manage and click Associate Now in the Elastic IP Address column.
- In the Associate EIP dialog box, set the following parameters and click OK:
Parameter Description Resource Group Select the resource group of the EIP. EIPs Select the EIP that you want to associate with the Internet NAT gateway. In this example, Purchase and Associate EIP is selected. The system automatically creates a pay-by-data-transfer EIP and associates the EIP with the Internet NAT gateway.

Step 3: Create an SNAT entry
SNAT allows ECS instances in a VPC to access the Internet when no public IP addresses are assigned to the ECS instances.
- Log on to the NAT Gateway console.
- In the top navigation bar, select the region where you want to create the NAT gateway.
- On the Internet NAT Gateway page, find the NAT gateway that you want to manage and click Configure SNAT in the Actions column.
- On the SNAT Management tab, click Create SNAT Entry.
- On the Create SNAT Entry page, set the parameters and click Confirm.
Parameter Description SNAT Entry Specify whether to create an SNAT entry for a VPC, a vSwitch, an ECS instance, or a custom CIDR block. Specify vSwitch is selected in this example. The ECS instances that are attached to the specified vSwitch use the EIP to access the Internet. - Select VSwitch: Select a vSwitch from the drop-down list. Note If you select multiple vSwitches, the system creates multiple SNAT entries that use the same EIP.
- VSwitch CIDR Block: displays the CIDR block of the vSwitch.
Select Public IP Address Select one or more EIPs that are used to access the Internet. Use One IP Address is selected and an EIP is selected from the drop-down list. Entry Name Enter a name for the SNAT entry. - Select VSwitch: Select a vSwitch from the drop-down list.

Step 4: Test the connectivity
- Log on to an ECS instance that is attached to the vSwitch. For more information, see Connection methods.
- Run the
ping
command to pingwww.aliyun.com
.If you can receive echo reply packets, the connection is established.The result shows that the ECS instance can access the Internet.
FAQ
How many SNAT entries can I add to an Internet NAT gateway?
By default, you can add up to 40 SNAT entries to an Internet NAT gateway.
How many EIPs can I specify in an SNAT entry?
You can specify up to 64 EIPs in an SNAT entry. The quota cannot be increased.
For more information about SNAT, see FAQ about SNAT.