一台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 1 > /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 192.168.66.0/24 table ct pref 100
iptables -t nat -A POSTROUTING -s 192.168.66.0/24 -j SNAT --to <外网IP>