Home/Server & Website Managed Operations/Tutorial: Configuring SNAT on Alibaba Cloud VPC for Internet Access
Server & Website Managed Operations

Tutorial: Configuring SNAT on Alibaba Cloud VPC for Internet Access

Many cloud servers, including those from AWS and Alibaba Cloud, do not support SNAT by default. A client obtained test permissions for an Alibaba Cloud VPC and asked our studio to verify if SNAT is supported in this virtual private network mode. Below is a summary of the testing process.

Use one virtual router and two virtual switches to connect the internal LAN and the external network LAN. Use two ECS instances:
one purely internal, and one bound with an EIP to act as a NAT gateway, as shown below:

 

1

 

 

Configure routing on the virtual router

To allow internal servers to access the public internet via the EIP, set the next hop for all destination addresses 0.0.0.0/0 to forward to the ECS instance bound with the public IP. Note that the next-hop ECS does not support search, which can be somewhat cumbersome.

2

 






After configuration, log into the external-facing machine to configure SNAT
1 iptables -t nat -I POSTROUTING -s 172.16.3.0/24 -j SNAT --to-source 172.16.1.2

Here, the 3rd subnet (172.16.3.0/24) is the internal LAN segment, and 172.16.1.2 is the self IP of the ECS bound with the EIP, used to complete source address translation.

31

 

Then, modify kernel parameters to enable IP forwarding:
1 sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g' /etc/sysctl.conf;sysctl -p

After completion, test the connection. The internal server can now access the external network: 5

FREE CHECKUP

Free server checkup

We will send a problem checklist and remediation advice within one business day — no obligation to engage.

135 410 16684
Weekdays Mon – Fri 10:00 – 22:00 (UTC+8) · 7×24 emergency response
Call now
CONTACT

Contact Us

How can we help?

* Required