When every device in an office sits on the same network, guests can see staff computers and a problem on one machine can affect everyone. VLANs (Virtual LANs) fix this by splitting one physical switch into several separate networks.
Analogy: VLANs are like separate floors in one building. People on the 2nd and 5th floors share the building, but they don't walk into each other's offices. To move between floors you need the lift, which in networking is a router.
Our example plan
| VLAN | Name | Ports |
|---|---|---|
| 10 | STAFF | Fa0/1 to Fa0/12 |
| 20 | GUEST | Fa0/13 to Fa0/20 |
| Trunk | carries VLAN 10 and 20 | Gi0/1 (to a router or another switch) |
Step 1: Enter configuration mode
Switch> enable
Switch# configure terminal
Switch(config)# hostname SW1
Step 2: Create and name the VLANs
SW1(config)# vlan 10
SW1(config-vlan)# name STAFF
SW1(config-vlan)# vlan 20
SW1(config-vlan)# name GUEST
SW1(config-vlan)# exit
Step 3: Assign access ports
An access port belongs to exactly one VLAN. Use access ports for computers, printers and IP phones.
SW1(config)# interface range fa0/1 - 12
SW1(config-if-range)# switchport mode access
SW1(config-if-range)# switchport access vlan 10
SW1(config-if-range)# exit
SW1(config)# interface range fa0/13 - 20
SW1(config-if-range)# switchport mode access
SW1(config-if-range)# switchport access vlan 20
SW1(config-if-range)# exit
Step 4: Configure the trunk port
A trunk carries many VLANs over one cable. It adds a small 802.1Q tag to each frame so the device on the other end knows which VLAN the frame belongs to.
SW1(config)# interface gi0/1
SW1(config-if)# switchport mode trunk
SW1(config-if)# switchport trunk allowed vlan 10,20
SW1(config-if)# end
On some older switches you must run switchport trunk encapsulation dot1q before switchport mode trunk. If the trunk command is rejected, try that first.
Step 5: Verify
SW1# show vlan brief
SW1# show interfaces trunk
show vlan brief lists each VLAN and the ports in it. show interfaces trunk shows which ports are trunks and which VLANs they carry.
Step 6: Save the configuration
SW1# copy running-config startup-config
If you skip this, the switch forgets everything after a reboot.
Common beginner mistakes
- Expecting VLAN 10 and VLAN 20 to talk to each other. They can't without a router or a Layer 3 switch. That is called inter-VLAN routing.
- Leaving unused ports in VLAN 1. Move them to an unused VLAN and disable them with
shutdown, so nobody can plug in and join your network. - Not naming VLANs. Six months later, "VLAN 37" means nothing. Names save time.
- Forgetting to save.
Practise it
Build this in Cisco Packet Tracer with one switch and four PCs, two in each VLAN. PCs in the same VLAN should ping each other, and PCs in different VLANs should not. Then try adding a router to make the two VLANs talk.