别名接口定义在/etc/网络/接口不能有多个默认网关。不幸的是我想使用相同的接口来访问2个不同的网络,并且我需要在同一接口上定义 2 个地址和 2 个网关。
该别名接口必须打开eth1接口因为以太网0在本地网络上使用。如果我只为主网关定义一个网关eth1接口,并手动route add default gw 1.2.3.4
为别名做以太坊1:0有用。
但我希望它在启动时正确设置自动地。
这是我最后一次审判/etc/网络/接口:
# 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
答案1
此设置不应该起作用,因为别名接口不能在传统模式下拥有网关(又名/etc/network/interfaces
::
https://wiki.debian.org/NetworkConfiguration#Legacy_method
别名接口不应包含“gateway”或“dns-nameservers”;允许动态 IP 分配。
如果您使用 ip 在 a 上定义此路由会怎么样post-up
?
ip route add default via x.x.x.x dev eth0:1
这里唯一的问题是,使用 iproute 您可能需要创建 2 条规则,每个链路一条规则,并设置优先级,同时保持默认表为空。 LARC 是你的朋友 -http://www.lartc.org/howto/lartc.rpdb.multiple-links.html
为什么使用iproute2
而不是route
?因为route, arp, ifconfig
它的朋友是旧工具并且正在被淘汰已弃用,但一些发行版仍然提供它们。