設定預設網路介面

設定預設網路介面

我的/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 

相關內容