VLAN
VLANs split one physical switch into several separate broadcast domains. Access ports belong to one VLAN and carry untagged frames to end devices. Trunk ports carry several VLANs between switches and mark each frame with an 802.1Q tag. PC A reaches PC C, but traffic between VLANs (PC A to PC B) always goes through a router or layer 3 switch.
flowchart LR a["PC A<br/>VLAN 10"] --- sw1[SW1] b["PC B<br/>VLAN 20"] --- sw1 sw1 <==>|"trunk: tagged 10, 20"| sw2[SW2] sw2 --- c["PC C<br/>VLAN 10"] sw2 --- d["PC D<br/>VLAN 20"]
Configuration
Section titled “Configuration”Switch# configure terminalSwitch(config)# vlan 10Switch(config-vlan)# name clientsSwitch(config-vlan)# vlan 20Switch(config-vlan)# name serversSwitch(config-vlan)# endSwitch(config)# interface GigabitEthernet0/5Switch(config-if)# switchport mode accessSwitch(config-if)# switchport access vlan 10Switch(config)# interface GigabitEthernet0/24Switch(config-if)# switchport trunk encapsulation dot1qSwitch(config-if)# switchport mode trunkSwitch(config-if)# switchport trunk allowed vlan 10,20Switch(config-if)# switchport trunk native vlan 999The encapsulation line is only needed (and only accepted) on switches that also support the old ISL protocol. Save
everything with write memory.
Verification
Section titled “Verification”| Command | Shows |
|---|---|
show vlan brief |
All VLANs and their access ports (trunk ports are not listed). |
show interfaces trunk |
Trunk ports, native VLAN and the allowed and active VLANs. |
show interfaces <if> switchport |
Mode, access VLAN and trunk settings of one port. |
show mac address-table vlan <id> |
Which MAC addresses the switch learned in a VLAN. |