Original:http://blog.sina.com.cn/s/blog_6ca646a0010126wl.html
Background:
There is a server can not access the Internet, and B server through the intranet to connect, B server to the Internet, to achieve a server can also be online.
A ip:192.168.0.35
B ip:192.168.0.146
SNAT: Change the source address of the packet. The firewall uses an external address to replace the local network address of the packet. This enables the network internal host to communicate with the network external.
1. On the Internet that Server B, to open the kernel routing forwarding function
Echo 1 >/proc/sys/net/ipv4/ip_forward
2. View the routing table on the Internet server A via proxy. and add a default gateway. Route add default GW 192.168.0.146
[Root@localhost ~]# Route-n
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.0.146 0.0.0.0 UG 0 0 0 eth0
3. Add Snat rule on Server B where you can access the Internet
Iptables-t nat-a postrouting-o eth0-s 192.168.0.0/24-j snat–-to
4. Save
Service Iptables Save
5. Verify that you can access the Internet normally.