iptables开启NAT及共享上网命令

启用NAT echo “1” > /proc/sys/net/ipv4/ip_forward (开启IP 转发)

公网到内网 iptables -t nat -A PREROUTING -p tcp -d 1.2.3.4 –dport 10096 -j DNAT –to-destination 192.168.1.1:3389

内网到公网 iptables -t nat -A POSTROUTING -p tcp -s 192.168.1.1 –sport 3389 -j SNAT –to-source 1.2.3.4:10096

共享上网 192.168.1 段允许上网 iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT –to 1.2.3.4