1. 程式人生 > 實用技巧 >不同VLAN下實現網路互相通訊(配置port trunk pvid vlan進行資料轉發)

不同VLAN下實現網路互相通訊(配置port trunk pvid vlan進行資料轉發)

1. 兩臺交換機同一網段,不同VLAN實現網路互通,邏輯拓撲圖如下:

  需求:實現VLAN 10與VLAN20之間的網路互通

在LSW 12交換機進行如下命令列配置:

<HuaWei>system-view            #切換系統檢視
[Huawei]sysname test            #將交換機命名為test
[test]vlan 10            #建立vlan 10
[test-vlan10]description test            #為vlan 10描述為test
[test-vlan10]quit                #退出


#介面配置
[test]
interface Ethernet0/0/1 #進入e0/0/1介面 [test-Ethernet0/0/1]port link-type access #將e0/0/1介面鏈路型別設定為access [test-Ethernet0/0/1]port default vlan 10 #將e0/0/1介面劃分至vlan 10中 [test-Ethernet0/0/1]quit #退出 [test]interface e0/0/2 #進入e0/0/2介面;Ethernet0/0/2可簡寫 [test-Ethernet0/0/2]port link-type access #將e0/0
/2介面鏈路型別設定為access [test-Ethernet0/0/2]port default vlan 10 #將e0/0/2介面劃分至vlan 10中 [test-Ethernet0/0/2]quit #退出 [test]interface e0/0/3 #進入e0/0/3介面 [test-Ethernet0/0/3]port link-type trunk #將e0/0/3介面鏈路型別設定為trunk [test-Ethernet0/0/3]port trunk allow-pass vlan 10 #只允許vlan10資料通過 [test
-Ethernet0/0/3]display port vlan #檢視埠資訊 Port Link Type PVID Trunk VLAN List ------------------------------------------------------------------------------- Ethernet0/0/1 access 10 - Ethernet0/0/2 access 10 - Ethernet0/0/3 trunk 1 1 10 Ethernet0/0/4 hybrid 1 - Ethernet0/0/5 hybrid 1 - Ethernet0/0/6 hybrid 1 - Ethernet0/0/7 hybrid 1 - Ethernet0/0/8 hybrid 1 - Ethernet0/0/9 hybrid 1 - Ethernet0/0/10 hybrid 1 - Ethernet0/0/11 hybrid 1 - Ethernet0/0/12 hybrid 1 - Ethernet0/0/13 hybrid 1 - Ethernet0/0/14 hybrid 1 - Ethernet0/0/15 hybrid 1 - Ethernet0/0/16 hybrid 1 - Ethernet0/0/17 hybrid 1 - Ethernet0/0/18 hybrid 1 - Ethernet0/0/19 hybrid 1 - Ethernet0/0/20 hybrid 1 - Ethernet0/0/21 hybrid 1 - Ethernet0/0/22 hybrid 1 - GigabitEthernet0/0/1 hybrid 1 - GigabitEthernet0/0/2 hybrid 1 -

在LSW 13交換機上也做相同的配置:

<Huawei>system-view            #切換至系統檢視
[Huawei]sysname technology            #將交換機命名為technology
[technology]vlan 20            #建立vlan 20
[technology-vlan20]description technology            #vlan 20描述為technology
[technology-vlan20]quit            #退出

#介面配置
[technology]interface e0/0/1            #進入e0/0/1介面
[technology-Ethernet0/0/1]port link-type access        #鏈路型別為access
[technology-Ethernet0/0/1]port default vlan 20            #劃分至vlan 20
[technology-Ethernet0/0/1]quit        #退出

[technology]interface e0/0/2            #進入e0/0/2介面
[technology-Ethernet0/0/2]port link-type access        #鏈路型別為access
[technology-Ethernet0/0/2]port default vlan 20            #劃分至vlan 20
[technology-Ethernet0/0/2]quit            #退出

[technology]interface e0/0/3            #進入e0/0/3介面
[technology-Ethernet0/0/3]port link-type trunk            #鏈路型別為trunk
[technology-Ethernet0/0/3]port trunk allow-pass vlan 20            #只允許vlan 20資料通過
[technology-Ethernet0/0/3]quit            #退出


[technology]display port vlan            #查詢埠資訊


