Iptables port forwarding settings for a single NIC
Source: Internet
Author: User
Pc11.1.1.1pc22.2.2.2port80port801. First, the net. ipv4.ip _ forward1 in the/etc/sysctl. conf configuration file is 0 by default, which allows iptalbesFORWARD. 2. there is an iptables file in the/etc/rc. d/init. d directory, in the following format:./iptabl pc1 1.1.1.1 pc2 2.2.2.2
Port80 port 80
1. First, the net. ipv4.ip _ forward = 1 in the/etc/sysctl. conf configuration file is 0 by default.
This allows iptalbes FORWARD.
2. in/ Etc/rc. d/init. dDirectory has IptablesFile in the following format:
Usage:./iptables {start | stop | restart | condrestart | status | panic | save}
Equivalent to service iptables {....}
Stop the iptables service, clear previous rules, and save disks.
To /Etc/rc. d/init. dDirectory,
Run
./Iptables stop Iptalbes-F
Iptalbes-X
Iptalbes-Z
./Iptables save
3. reconfigure rules
Iptables-t nat-a prerouting-d 1.1.1.1-p tcp -- dport 80-jDNAT -- to-destination 2.2.2.2: 80
Iptables-t nat-a postrouting-d 2.2.2.2-p tcp -- dport 80-jSNAT -- to 1.1.1.1
Iptables-a forward-o eth0-d 2.2.2.2-p tcp -- dport 80-jACCEPT
Iptables-a forward-I eth0-s 2.2.2.2-p tcp -- sport 80-jACCEPT
It should be noted that the system does not perform SNAT until the packets are sent out during routing and overconsideration.
There is a special case of SNAT which ip spoofing is called Masquerading. we recommend that you use it when using dial-up Internet access, or use it when the valid ip address is not fixed. For example
Iptables-t nat-a postrouting-o ppp0-j MASQUERADE
We can see that there is no need to explicitly specify the source IP address and other information at this time.
4. new rule disks
./Iptables save
After saving the disk
/Etc/sysconfig/iptables
In this file
5. start the iptables service.
./Iptables start
There is a package flow in the/proc/net/ip_conntrack file
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