vlan的創建與划分
一、實驗目的:
1.了解vlan的工作原理;
2.學習基於端口划分vlan的方法;
3.了解跨交換機的相同vlan之間的通信;
4.進一步學習交換機端口的配置命令。
二、實驗原理:
VLAN(Virtual Local Area Network)即虛擬局域網,是一種通過將局域網內的設備邏輯地而不是物理地划分成一個個網段從而實現虛擬工作組的新興技術。
VLAN技術允許網絡管理者將一個物理的LAN邏輯地划分成不同的廣播域(或稱虛擬LAN,即VLAN),每一個VLAN都包含一組有着相同需求的計算機工作站,與物理上形成的LAN有着相同的屬性。但由於它是邏輯地而不是物理地划分,所以同一個VLAN內的各個工作站無須被放置在同一個物理空間里,即這些工作站不一定屬於同一個物理LAN網段。一個VLAN內部的廣播和單播流量都不會轉發到其他VLAN中,從而有助於控制流量、減少設備投資、簡化網絡管理、提高網絡的安全性。
VLAN是為解決以太網的廣播問題和安全性而提出的一種協議,它在以太網幀的基礎上增加了VLAN頭,用VLAN ID把用戶划分為更小的工作組,限制不同工作組間的用戶二層互訪,每個工作組就是一個虛擬局域網。虛擬局域網的好處是可以限制廣播范圍,並能夠形成虛擬工作組,動態管理網絡。
三、實驗設備:
pc機、交換機
四、實驗拓撲圖(拓撲圖上要標明所用交換機型號、所用交換機的端口號以及各主機配置的IP地址):
1.同一個交換機上的vlan划分:將四台計算機連接到一台交換機上,將其中兩台計算機划分到一個vlan中,另兩台計算機划分到另一個vlan中,驗證同vlan中的計算機和不同vlan中的計算機之間的通信。注:vlan的名字不能用vlan1。
2.進行跨交換機的相同vlan之間的計算機和不同vlan之間的計算機的通信實驗。
五、實驗過程(配置過程):
實驗一:一個交換機上實現虛擬局域網拓撲圖
各主機配置的IP地址
pc0: 192.168.101.3,連接端口F0/1
pc1: 192.168.101.4,連接端口F0/2
pc2: 192.168.101.5,連接端口F0/3
pc3: 192.168.101.6,連接端口F0/4
步驟1:划分子網,在交換機switch0上創建虛擬局域網VLAN11和VLAN22
Switch>enable
Switch#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname S1
S1(config)#vlan 22
S1(config-vlan)#name T22
S1(config-vlan)#exit
S1(config)#vlan 11
S1(config-vlan)#name T11
S1(config-vlan)#exit
S1(config)#
驗證虛擬局域網VLAN11和VLAN22已創建成功:
S1#show vlan
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/1, Fa0/2, Fa0/3, Fa0/4
Fa0/5, Fa0/6, Fa0/7, Fa0/8
Fa0/9, Fa0/10, Fa0/11, Fa0/12
Fa0/13, Fa0/14, Fa0/15, Fa0/16
Fa0/17, Fa0/18, Fa0/19, Fa0/20
Fa0/21, Fa0/22, Fa0/23, Fa0/24
Gig1/1, Gig1/2
11 T11 active
22 T22 active
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 0 0
11 enet 100011 1500 - - - - - 0 0
22 enet 100022 1500 - - - - - 0 0
1002 fddi 101002 1500 - - - - - 0 0
1003 tr 101003 1500 - - - - - 0 0
1004 fdnet 101004 1500 - - - ieee - 0 0
1005 trnet 101005 1500 - - - ibm - 0 0
Remote SPAN VLANs
------------------------------------------------------------------------------
Primary Secondary Type Ports
------- --------- ----------------- ------------------------------------------
步驟2:將pc0和pc3划分到虛擬網段vlan11,pc1和pc2划分到虛擬網段vlan22.
Switch>enable
Switch#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname S1
S1(config)#vlan 22
S1(config-vlan)#name T22
S1(config-vlan)#exit
S1(config)#vlan 11
S1(config-vlan)#name T11
S1(config-vlan)#exit
S1(config)#
驗證為VLAN11和VLAN22分配端口成功
S1#show vlan
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/5, Fa0/6, Fa0/7, Fa0/8
Fa0/9, Fa0/10, Fa0/11, Fa0/12
Fa0/13, Fa0/14, Fa0/15, Fa0/16
Fa0/17, Fa0/18, Fa0/19, Fa0/20
Fa0/21, Fa0/22, Fa0/23, Fa0/24
Gig1/1, Gig1/2
11 T11 active Fa0/1, Fa0/4
22 T22 active Fa0/2, Fa0/3
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 0 0
11 enet 100011 1500 - - - - - 0 0
22 enet 100022 1500 - - - - - 0 0
1002 fddi 101002 1500 - - - - - 0 0
1003 tr 101003 1500 - - - - - 0 0
1004 fdnet 101004 1500 - - - ieee - 0 0
1005 trnet 101005 1500 - - - ibm - 0 0
Remote SPAN VLANs
------------------------------------------------------------------------------
Primary Secondary Type Ports
------- --------- ----------------- ------------------------------------------
步驟3:檢查4台pc之間的通信情況
pc0 ping pc3
pc2 分別ping pc1和pc0
實驗二:跨交換機實現虛擬局域網
交換機Switch3端口0/1和Switch4端口0/1相連
pc0: 192.168.11.3,連接交換機Switch3端口0/2
pc3: 192.168.11.6,連接交換機Switch3端口0/3
pc1: 192.168.11.4,連接交換機Switch4端口0/2
pc2: 192.168.11.5,連接交換機Switch4端口0/3
步驟1:將交換機Switch3重命名為s1並在S1上創建虛擬局域網VLAN11和VLAN22並為之分配端口。
Switch>enable
Switch#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname S1
S1(config)#vlan 11
S1(config-vlan)#name T11
S1(config-vlan)#exit
S1(config)#interface fastethernet 0/2
S1(config-if)#switchport access vlan 11
S1(config-if)#exit
S1(config)#vlan 22
S1(config-vlan)#name T22
S1(config-vlan)#exit
S1(config)#interface fastethernet 0/3
S1(config-if)#switchport access vlan 22
S1(config-if)#exit
S1(config)#exit
S1#
%SYS-5-CONFIG_I: Configured from console by console
S1#show vlan
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/1, Fa0/4, Fa0/5, Fa0/6
Fa0/7, Fa0/8, Fa0/9, Fa0/10
Fa0/11, Fa0/12, Fa0/13, Fa0/14
Fa0/15, Fa0/16, Fa0/17, Fa0/18
Fa0/19, Fa0/20, Fa0/21, Fa0/22
Fa0/23, Fa0/24, Gig1/1, Gig1/2
11 T11 active Fa0/2
22 T22 active Fa0/3
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 0 0
11 enet 100011 1500 - - - - - 0 0
22 enet 100022 1500 - - - - - 0 0
1002 fddi 101002 1500 - - - - - 0 0
步驟2:將S1的F0/1端口設置為trunk模式
S1#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
S1(config)#interface fastethernet 0/1
S1(config-if)#switchport mode trunk
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
S1(config-if)#exit
S1(config)#exit
S1#show interfaces fastEthernet 0/1 switchport
Name: Fa0/1
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: trunk
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 1 (default)
Voice VLAN: none
Administrative private-vlan host-association: none
Administrative private-vlan mapping: none
Administrative private-vlan trunk native VLAN: none
Administrative private-vlan trunk encapsulation: dot1q
Administrative private-vlan trunk normal VLANs: none
Administrative private-vlan trunk private VLANs: none
Operational private-vlan: none
Trunking VLANs Enabled: ALL
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL
Protected: false
Appliance trust: none
步驟3:將交換機Switch4重命名為s2並在S2上創建虛擬局域網VLAN11和VLAN22並為之分配端口
Switch>enable
Switch#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname S2
S2(config)#vlan 11
S2(config-vlan)#name T11
S2(config-vlan)#exit
S2(config)#interface fastEthernet 0/2
S2(config-if)#switchport access vlan 11
S2(config-if)#exit
S2(config)#vlan 22
S2(config-vlan)#name T22
S2(config-vlan)#exit
S2(config)#interface fastEthernet 0/3
S2(config-if)#switchport access vlan 22
S2(config-if)#exit
S2(config)#exit
S2#
%SYS-5-CONFIG_I: Configured from console by console
S2#show vlan
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/4, Fa0/5, Fa0/6, Fa0/7
Fa0/8, Fa0/9, Fa0/10, Fa0/11
Fa0/12, Fa0/13, Fa0/14, Fa0/15
Fa0/16, Fa0/17, Fa0/18, Fa0/19
Fa0/20, Fa0/21, Fa0/22, Fa0/23
Fa0/24, Gig1/1, Gig1/2
11 T11 active Fa0/2
22 T22 active Fa0/3
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1 enet 100001 1500 - - - - - 0 0
11 enet 100011 1500 - - - - - 0 0
22 enet 100022 1500 - - - - - 0 0
1002 fddi 101002 1500 - - - - - 0 0
1003 tr 101003 1500 - - - - - 0 0
1004 fdnet 101004 1500 - - - ieee - 0 0
1005 trnet 101005 1500 - - - ibm - 0 0
Remote SPAN VLANs
------------------------------------------------------------------------------
Primary Secondary Type Ports
------- --------- ----------------- ------------------------------------------
步驟4:將S2的F0/1端口設置為trunk模式
S2#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
S2(config)#interface fastEthernet 0/1
S2(config-if)#switchport mode trunk
S2(config-if)#exit
S2(config)#exit
S2#show interfaces fastEthernet 0/1 switchport
Name: Fa0/1
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: trunk
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 1 (default)
Voice VLAN: none
Administrative private-vlan host-association: none
Administrative private-vlan mapping: none
Administrative private-vlan trunk native VLAN: none
Administrative private-vlan trunk encapsulation: dot1q
Administrative private-vlan trunk normal VLANs: none
Administrative private-vlan trunk private VLANs: none
Operational private-vlan: none
Trunking VLANs Enabled: ALL
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL
Protected: false
Appliance trust: none
步驟5:驗證局域網之間的通信情況
pc0 ping pc1
pc0 ping pc3
pc2 ping pc3
pc1 ping pc2
六、實驗總結:
通過本次實驗,可以發現,不管是只有一個交換機,還是跨交換機,只有在相同的局域網上pc機之間才能通信,不在同一個局域網的pc之間不能通信。