Ubuntu

為什麼這條靜態路由不生效?

  • April 7, 2014

原始問題

我正在執行 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 

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

此外,

~$ 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

如何強制 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

這種情況變得有點棘手。似乎第一次 ping 失敗是暫時的,第二次 pingeth1成功,然後後續 pingeth0正確路由。我很難確定 IP 堆棧是如何進入這種狀態的,但現在我將嘗試解決另一個與 DNS 相關的問題。

問題原來是UDP數據包沒有被傳遞。我不知道為什麼。TCP DNS 工作得很好。最後我network-manager-openconnect在VirtualBox中使用並且只保留了一個虛擬適配器,並且它可以工作。

引用自:https://unix.stackexchange.com/questions/122804