Lab environment:
System: centos6.2 linux2.6
VMware Virtual Environment Test
Three machines are available: A, B, and C.
A has a NIC: eth1: 1923168.66.225
B: One NIC: eth0: 192.168.66.10
C: One NIC: eth0: 192.168.66.11
For some reason, I want B to send data packets to C but not directly, and a can exchange data packets with B and C. At this time, I want, B sends the data packet to a, and then a forwards the data packet to C. At the same time, a changes the destination address of the forwarded data packet to B, when C receives the packet forwarded by A, it is like B directly sends it to C.
You can use netflter/iptables
Configure:
$ Iptables-T filter-a forward-O eth1-p tcp-J accept # Forward a data packet $ iptables-T filter-a forward-I eth1-P TCP-J accept # change the destination IP address of the data before the route entry to the IP address of C, you can use the 8080 $ iptables-T Nat-A prerouting-p tcp-m tcp -- dport 8080-j dnat -- to-destination 192.168.66.10: 8080 # change the source IP address of the data packet to a's IP address $ iptables-T Nat-A postrouting-D 192.168.66.10-p tcp-m tcp -- dport 8080-j snat -- to-Source 192.168.66.11
There is another one. Don't forget to enable the forwarding function of the Linux dual-nic.
To enable the packet forwarding function to take effect automatically after the system starts, you need to modify the/etc/sysctl. conf file and add a line:
# Controls IP packet forwarding
Net. ipv4.ip _ forward = 1
Then, you can write an application for testing and use tcpdump to capture packets on the C host.
Lab reference:
How to enable the forwarding function for Linux dual-nicHttp://blog.chinaunix.net/uid-24172143-id-2049790.html
Iptables port forwardingHttp://meridian.dyndns.org/any.thing/d04.html
Forward and Nat rulesHttp://man.chinaunix.net/linux/redhat/rhel-sg-zh_cn-4/s1-firewall-ipt-fwd.html