將一個 IP 位址設定為特定網路介面的路由時出現問題

將一個 IP 位址設定為特定網路介面的路由時出現問題

對於一個 IP 位址( aaa.bb.cd ),我需要透過 eth1 而不是 eth0 連接(這是預設位址,並且應該保持預設位址,但我認為添加 eth1 後不會這樣做。

我使用命令 <- 添加了自己的最後一條規則route add -host 172.27.4.213 dev eth1,我猜這是不正確的。

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.1        0.0.0.0         UG    0      0        0 eth1
10.0.0.0        0.0.0.0         255.255.0.0     U     0      0        0 eth1
10.0.0.0        0.0.0.0         255.255.0.0     U     0      0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-2eeb687f709e
172.19.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-0971950c62b2
172.20.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-c4f8472e3ea8
172.21.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-197f22a151b6
172.22.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-d1df5bfeb2d6
172.24.0.0      0.0.0.0         255.255.0.0     U     0      0        0 br-e00c82e13142
aaa.bb.c.d      0.0.0.0         255.255.255.255 UH    0      0        0 eth1

$ ip a show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:b5:7d:7b brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.27/16 brd 10.0.255.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feb5:7d7b/64 scope link 
       valid_lft forever preferred_lft forever

$ ip a show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:b5:7d:85 brd ff:ff:ff:ff:ff:ff
    inet 10.0.1.170/16 brd 10.0.255.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feb5:7d85/64 scope link 
       valid_lft forever preferred_lft forever

/etc/網路/接口

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
    address 10.0.0.27
    netmask 255.255.0.0
    gateway 10.0.0.1
    dns-nameservers 10.0.0.2

auto eth1
allow-hotplug eth1
iface eth1 inet dhcp

相關內容