Home/Server & Website Managed Operations/How to Configure Port Mapping (DNAT) on Alibaba Cloud Servers
Server & Website Managed Operations
How to Configure Port Mapping (DNAT) on Alibaba Cloud Servers
Published 2015-08-15By adminCategory Server & Website Managed Operations10 min read
Configuring DNAT via iptables is a common operation. While Alibaba Cloud servers in the Classic Network do not support SNAT, the DNAT functionality works correctly. Below are the steps for the method commonly used in our studio:
Environment: Two Alibaba Cloud ECS servers—one with a public IP and one with an internal IP. Nginx is installed on the internal server, and we want to access the internal Nginx site when visiting the public server.
The following steps are performed on the internal server:
First, install and start Nginx:
This table is wide — scroll sideways to see it all
Now, test by accessing the public server’s IP and capture packets to observe the forwarded traffic:
This table is wide — scroll sideways to see it all
1
15:35:46.602240 IP 42.120.74.108.8864 > 115.29.96.246.80: S 765781831:765781831(0) win 8192
This table is wide — scroll sideways to see it all
2
15:35:46.602272 IP 42.120.74.108.8864 > 10.144.26.11.80: S 765781831:765781831(0) win 8192
At this point, the source address is the visitor’s public IP, and the destination is the internal server’s private IP. This prevents two-way communication. Therefore, we need to change the source address of these packets to an internal address so that communication with the internal server can be established. Changing the source address involves SNAT.
We continue configuring on the public server:
This table is wide — scroll sideways to see it all
This table is wide — scroll sideways to see it all
1
15:38:14.846955 IP 42.120.74.108.10839 > 115.29.96.246.80: P 433:858(425) ack 159 win 16385
This table is wide — scroll sideways to see it all
2
15:38:14.846985 IP 10.163.209.59.10839 > 10.144.26.11.80: P 433:858(425) ack 159 win 16385
This table is wide — scroll sideways to see it all
3
15:38:14.847759 IP 10.144.26.11.80 > 10.163.209.59.10839: P 159:317(158) ack 858 win 317
This table is wide — scroll sideways to see it all
4
15:38:14.847772 IP 115.29.96.246.80 > 42.120.74.108.10839: P 159:317(158) ack 858 win 317
Visitor’s local public IP -> Public Server’s Public IP
Destination address modified
Public Server’s Internal IP -> Internal Server’s IP
Source address modified
Internal Server’s IP -> Public Server’s Internal IP
Public Server’s Public IP -> Visitor’s local public IP