Try   HackMD

802.1Q - Overview

課程影片

第 5A 講 IEEE 802.1Q 虛擬區域網路 (Virtual LAN) L04 1

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 →

第 5B 講 IEEE 802.1Q 虛擬區域網路 (Virtual LAN) L04 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 →

第 5C 講 IEEE 802.1Q 虛擬區域網路 (Virtual LAN) L04 3

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 →

功能

802.1Q 協定能讓一群 L2 的工作站形成一個虛擬的 LAN,這些虛擬的 LAN 形成的抽象層稱為 VLAN。

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 →

每個這樣的 VLAN 會有一個用以識別的 VID。更進一步,這樣的 VLAN 分割有以下功能:

  1. 一個這樣的 VLAN 中的每一個工作站未必在物理上直接相連,但是藉由 VLAN 的抽象化後,這個 VLAN 中的設備可以視為彼此處在一個「只包含這些設備的 LAN 上」。若這個 VLAN 中的其中一個成員廣播,這個廣播也只會被 VLAN 中的成員收到。
  2. 除此之外,這樣的 VLAN 中的成員,還可以動態地調整。
  3. 最後,分屬不同 VLAN 的工作站之間規定不能直接轉送封包,必須要藉由某個中 (比如說 router) 來轉送。或者說:VLAN 間的傳輸是由防火牆隔離的 (firewalled)。

劃分 VLAN

在 802.1Q 中,VLAN 的區分是以交換機的 port 作為劃分。在交換機開始運作前,要先在交換機上設定好「這台交換機的哪些 port 直接相連的設備會屬於同一個 VLAN」。這樣的設定稱為 port-based VLAN:

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 →

在這個設定方法中,每一個 port 都會有一個編號,用以識別其所屬的 VLAN 為何。這個編號稱為 PVID (Port VLAN-ID)。對於一個支援 VLAN 的設備,它會維護一個「哪個 VLAN 要往哪送」的表:

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 →

舉例來說,在這個設定中,Switch 1 的 2, 3, 4, 5 直接相連的設備屬於 VLAN 1。而對於 VLAN 2,除了與自己直接相連的 11, 12 號 port 之外,因為 Switch 3 中也有兩個屬於 VLAN 2 的 port,因此通往 Switch 3 的 7 號 port 也會在 VLAN 2 中。

除了使用 port 區分之外,影片中也提到可以使用 MAC 位址、IP 網段、不同的 L3 協定作為分割 VLAN 的依據。

Frame Tagging

劃分好 VLAN 之後,如果想要讓 VLAN 之間的傳輸有所區隔,就應該要有辦法區別一個封包正在哪個 VLAN 上傳輸,而這有兩種作法。首先,如果一個封包來自一個「交換機自身中,已知屬於某個 VLAN 的 port」,那麼這個封包就正在這個 port 的 PVID 所代表的 VLAN 上傳輸。

而除了使用「封包來自哪個 VLAN 上的 port」作為判斷依據外,802.1Q 中的另外一個機制,是在乙太網路封包中插入一個用以識別封包所屬 VLAN 的欄位。這一個插入的欄位就稱為 VLAN tag

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 →

VLAN 間傳輸

紀錄與設定自己的 port 屬於哪個 VLAN、在封包中插入 VLAN tag、識別封包上的 VLAN tag 等等功能,都需要有硬體本身的支援,因此並非所有支援乙太網路的設備都能直接支援 VLAN。在這樣的狀況下,就需要一些額外的機制,使得這些支援 VLAN 的設備與不支援 VLAN 的設備。

狀況一:大家都懂 VLAN - 所有封包都 TAG

這個可以算是一種「最好狀況」,所有人都會 VLAN,所以就可以放心的 tag 所有 VLAN。

狀況二:沒有人懂 VLAN - 所有封包都不 TAG

也就是這個 Link 周圍的設備都是不支援 VLAN 的設備。因為大家都不懂 VLAN,所以所有在這個 link 上流通的封包都不能帶有 VLAN tag。這其實變成「局部是 BLAN」的狀況。

狀況三:有人懂 VLAN,有人不懂 - 懂的人配合不懂的人

這時候 link 上的設備,可能各自屬於不同的 VLAN。而屬於某個 VLAN 的設備中,又可以區分為懂 VLAN 跟不懂 VLAN 的。如果這個 link 上屬於某個 VLAN 的所有設備,恰好也都支援 VLAN,那這個 VLAN 的封包在經過這個 link 時就可以帶有 VLAN tag。反正 link 上要收這個封包的設備恰好都懂 VLAN。

反之,如果這個 link 上屬於某個 VLAN 的設備中有不懂 VLAN 的,那這個 VLAN 的封包在經過這個 link 時,就要配合那些不懂 VLAN 的設備,不能有 VLAN tag。

Step 2:交換設定

在每一台交換機設定好 VLAN 之後,這些交換機在啟動之後應該要以某些方式來交換不同交換機上的設定。