IPv4 - Routing Problem
課程影片
第 7D 講 路由器運作原理以及網路互連技術 L07 4
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
第 7E 講 路由器運作原理以及網路互連技術 L07 5
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
第 7B 講 路由器運作原理以及網路互連技術 L07 2
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
目的:在不知道網路全貌的狀況下把封包送到目的地
Router 在收到一個封包時,會先把它儲存起來,並且把這個封包往「可能到達目的地」的地方發送。之所以說是「可能」,是因為整個網際網路很大,所以每個 Router 都只知道離自己較近 IP 的那些節點,而不知道整條路徑的全貌。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
所以一個封包傳送的過程,其實就像是「不斷地問 router 要往哪個方向走」,然後試著找到目的地。這就像是迷路時,要你在沒有 Google Map 或導航,只看路牌的狀況下,想辦法到達目的地:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
路由的過程
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
例子一:由 B 傳給 Y
因為 與 在同一個 LAN 上,所以不用借助路由器。只要 準備以下的封包就好:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
例子二:B 傳送給 A
因為 與 位於不同的 LAN 上,所以沒辦法直接傳輸。因此 就只能把責任丟給路由器,祈禱路由器有辦法找到 。因此, 需要先把資料網路由器送,也就是準備以下的封包:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
從 L3 的角度來看這個傳輸,因為 IP 到 IP 間傳送訊息,所以這個 IP 表頭的目的地仍然是 。但從 L2 的角度來說
Router 收到這個封包之後,就根據這個封包中的 IP 表頭的目的去查 routing table,看看該往哪送。以這邊為例,恰好 「直接相連」,因此就直接傳送給 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
術語:Routing Table
每個 Router 都會紀錄一部分的「要通往哪個 IP 位址的話,要往哪邊送?」的表。這個表稱為 routing table 或 forwarding table。概念上來說,會像下面這個表:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
在這個例子中,IP 位址為 140.114.77.0
與 140.114.78.0
的裝置直接與該該 Router 相連,而 140.114.79.0
則需要請 Router Z 幫忙轉送。
可以把這個 routing table 想像成是高速公路的路牌。高速公路的路牌會指示哪個車道可以往哪個目的地。
路由的原則 –- 三種狀況
狀況一:直接相連 –- 查 MAC Address
第一個狀況是這個 Router 跟該 IP 代表的設備直接相連。所以這時 Routing 問題就簡化成了一個 Link 的兩端傳送的問題。
這時候就可以去查「IP 對 MAC Address」的表,決定要往哪個 MAC Address 送:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
狀況二:間接相連 –- 送給其它 Router
這個狀況是:雖然沒有直接連接,但是 routing table 知道另外一個 router 可以到達該 IP。這時就會把封包轉送給那個 Router,請它幫忙送給目的地。舉例來說,上述的 140.114.79.0
就是這個例子。
狀況三:完全沒有頭緒 –- 送給 Default Port
這個狀況是:一個 IP 完全沒出現在 routing table 上時。這時就往 default port 送。
問題:表上要放哪些東西?
因為所有 IP 位址有 40 億個,所以這個 routing table 並不能列舉出所有在 internet 上面的設備,就像高速公路的路牌不會包含全台灣的鄉鎮市那樣。
那這個 routing table 裡面要存哪幾條目的地的資訊呢?通常只會存離自己較近的一些目的地。這是因為 routing 問題是依照範圍由大到小來分治的。舉例來說,整個網路會分為較大的「自治區」(AS, autonomous section),這樣就可以先把目的地 IP 依照「在自治區內」或「在自治區外」分割。若在同一個「自治區」內,那問題規模就從整個網際網路縮小到一個自治區; 若在自治區外,那任務就換成把封包送到該自治區。
這個機制跟郵政系統滿像的。信會先送到一個國家,再送到一個行政區,再送到特定的鄉鎮市的郵局,最後送到家裡。