Linux
別名介面的多個預設網關
/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
但是當我嘗試調出一個界面時,我得到:
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
此設置不應該工作,因為別名介面在傳統模式下不能有網關(又名
/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
它的朋友是舊工具並且正在被棄用,但一些發行版仍然發布它們。