你可能是只在路由里面设置了走eth0的路由,没有对eth1上设置路由。
你可以用策略路由,先将默认网关走eth0的设一个高的优先级。将默认网关走eth1的设一个普通的优先级。
命令如下:
ip rule add table 200
ip route add default dev eth0 via gw table 200 (gw是你的网关)
ip route add default dev eth1 via gw
这样设置以后,在两条线都接通的情况下,会优先从eth0走
如果eth0断了,会改成从eth1走。
不过由个问题是当eth0断了以后,ip route add default dev eth0 via gw table 200
这条路由就消失了,在接上eth0以后要重新加入这条路由。
ip route add 192.168.1.0/24 dev eth0 src 192.168.1.1 table local100
ip route add 192.168.1.0/24 dev eth2 src 192.168.1.253 table local200
ip route add default dev eth0 table local100
ip route add default dev eth2 table local200
ip rule add from 192.168.1.1 table local100
ip rule add from 192.168.1.253 table local200