Dan*_*k82 3 linux networking routing ip ethernet
/etc/network/ interfaces 中定义的别名接口不能有多个默认网关。不幸的是,我想使用相同的接口来访问 2 个不同的网络,我需要在同一个接口上定义 2 个地址和 2 个网关。
这个别名接口必须在eth1 上接口上,因为eth0用于本地网络。如果我只为主eth1接口定义一个网关,并手动route add default 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
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将达到一个界面,我得到:
root@server:~# ifconfig eth1:0 up
SIOCSIFFLAGS: Cannot assign requested address
Run Code Online (Sandbox Code Playgroud)
我自己找不到进一步的解决方案,有人有想法吗?
谢谢,最好的问候。
解决方案:
我终于这样解决了:
# 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
Run Code Online (Sandbox Code Playgroud)
小智 5
这个设置不应该工作,因为别名接口不能在传统模式下有网关(又名/etc/network/interfaces::
https://wiki.debian.org/NetworkConfiguration#Legacy_method
别名接口不应有“网关”或“dns-nameservers”;允许动态 IP 分配。
如果你使用 ip 来定义这条路由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它的朋友是旧工具并且正在被弃用,但一些发行版仍然提供它们。