/ etc / network / interfaces中定义的别名接口不能有多个默认网关.不幸的是,我想使用相同的接口访问2个不同的网络,我需要在同一个接口上定义2个地址和2个网关.
此别名接口必须位于eth1接口上,因为eth0用于本地网络.如果我只为主eth1接口定义一个网关,并手动为路由添加默认gw 1.2.3.4为别名eth1:0它可以工作.
但我希望它能在启动时自动正确设置.
这是我的最后一次试用/ etc / network / interfaces:
# The loopback network interface
auto lo
iface lo inet loopback
# The external network interface, address on university internal network
auto eth1
iface eth1 inet static
address 172.x.y.33
netmask 255.255.255.224
network 172.x.y.32
broadcast 172.x.y.63
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers x.x.x.x
dns-search mysite.org
# multiple gateways are not allowed, so I try to add them like that:
post-up route add default gw 172.x.y.62 metric 1
pre-down route del default gw 172.x.y.62
# external interface with external world IP address
auto eth1:0
iface eth1:0 inet static
address 1.2.3.1
netmask 255.255.255.128
network 1.2.3.0
broadcast 1.2.3.128
# dns on ensg dns
dns-nameservers x.x.x.x
dns-search mysite.org
# multiple gateways are not allowed, so I try to add them like that:
post-up route add default gw x.x.x.x metric 2
pre-down route del default gw x.x.x.x
# internal network for my cluster
auto eth0
iface eth0 inet static
address 10.1.1.1
netmask 255.255.255.0
network 10.1.1.0
broadcast 10.1.1.255
gateway 10.1.1.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 10.1.1.1 127.0.0.1
dns-search cluster
但是当我尝试调出一个界面时,我会得到:
root@server:~# ifconfig eth1:0 up
SIOCSIFFLAGS: Cannot assign requested address
我自己找不到进一步的解决方案,有没有人有想法?
谢谢,最好的问候.
解:
我终于解决了这个问题:
# The primary network interface
auto eth1
iface eth1 inet static
address a.b.c.1
netmask 255.255.255.128
network a.b.c.0
broadcast a.b.c.128
# this is the interface with the default gateway!
gateway a.b.c.126
dns-nameservers a.d.e.f
dns-search mysite.org
auto eth1:0
iface eth1:0 inet static
address 172.x.y.33
netmask 255.255.255.224
network 172.x.y.32
broadcast 172.x.y.63
# multiple gateways are not allowed, so we do it like that
post-up route add -net 172.x.y.32 netmask 255.255.255.224 gw 172.x.y.62
pre-down route del -net 172.x.y.32 netmask 255.255.255.224 gw 172.x.y.62
auto eth0
iface eth0 inet static
address 10.1.1.1
netmask 255.255.255.0
network 10.1.1.0
broadcast 10.1.1.255
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 10.1.1.1 127.0.0.1
dns-search cluster
解决方法:
此设置不起作用,因为别名接口在传统模式下无法使用网关(aka:/ etc / network / interfaces:
https://wiki.debian.org/NetworkConfiguration#Legacy_method
An alias interface should not have “gateway” or “dns-nameservers”;
dynamic IP assignment is permissible.
如果你使用ip在post-up上定义这条路线怎么样?
ip route通过x.x.x.x dev eth0:1添加默认值
这里唯一的问题是使用iproute你可能需要创建2个规则,每个链接一个,并设置优先级,同时保持默认表为空. LARC是你的朋友 – http://www.lartc.org/howto/lartc.rpdb.multiple-links.html
为什么使用iproute2而不是路由?因为路由,arp,ifconfig和它的朋友都是旧工具并且在deprecated的过程中,但是一些发行版仍然发布它们.