I have been troubled by this problem for at least two weeks. I have repeatedly reviewed a lot of information and can finally complete the configuration today. Now I'm so excited to write it down.
Requirement: I want to test ipp2p traffic control, so I need to build a test environment within the company. Build a dual-nic Linux machine between my network and my company. The specific hardware architecture diagram is as follows:
Internet
|
Company's intranet segment 192.168.4.0 (the gateway is 192.168.4.1)
|
Eth1 (IP 192.168.4.129)
Linux host (dual Nic)
Eth2 (IP 111.111.112.111)
|
My pc xp system (IP 111.111.112.112, Gateway 111.111.112.111)
The problem encountered in the early stage was that the Linux host could access the Internet and ping the company's internal network segment 192.168.4.0, but it could not Ping the XP system machine. This problem had been plagued for several days, the final solution is to disable the Windows Firewall. It turns out that the Windows Firewall blocks the ICMP packet so that the XP system can ping the dual network card of the Linux system (which cannot ping the company network ), but Linux cannot ping the XP system machine.
This problem has been solved, and now the XP system can be connected to the company's network segment 192.168.4.0, but also to the Internet
The solution is static routing settings + NAT translation of iptables, which enables the XP system (IP 111.111.112.112) to access the Internet through the IP address eth1 (IP 192.168.4.129) and implement Nat translation.
Static route configuration command
Route add-net 111.111.112.0/24 GW 111.111.112.111 Dev eth2
Route add-net 192.168.4.0/24 GW 192.168.4.129 Dev eth1
Route add default GW 192.168.4.1
Next, configure iptables.
Iptables-T nat-F
Iptables-T Nat-A postrouting-O eth1-s 111.111.112.112-j snat -- To 192.168.4.129
Iptables-T Nat-A prerouting-I eth1-D 192.168.4.129-J DNAT -- To 111.111.112.112
Also, enable kernel forwarding Echo 1>/proc/sys/NET/IPv4/ip_forward
My name is Red Hat 2.6.18-8. EL5 iptables v1.3.5.
After that, we found that the XP machine can ping the company's 192.168.4.0 network segment and access the internet.
Now attach the script
[Root @ localhost ~] # Echo 1>/proc/sys/NET/IPv4/ip_forward
[Root @ localhost ~] # Iptables-T nat-F
[Root @ localhost ~] # Iptables-T Nat-A postrouting-O eth1-s 111.111.112.112-j snat -- To 192.168.4.129
[Root @ localhost ~] # Iptables-T Nat-A prerouting-I eth1-D 192.168.4.129-J DNAT -- To 111.111.112.112
[Root @ localhost ~] # Route add-net 111.111.112.0/24 GW 111.111.112.111 Dev eth2
[Root @ localhost ~] # Route add-net 192.168.4.0/24 GW 192.168.4.129 Dev eth1
[Root @ localhost ~] # Route add default GW 192.168.4.1