nat

Posted by Struggle on 2019-03-23

Centos7.x设置NAT共享上网
1.开启共享上网(带公网的节点)

1
firewall-cmd --zone=public --add-masquerade --permanent && firewall-cmd --reload

2.开启内核转发(带公网的节点)

1
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf && sysctl -p

3.内网机器设置默认网关为公网机器的内网ip

ubuntu14.04

1
2
3
1 echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf && sysctl -p
2 iptables -t nat -A POSTROUTING -o 外网网卡 -j MASQUERADE
3 iptables -t nat -A POSTROUTING -s 内网ip段 -o 外网网卡 -j SNAT --to 本机内网ip