[Linux] 錯誤的 172.0.0.0 路由 (routing),導致連不上 Google

[Linux] 錯誤的 172.0.0.0 路由 (routing),導致連不上 Google

今天到公司打開電腦,突然發現桌機連不到 Google 了,

但使用 Wi-Fi 的筆電可以正常連上 Google,所以應該不是公司網路連外有問題,

而且其他同事似乎沒有遇到問題,看來只有我這台桌機連不到 Google…

 

先在桌機 ping 看看 Google,發現不行:

testuser@localhost ~ $ ping www.google.com
PING www.google.com (172.217.24.4) 56(84) bytes of data.
^C
--- www.google.com ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 999ms

 

不過從 ping 的結果可以看到 Google 的 IP 是 172.217.24.4…

看到 172. 開頭的 IP,直覺想到了公司內網 lab 的網段就是 172.22.x.y,

但 172.217 應該是屬於 public IP,並非 172.16.0.0-172.31.255.255 的內網範圍…

 

不過這倒是讓我想起來,之前為了在公司內部可以連到 lab 的 172.22 網段,

我曾經修改了 routing table,立刻看一下目前的 routing,

果真有一個 172.0.0.0 網段,都會往 10.1.119.250 這台 gateway 送過去:

testuser@localhost ~ $ route -n
Kernel IP routing table
Destination   Gateway       Genmask       Flags Metric Ref    Use Iface
0.0.0.0       10.1.119.254  0.0.0.0       UG    100    0        0 em1
172.0.0.0     10.1.119.250  255.0.0.0     UG    0      0        0 em1

 

看來真相大白了~我之前因為偷懶,把整個 172.x.y.z 網段都當作是 lab 網段,

所以設定了一個 172.0.0.0 的 routing destination,只要是 172.x.y.z 的 IP,

封包全都會往 10.1.119.250 這台 gateway 送。

但 10.1.119.250 想必看不懂 Google 的這個 172.217.24.4 public IP,所以封包八成被丟掉了…

 

解法是先把原本的這個 172.0.0.0 的 routing 刪除:

sudo /sbin/route del -net 172.0.0.0 gw 10.1.119.250 netmask 255.0.0.0

 

再重新加入 172.22.0.0 網段的專屬 routing:

sudo /sbin/route add -net 172.22.0.0 netmask 255.224.0.0 gw 10.1.119.250

 

這是修正後的 routing table:

testuser@localhost ~ $ route -n
Kernel IP routing table
Destination   Gateway       Genmask       Flags Metric Ref    Use Iface
0.0.0.0       10.1.119.254  0.0.0.0       UG    100    0        0 em1
172.22.0.0    10.1.119.250  255.255.0.0   UG    0      0        0 em1

 

修正之後,Google 就可以正常連線囉:

testuser@localhost ~ $ ping www.google.com
PING www.google.com (172.217.24.4) 56(84) bytes of data.
64 bytes from tsa01s07-in-f4.1e100.net (172.217.24.4): icmp_seq=1 ttl=51 time=2.60 ms
64 bytes from tsa01s07-in-f4.1e100.net (172.217.24.4): icmp_seq=2 ttl=51 time=2.80 ms

 

結論:routing table 還是不能隨便亂設定呀…

也千萬別偷懶,用一個超大的 IP 範圍,不小心就會把外網的 IP 都當成內網了~

 

(本頁面已被瀏覽過 556 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料