一、vlan簡介
預設時交換機分割沖突域,路由器分割廣播域,vlan可以分割廣播域,而且vlan可以對硬體位址、協定、和應用程式實施限制,這樣可以保證安全性,vlan還具有靈活性和可擴張性
通常有管理者建立的valn并将端口放入每個vlan,這樣的vlan成為靜态vlan
将主機硬體位址放入資料庫,主機接入交換機時,交換機自動為其配置設定vlan,成為動态vlan
vlan識别:
交換機間鍊路(inter-switch link,ISL),在以太網幀上标記vlan資訊,isl外部封裝方法允許這是cisco交換機專用的方法
IEEE802.1Q,在幀中插入一個字段以标示vlan
2960系列隻支援ieee802.1Q中繼協定,3560系列能支援ISL和IEEE802.1Q
vlan中繼協定VTP,子vtp域中有三種操作模式:伺服器(預設模式,vtp域中至少要有一台伺服器,可以之心建立添加删除等操作,在vtp伺服器模式下,vlan配置儲存在NVRAM中)、客戶機(從伺服器接收資訊,轉發彙總通告不做更改)、透明
vtp修剪:用來儲存帶寬的一種方法;預設時vlan2--1001是可以啟用修剪的,擴充vlan1006--4096不能被修剪但vlan1從來不啟用修剪,vtp1和2 版本都支援vtp修剪
使用show interface trunk 指令可以看到穿越中繼鍊路的vlan
使用switchport trunk pruning vlan 3-4 為3-4vlan啟用vtp修剪
二、VLAN間的路由

執行個體示範如圖所示規劃:pc0 、pc3屬于vlan10,pc2、pc1屬于vlan20,ip位址如圖所示配置設定,route4ip為1.1.1.2/16
1、首先規劃ip位址
2、在switch0 上Switch>en
Switch#config terminal
Switch(config)#vlan 10
Switch(config)#vlan 20
建立vlan,在switch1上執行相同指令;可以用Switch#show vlan指令檢視建立的valn
3、将端口配置設定到vlan
進入switch0
Switch#config ter
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#inter fa0/2
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access valn 10
Switch(config)#inter fa0/5
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access valn 20
在switch1上執行相同指令将fastEthernet 0/2加入vlan20,将fastEthernet 0/5加入vlan10
使用interface range 可以同時設定許多端口,dynamic和trunk分别用于中繼端口
4、配置中繼端口
Switch(config)#inter fa0/3
switchport mode trunk
Switch(config)#inter fa0/4
Switch(config)#inter fa0/1
switchport mode trunk
(cisco3560交換機上有encapsulation指令,而2960則沒有
Switch(config-if)#switchport trunk encapsulation dot1q
Switch(config-if)#switchport mode trunk)
在中繼端口上定義允許的vlan
Switch(config-if)#switchport trunk allowed vlan ?
WORD VLAN IDs of the allowed VLANs when this port is in trunking mode
add add VLANs to the current list
all all VLANs
except all VLANs except the following
none no VLANs
remove remove VLANs from the current list
Switch(config-if)#switchport trunk allowed vlan all其後有其它選項remove可以防止特定vlan穿越中繼鍊路
變更或修改本機vlan
Switch(config-if)#switchport trunk native vlan 40
使用Switch(config-if)# no switchport trunk native vlan 可以将本機vlan設定回預設,交換機必須使用相同的本機vlan
配置vlan間路由,在route1的fa0/1上劃分子接口
Router>en
Router#config ter.
Router(config)#int fa0/1.1
Router(config-subif)#encapsulation dot1Q ?
<1-1005> IEEE 802.1Q VLAN ID
Router(config-subif)#encapsulation dot1Q 10
Router(config)#int fa0/1.2
Router(config-subif)#encapsulation dot1Q 20
給子接口fa0/1.1配置ip為192.168.0.13/24,fa0/1.2ip為192.168.1.23/24
并把fa0/1設定成trunk口,然後s0/0/0設定ip為1.1.1.1/16,并且需要配置時鐘頻率clock rate
5、測試如圖所示: