Use iptables as a NAT proxy to access the Internet, iptablesnat
Background:
One server A cannot access the Internet and is connected to server B through the Intranet. Server B can access the Internet, and server A can also access the internet.
Intranet HOST: A eth1: 172.16.1.8 Internet host: B eth0: 10.0.0.61
Internet host: B eth1: 172.16.1.61
SNAT: Change the source address of the data packet. The firewall uses an external address to replace the local network address of the data packet. In this way, the host inside the network can communicate with the outside of the network.
1. Enable kernel route forwarding on server B that can access the Internet
# Temporary echo 1>/proc/sys/net/ipv4/ip_forwardsysctl-p # Permanent echo 'Net. ipv4.ip _ forward = 1'>/etc/sysctl. confsysctl-p
2. view the route table on the proxy server. And add the default gateway. Route add default gw 172.16.1.61
[root@localhost ~]# route -nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface172.16.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth10.0.0.0 172.16.1.6 0.0.0.0 UG 0 0 0 eth1
3. You can add SNAT rules on server B.
iptables -t nat -A POSTROUTING -o eth0 -s 172.16.1.0/24 -j SNAT --to 10.0.0.61
4. Save
Service iptables save # restart iptables service/etc/init. d/iptables restart
5. Verify that the Internet can be accessed normally.
Set iptables to boot automatically [root @ lb02 ~] # Chkconfig | grep iptables 0: off1: off2: on3: on4: on5: on6: off