后端服务器nat共享上网

网关服务器外网IP eth0: 10.0.0.1

                 eth1: 192.168.1.1

1.在网关服务器开启转发功能

sysctl -p

grep "net.ipv4.ip_forward = 0" /etc/sysctl.conf 

sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g' /etc/sysctl.conf 

sysctl -p


2.设置网关服务器iptables的nat 转换

/etc/init.d/iptables stop

/sbin/iptables -t nat -A POSTROUTING -o eth0  -s 192.168.1.0/24 -j MASQUERADE 


3.后端局域网服务器需要上网的,内网IP需要设置为192.168.1.0/24网段IP。同时设置网关IP为网关服务器连接内网的接口IP也就是 192.168.1.1

  ifconfig eth0 192.168.1.100/24 up

  route  add default gw 192.168.1.1