为什么这条静态路由没有生效?

Rei*_*ien 5 ubuntu routing ip networkmanager

原始问题

我正在运行 Ubuntu 和网络管理器。我有两个不同的接口,eth0eth1. 网络管理员已(据我所知)正确添加了此手动路由:

~$ ip route

default via 172.16.0.2 dev eth1  proto static 
10.0.0.0/8 via 172.16.0.2 dev eth1  proto static 
130.35.0.0/16 via 172.16.0.2 dev eth1  proto static 
...
172.16.0.0/12 dev eth1  proto kernel  scope link  src 172.16.0.15  metric 1 
192.135.82.0/24 via 172.16.0.2 dev eth1  proto static 
Run Code Online (Sandbox Code Playgroud)

eth0出现了,但在我看来这是一个单独的问题。即使给出了上述路由,IP 堆栈似乎更喜欢eth0

~$ ping 130.35.249.52
PING 130.35.249.52 (130.35.249.52) 56(84) bytes of data.
^C
--- 130.35.249.52 ping statistics ---
18 packets transmitted, 0 received, 100% packet loss, time 17132ms

~$ ping -Ieth1 130.35.249.52
PING 130.35.249.52 (130.35.249.52) from 172.16.0.15 eth1: 56(84) bytes of data.
64 bytes from 130.35.249.52: icmp_seq=1 ttl=57 time=210 ms
Run Code Online (Sandbox Code Playgroud)

此外,

~$ ip rule
0:  from all lookup local 
32766:  from all lookup main 
32767:  from all lookup default 

~$ netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         172.16.0.2      0.0.0.0         UG        0 0          0 eth1
10.0.0.0        172.16.0.2      255.0.0.0       UG        0 0          0 eth1
130.35.0.0      172.16.0.2      255.255.0.0     UG        0 0          0 eth1
...
172.16.0.0      0.0.0.0         255.240.0.0     U         0 0          0 eth1
192.135.82.0    172.16.0.2      255.255.255.0   UG        0 0          0 eth1

~$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:01:b1:f6 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::a00:27ff:fe01:b1f6/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:35:eb:24 brd ff:ff:ff:ff:ff:ff
    inet 172.16.0.15/12 brd 172.31.255.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe35:eb24/64 scope link 
       valid_lft forever preferred_lft forever
Run Code Online (Sandbox Code Playgroud)

如何强制 IP 堆栈遵守这些路由?

路由成功

~$ ip route get 130.35.249.52
130.35.249.52 via 172.16.0.2 dev eth1  src 172.16.0.15
    cache
Run Code Online (Sandbox Code Playgroud)

这种情况变得有点棘手。似乎第一次ping失败是暂时的,第二次pingeth1成功,然后后续ping才能eth0正确路由。我很难确定 IP 堆栈如何进入这种状态,但现在我将尝试解决一个不同的 DNS 相关问题。

Rei*_*ien 0

结果发现问题是 UDP 数据包没有被传递。我不知道为什么。TCP DNS 工作得很好。最后我network-manager-openconnect在VirtualBox中使用并只保留了一个虚拟适配器,并且它可以工作。