An Elastic Compute Service (ECS) instance without an associated Elastic IP Address (EIP) can access the internet through the SNAT entry of an Internet NAT Gateway. This topic describes how to create, modify, and delete an SNAT entry.
Create an SNAT entry
After creating an SNAT entry, your ECS instances can share the EIP associated with the SNAT entry to access the internet.
Prerequisites
- The Internet NAT Gateway is associated with an EIP.
- The CIDR block for the newly created SNAT entry cannot be the same as any existing SNAT entries.
- When multiple SNAT entries have overlapping CIDR blocks, the system matches SNAT entries based on the longest subnet mask. That is, the longer the subnet mask of the SNAT entry, the higher the priority. For example, an SNAT entry at granularity of ECS with a subnet mask of /32 has the highest priority due to its longest length.
- Make sure the route table linked to your ECS instance's subnet (for the SNAT entry) includes a custom route entry.The recommended destination Classless Inter-Domain Routing (CIDR) block for this entry is 0.0.0.0/0, with the target Internet NAT Gateway instance as the next hop. This ensures the SNAT entry takes effect. For specific actions, see Add route.
tip
If you create your first Internet NAT Gateway in a Virtual Private Cloud (VPC), the system automatically adds a custom route entry with a destination CIDR block of 0.0.0.0/0 and the next hop of the Internet NAT Gateway instance in the system route table, routing traffic to the Internet NAT Gateway.
Procedure
- In the top menu bar, select a target region and project.
- In the list of Internet NAT Gateways, click the name of the target NAT Gateway.
- Select the SNAT rules tab, then click Create SNAT rule.
- Configure relevant parameters based on the table below.
- Click OK to complete the action.
Modify an SNAT entry
After creating an SNAT entry, you can modify its name and EIP.
Modifying an EIP in an SNAT entry will cause the existing SNAT connection drop. To re-establish the connection, a request made from the ECS instance is required. Proceed with caution.
Procedure
- In the top menu bar, select a target region and project.
- In the list of Internet NAT Gateways, click the name of the target NAT Gateway.
- Select the SNAT rules tab. On the right side of the target SNAT entry list, click Edit to modify the name and EIP.
tip
Note the following when modifying the EIP of the SNAT entry:
- Single EIP: If you select a single EIP from the drop-down list, all business connections access the internet through the EIP.
- Multiple EIPs: If you select multiple EIPs from the drop-down list, business connections access the internet through relative EIPs assigned by the five-tuple hashing algorithm. It is recommended to add the EIPs to a Shared Bandwidth Package to prevent any traffic packet loss caused by reaching the bandwidth cap of a single EIP.
- Click OK to complete the action.
Delete an SNAT entry
If you no longer need an SNAT entry, you can follow this procedure to delete it.
- In the top menu bar, select a target region and project.
- In the list of Internet NAT Gateways, click the name of the target NAT Gateway.
- Select the SNAT rules tab, click Delete on the right side of the target SNAT entry list.
- Click Delete to complete the action.
Related documents