1. 建立 VLAN
2. 存取介面
3. 中繼模式介面
4. 通用模式介面
若要在交換器上建立 VLAN,請執行下列命令此範例使用 VLAN 10、13、14、15、16。console>enable
console#configure
console(config)#vlan database
console(config-vlan)#vlan 10,13-16
console(config-vlan)#end
console#
交換機上的接入介面為該介面指定一個 VLAN,未標識。在為訪問 10 設置的埠上接收的任何流量都會將該流量放入 VLAN 10。這對於只需要一個 VLAN 的伺服器端介面很常見。以下示例將伺服器端介面千兆位 1/1 配置為訪問 10。console#config
console(config)#interface gi1/1
console(config-if)#switchport access vlan 10
若要移除存取組態,並將其設回預設的 VLAN 1,請使用下列命令。console(config-if)#no switchport access vlan
console(config)#Interface port-channel 1
交換器上的中繼介面會傳遞一個未標記的 VLAN,而所有其他 VLAN 已標記。這對於連接至其他交換器的介面,或採用採用多個 VMware 的 VMware 伺服器來說很常見。此範例在外部介面 Gigabit 0/4 上設定中繼模式。console#config
console(config)#interface gi0/4
console(config-if)#switchport mode trunk
VLAN 1 預設為未標記的 VLAN,若要變更未標記的 VLAN,請執行下列命令。console(config-if)#switchport trunk native vlan 10
若要復原上述命令,請執行下列步驟。console(config-if)#no switchport trunk native vlan
若要復原中繼模式,請執行下列步驟。console(config-if)#no switchport mode trunk
console(config)#Interface port-channel 1
一般模式介面也會傳遞一個未標記的 VLAN 和多個額外的已標記 VLAN與常規模式的不同之處在於,您可以指定要手動添加的 VLAN,並且預設情況下不會自動添加每個 VLAN。這很適合 VLAN 修剪。此範例在外部介面 Gigabit 0/4 上設定一般模式,並允許 VLAN 1、10、13、14,但不允許 15 和 16。console#config
console(config)#interface gi0/4
console(config-if)#switchport mode general
console(config-if)#switchport general allowed vlan add 10,13-14 tagged
一般模式預設不會傳遞未標記的 VLAN。要設置未標記的 VLAN,必須添加它並設置 PVID。下面的示例將 16 設置為未標記。console(config-if)#switchport general allowed vlan add 16 untagged
console(config-if)#switchport general pvid 16
若要從連接埠移除 VLAN,請執行下列命令。console(config-if)#switchport general allowed vlan remove 10
若要移除 pvid
命令,執行以下命令。console(config-if)#no switchport general pvid
若要從介面移除一般模式,請執行下列步驟。console(config-if)#no switchport mode
console(config)#Interface port-channel 1