条件:一台电脑,两块网卡,eth0联网,eth1内网
设置内网网卡参数
ifconfig eth1 192.168.31.1 broadcast 192.168.31.255 netmask 255.255.255.0
打开IP转发功能
/etc/sysctl.conf : net.ipv4.ip forward=1 取消注释, sudo sysctl -p
配置iptebles
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth1 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
host机器配置
ifconfig eth0 192.168.31.112
route add default gw 192.168.31.1