我的/etc/network/interfaces
样子是这样的:
auto lo
iface lo inet loopback
auto eth1
iface eth1 inet static
address 10.0.0.99
netmask 255.255.255.0
gateway 10.0.0.1
auto eth0
iface eth0 inet dhcp
重启机器后,我得到了
vagrant@precise64:~$ ip route
default via 10.0.2.2 dev eth0
default via 10.0.0.1 dev eth1 metric 100
10.0.0.0/24 dev eth1 proto kernel scope link src 10.0.0.99
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15
我该如何修改/etc/network/interfaces
,以便我的流量默认通过 10.0.0.1 而不是 10.0.2.2?我可以按如下方式手动执行此操作,但我不想在每次重启时都这样做:
vagrant@precise64:~$ sudo ip route del default via 10.0.2.2 dev eth0
vagrant@precise64:~$ ip route
default via 10.0.0.1 dev eth1 metric 100
10.0.0.0/24 dev eth1 proto kernel scope link src 10.0.0.99
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15
答案1
原来原因与此无关/etc/network/interfaces
。这台机器是流浪汉VM,默认情况下有一些额外的东西/etc/rc.local
:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Make sure eth0 is working. This works around Vagrant issue #391
dhclient eth0
exit 0
注释掉该dhclient eth0
行并重新启动会产生以下结果:
vagrant@precise64:~$ ip r
default via 10.0.0.1 dev eth1 metric 100
10.0.0.0/24 dev eth1 proto kernel scope link src 10.0.0.99
10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15