日期:2014-05-16  浏览次数:21049 次

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


------解决方案--------------------
一般都是只配置一个网关作为默认路由,多网卡的其它路由都通过加子网路由来做
------解决方案--------------------
一个系统中就一个默认gateway的,其他你用路由来做吧