这是我的接口文件:
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
注意指标。我明白你的问题了吗?