Linux under CentOS use Iptables to do native port forwarding method (real available) __linux

Source: Internet
Author: User
Tags iptables
Forwarding from one computer to another port

Enable the network card forwarding feature
#echo 1 >/proc/sys/net/ipv4/ip_forward

Example: Access to 192.168.0.211:1521 Port from 192.168.0.132:21521 (new port)
A. The same port forwarding (192.168.0.132 1521 port access iptables-a rh-firewall-1-input-m State--state new-m tcp-p TCP--dport 1521-j accep T
Iptables-t nat-i prerouting-p tcp--dport 1521-j dnat--to
Iptables-t nat-i postrouting-p TCP--dport 1521-j Masquerade

B. Different port forwarding (192.168.0.132 21521 port access iptables-a rh-firewall-1-input-m State--state new-m tcp-p TCP--dport 21521-j ACC EPT)
Iptables-t nat-a prerouting-p tcp-m tcp--dport 21521-j dnat--to-destination 192.168.0.211:1521
Iptables-t nat-a postrouting-s 192.168.0.0/16-d 192.168.0.211-p tcp-m tcp--dport 1521-j SNAT--to-source .132


Above two equivalent configurations (simpler [specify network adapters]):
Iptables-t nat-a prerouting-p tcp-i eth0--dport 31521-j dnat--to 192.168.0.211:1521
Iptables-t nat-a Postrouting-j Masquerade

Save Iptables
#service iptables Save

#service iptables Restart

two uses the iptables to make the native port forwarding

The code is as follows:
Iptables-t nat-a prerouting-p tcp--dport 80-j REDIRECT--to-ports 8080

Estimating the appropriate addition of other parameters can also be done with different IP port forwarding.

If you need this machine to also be able to access, you need to configure the output chain (******** Special Note: Local access to the extranet port will be forwarded locally, resulting in the visit to the extranet, such as access to yown.com, is actually access to local, it is recommended not to do 80-port forwarding or specified purpose D localhost):
Iptables-t nat-a output-d localhost-p tcp--dport 80-j REDIRECT--to-ports 8080

Reason:
The extranet access needs to go through the prerouting chain, but the localhost does not go through the chain, so it needs to be output.

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.