Port ing of iptables in CentOS

Source: Internet
Author: User
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.confConfiguration filenet.ipv4.ip_forward = 1The default value is 0. run the command again.sysctl -pMake 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.