ubuntu 多网卡配置网关不起作用的问题[分享]
项目上出了匪夷所思的问题,工控机有两个网卡,逻辑号分别是eth0和eth1,配置了两个网关,不过eth0只是备用网口,实际使用的是eth1。现象是始终ping不通外网机器,怀疑网关配置错误。使用route命令查看,发现默认网关是eth0的网关,而我们想要用的是eth1网卡,于是修改后配置/etc/network/interfaces如下:
auto lo
iface lo inet loopback
auto eth0 eth1
iface eth0 inet static
address 10.10.101.100
netmask 255.255.255.0
iface eth1 inet static
address 192.168.106.232
netmask 255.255.255.0
gateway 192.168.106.99
auto lo
iface lo inet loopback
auto eth0 eth1
iface eth0 inet static
address 172.31.101.100
netmask 255.255.255.0
iface eth1 inet static
address 192.168.106.233
netmask 255.255.255.0
dns-nameservers 101.202.172.35
up route add -net 192.168.106.0 netmask 255.255.255.0 gw 192.168.106.99 dev eth1
up route add -net 192.168.52.0 netmask 255.255.255.0 gw 192.168.106.99 dev eth1