這是我的介面檔:
auto eth0
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
auto eth1
iface eth1 inet static
address 192.168.2.10
netmask 255.255.255.0
gateway 192.168.2.1
如果我重新啟動網路守護程序,我會收到此錯誤:eth1 is not up
。我想要兩個預設網關實現此處問題的接受答案中提到的內容。我的路由表應該是這樣的:
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.2.1 0.0.0.0 UG 0 0 0 eth1
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth1
ifconfig
我透過使用和命令得到了上表route add default gw
。但我想用文件來做/etc/network/interfaces
。我該怎麼做?
更新1:
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
up ip route del 192.168.1.0/24
post-up ip route add 192.168.1.0/24 dev eth0 metric 1
up route add default gw 192.168.1.1 metric 1
答案1
這個 /etc/network/interfaces 在 2.6.32-40 Ubuntu 10.04 LTS 上適用於我:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.254
post-up route add default gw 192.168.1.1 metric 1
pre-down route del default gw 192.168.1.1
auto eth1
iface eth1 inet static
address 192.168.2.10
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.254
post-up route add default gw 192.168.2.1 metric 2
pre-down route del default gw 192.168.2.1
我有兩個預設路由:
root@gamla:/etc/network# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 1 0 0 eth0
0.0.0.0 192.168.2.1 0.0.0.0 UG 2 0 0 eth1
注意指標。我明白你的問題了嗎?