IPv4 - Subnet and Routing
課程影片
第 7I 講 路由器運作原理以及網路互連技術 L07 9
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 →
Subnet 對路由表的影響
在引入 subnet 之後,如果路由器想找某一個 IP,就不用對網段裡面所有的 IP 線性搜尋,而是使用分治法:先找出該 IP 所屬的網段,再把封包交由該網段的路由器負責即可。這樣問題就變成「線性搜尋所有 IP」變成「先搜尋 subnet,再搜尋 subnet 中的特定 IP」。
演算法
具體的作法是:
- 路由表若連接 subnet 時,同時也會維護該 subnet 的 subnet mask。
- 若想知道一個 IP 是否屬於該 subnet,則把該 IP 跟該 subnet 對應的 subnet mask 做位元
&
。
- 之後去查路由表,並且依照這個結果決定往哪個 port 或哪台路由器送。總共有
- 如果發現這個結果,跟路由表其中一個 subnet 一樣,就把這個封包往那邊送。
- 如果路由表中沒有任何一個
例子
假定以下的網路拓樸:
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 →
並且假定 R1
的路由表為:
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 →
例子一:目的地是 H1
H1
的 IP 是 128.96.34.15
。所以:
- 把
128.96.34.15
跟路由表中的第一個 subnet 的 subnet mask (255.255.255.128
) 做位元 &
,這時會得到 128.96.24.0
。
- 這個結果恰好跟路由表的第一個 subnet 吻合,因此就把這個封包往 Interface 0 送。
例子二:送往 H5
H5
的 IP 是 128.96.34.131
。而路由表中的第二條,恰好滿足 (128.96.34.131 & subnet_mask) == subnet_ip
,所以就把這個封包往 Interface 1 送。