Port                    Link Type    PVID  Trunk VLAN List
-------------------------------------------------------------------------------
Ethernet0/0/1           access       20    -                                   
Ethernet0/0/2           access       20    -                                   
Ethernet0/0/3           trunk        1     1 20
Ethernet0/0/4           hybrid       1     -                                   
Ethernet0/0/5           hybrid       1     -                                   
Ethernet0/0/6           hybrid       1     -                                   
Ethernet0/0/7           hybrid       1     -                                   
Ethernet0/0/8           hybrid       1     -                                   
Ethernet0/0/9           hybrid       1     -                                   
Ethernet0/0/10          hybrid       1     -                                   
Ethernet0/0/11          hybrid       1     -                                   
Ethernet0/0/12          hybrid       1     -                                   
Ethernet0/0/13          hybrid       1     -                                   
Ethernet0/0/14          hybrid       1     -                                   
Ethernet0/0/15          hybrid       1     -                                   
Ethernet0/0/16          hybrid       1     -                                   
Ethernet0/0/17          hybrid       1     -                                   
Ethernet0/0/18          hybrid       1     -                                   
Ethernet0/0/19          hybrid       1     -                                   
Ethernet0/0/20          hybrid       1     -                                   
Ethernet0/0/21          hybrid       1     -                                   
Ethernet0/0/22          hybrid       1     -                                   
GigabitEthernet0/0/1    hybrid       1     -                                   
GigabitEthernet0/0/2    hybrid       1     -    

在PC 30上執行命令列視窗,ping 10.0.1.4發現是無法通訊的,在LSW 13交換機的 Ethernet0/0/3 口抓包是有ARP報文通過,但是交換機發現是報文VLAN標籤是vlan 10的,所以交換機會丟棄這些資料包而不進行轉發,在LSW 13交換機的Ethernet0/0/2 口抓包是沒有ARP報文經過

在LSW 12交換機上配置:

<test>system-view             #進入系統檢視
[test]interface e0/0/3            #進入e0/0/3介面
[test-Ethernet0/0/3]port trunk pvid vlan 10            #剝掉vlan 10資料標籤進行轉發
[test-Ethernet0/0/3]display this            #查詢e0/0/3介面配置

#
interface Ethernet0/0/3
 port link-type trunk
 port trunk pvid vlan 10
 port trunk allow-pass vlan 10
#
return


[test]display current-configuration interface         #查詢詳細的介面資訊


#
interface Vlanif1
#
interface MEth0/0/1
#
interface Ethernet0/0/1
 port link-type access
 port default vlan 10
#
interface Ethernet0/0/2
 port link-type access
 port default vlan 10
#
interface Ethernet0/0/3
 port link-type trunk
 port trunk pvid vlan 10
 port trunk allow-pass vlan 10
#
interface Ethernet0/0/4
#
interface Ethernet0/0/5
#
interface Ethernet0/0/6
#
interface Ethernet0/0/7
#
interface Ethernet0/0/8
#
interface Ethernet0/0/9
#
interface Ethernet0/0/10
#
interface Ethernet0/0/11
#
interface Ethernet0/0/12
#
interface Ethernet0/0/13
#
interface Ethernet0/0/14
#
interface Ethernet0/0/15
#
interface Ethernet0/0/16
#
interface Ethernet0/0/17
#
interface Ethernet0/0/18
#
interface Ethernet0/0/19
#
interface Ethernet0/0/20
#
interface Ethernet0/0/21
#
interface Ethernet0/0/22
#
interface GigabitEthernet0/0/1
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
return

在LSW 13交換機上配置:

<technology>system-view            #切換系統檢視
[technology]interface e0/0/3            #進入介面檢視
[technology-Ethernet0/0/3]port trunk pvid vlan 20            #剝掉vlan 20資料標籤進行轉發

科普交換機工作原理:

(1)同網段本身是可以直接通訊的,是不同VLAN在阻礙他們之間的交流,可以把VLAN資訊拿掉就可以恢復之間通訊了

(2)VLAN標籤:

    tag;帶有vid的幀就叫tag,交換機發送的幀都帶vlan資訊

    untag;不帶vid的幀,網絡卡傳送的幀都不帶vlan資訊

(3)交換機轉發原理:

  • 在交換機內部埠間的通訊,是必須帶VLAN ID的,必須帶標籤!
  • 預設情況,所有埠都在VLAN 1中,即所有埠 PVID = 1
  • PVID 一個埠可以屬於多個VLAN,但只能有一個PVID
  • acess埠收到不帶tag的幀,打上pvid,進入交換機
  • trunk埠,收到不帶tag的幀,打上pvid,進入交換機
  • trunk埠,傳送 vid=PVID 的幀,剝離tag後傳送,此時,該幀就變成網絡卡可以識別的幀

(4)資料包具體流向如下:

  1,PC 30傳送無tag幀進入交換機LSW 12的Ethernet 0/0/1,被打上vid=pvid=10的tag

  2,經過LSW 12的Ethernet 0/0/3時,vid=10=pvid,剝離tag,傳送給LSW 13

  3,被剝離tag幀進入LSW 13的Ethernet 0/0/3,被打上vid=pvid=20的tag

  4,vid=20的幀經過LSW 13的Ethernet 0/0/2,vid=20=pvid,剝離tag,傳送給PC 33

  5、PC 33收到無tag幀,可以識別,通訊完成!

最後驗證,在PC 30上ping 10.0.1.4,資料可以正常通訊!