一台ubuntu server有雙網卡,eno1和eno2
eno1是内網網卡配置為私有位址
auto eno1
iface eno1 inet static
pre-up ifconfig eno1 hw ether 70:e2:84:13:2c:3c
address 192.168.66.1
netmask 255.255.255.0
network 192.168.66.0
broadcast 192.168.66.255
eno2配置連接配接外網(專線)
auto eno2
iface eno2 inet static
address <外網IP>
netmask <子網路遮罩>
gateway <外網網關>
配置路由和NAT
su
echo > /proc/sys/net/ipv4/ip_forward
echo "10 ct" >> /etc/iproute2/rt_tables
ip route add default via <外網IP> table ct
ip rule add from / table ct pref
iptables -t nat -A POSTROUTING -s / -j SNAT --to <外網IP>