I. environment and requirements lab environment node network settings are as follows: node nic ip node Node1eth0172.19.104.33 intranet No I. environment and requirements lab environment
The network settings of the node are as follows:
Node |
Nic |
IP |
Network |
Node1 |
Eth0 |
172.19.104.33 |
Intranet |
Node1 |
Eth1 |
6.6.5.5 |
Internet |
Node2 |
Eth0 |
172.19.104.14 |
Intranet |
Requirement
The function we need to implement is to map Port 8100 of Node1 to port 8000 of Node2, that is, access http: // 6.6.5.5: 8100 over the internet to access the WEB service on port 8000 of PC2.
II. implementation steps
The following operations are performed on node1. some modifications may require the root permission.
1. Edit/etc/sysctl.conf
Configuration filenet.ipv4.ip_forward = 1
The default value is 0. run the command again.sysctl -p
Make it take effect
Or directly execute
echo 1 > /proc/sys/net/ipv4/ip_forward
2. execute
iptables -t nat -A PREROUTING -d 172.19.104.33 -p tcp --dport 8100 -j DNAT --to-destination 172.19.104.14:8000iptables -t nat -A POSTROUTING -d172.19.104.14 -p tcp --dport 8000 -j SNAT --to 172.19.104.33 iptables -A FORWARD -o eth0 -d172.19.104.14 -p tcp --dport 8000 -j ACCEPTiptables -A FORWARD -i eth0 -s 172.19.104.14 -p tcp --sport 8000 -j ACCEPTiptables save
Note the IP address, port, and Nic configurations.
Or directly modify the location file
Edit/etc/sysconfig/iptables
AddThe following content:
The following is a reference file, which can be modified according to the actual situation.
...-A PREROUTING -d 172.19.104.33 -p tcp -m tcp --dport 8100 -j DNAT --to-destination 172.19.104.14:8000-A POSTROUTING -d 172.19.104.14 -p tcp -m tcp --dport 8000 -j SNAT --to-source 172.19.104.33...-A FORWARD -o eth0 -d 172.19.104.14 -p tcp --dport 8000 -j ACCEPT-A FORWARD -i eth0 -s 172.19.104.14 -p tcp --dport 8000 -j ACCEPT...
3. restart iptables.
/etc/init.d/iptables restart
Or
service iptables restart
III. test
Access http: // 6.6.5.5: 8100 to access the WEB service on port 8000 of Node2.