一、實驗說明:按照網絡拓撲圖連接並設置好PC機的IP地址,要求PC1、PC2在VLAN 12上訪問,PC3、PC4在VLAN 34上訪問,PC1與PC2互聯互通,PC3與PC4互聯互通,VLan 12 與VLan 34互不相通,以實現隔離局域網的廣播域。附圖如下:
二、思路:
①創建VLAN
②設置access模式訪問固定Vlan
③設置turnk模式傳輸多個Vlan
④驗證配置
⑤連通測試
三、主要步驟:
@交換機一的基本配置
Switch>enable
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#no ip domain lookup
Switch(config)#hostname SW1
@在交換機一上創建Vlan
SW1(config)#vlan 12
SW1(config-vlan)#exit
SW1(config)#vlan 34
SW1(config-vlan)#exit
@在交換機一上設置access模式
SW1(config)#interface f0/1
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 12 //將access模式的端口放入VLan 12 中
SW1(config-if)#no shutdown //最好開啓端口,以防萬一
SW1(config-if)#exit
SW1(config)#interface f0/4
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 34 //將access模式的端口放入VLan 34 中
SW1(config-if)#no shutdown //最好開啓端口,以防萬一
SW1(config-if)#exit
SW1#show vlan brief
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/2, Fa0/3, Fa0/5, Fa0/6……
12 VLAN0012 active Fa0/1
34 VLAN0034 active Fa0/4
……
@在交換機一上設置交換機互聯的端口爲trunk模式
SW1(config)#interface f0/24
SW1(config-if)#switchport mode trunk
SW1(config-if)#end
%SYS-5-CONFIG_I: Configured from console by console
@驗證trunk接口
SW1#show interface trunk
Port Mode Encapsulation Status Native vlan
Fa0/24 on 802.1q trunking 1
Port Vlans allowed on trunk
Fa0/24 1-1005
Port Vlans allowed and active in management domain
Fa0/24 1,12,34
……
------------------------------------------------------------------
在交換機2上進行類似操作,註解略
Switch>enable
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#no ip domain lookup
Switch(config)#hostname SW2
SW2(config)#vlan 12
SW2(config-vlan)#exit
SW2(config)#vlan 34
SW2(config-vlan)#exit
SW2(config)#interface f0/2
SW2(config-if)#switchport mode access
SW2(config-if)#switchport access vlan 12
SW2(config-if)no shutdown
SW2(config-if)#exit
SW2(config)#interface f0/3
SW2(config-if)#switchpor mode access
SW2(config-if)#switchport access vlan 34
SW2(config-if)no shutdown
SW2(config-if)#exit
SW2(config)#interface f0/24
SW2(config-if)#switchport mode trunk
SW2(config-if)#exit
SW2(config)#end
SW2#show vlan brief
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/1, Fa0/4, Fa0/5, Fa0/6……
12 VLAN0012 active Fa0/2
23 VLAN0023 active
……
SW2#show interface trunk
Port Mode Encapsulation Status Native vlan
Fa0/24 on 802.1q trunking 1
Port Vlans allowed on trunk
Fa0/24 1-1005
Port Vlans allowed and active in management domain
Fa0/24 1,12,23,34,111
……
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
實驗結果:
在PC1~PC4命令行界面用ping命令驗證連通性,結果PC1與PC2互聯互通,PC3與PC4互聯互通,VLan 12 與VLan 34互不相通。
四、延伸:如何刪除 VLAN ?
1、首先將 VLAN 的成員端口移除;
SW1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
@將端口fas0/解除固定訪問vlan14,端口變回默認的 vlan 1
SW1(config)#interface f0/1
SW1(config-if)#no switchport access vlan 12
SW1(config-if)#exit
@其次刪除不再使用的VLAN號
SW1(config)#no vlan 12
SW1(config)#end
五、實驗總結:
1、trunk鏈路發送出去的數據是帶有vlan標籤的,僅有交換機、路由器等網絡設備才能認識,PC是無法識別的,所以接PC的端口,不可以配置爲trunk,trunk模式用於配置在交換設備上,允許不同VLan的數據包通過。
2、Access鏈路發送出去的數據是不帶有任何標籤的,access模式用於配置在非交換設備上,一口端口只能允許指定的那個Vlan數據通行。
3、trunk 中存在一個特殊的 VLAN --native VLAN (本地/本徵 VLAN), 該 vlan 中的 流量是沒有標籤 的,默認值爲 vlan 1。
4、當trunk鏈路收到一個沒有標籤的數據包時,轉發給本地交換機的 native vlan 中的成員端口,不會將其丟棄.