A VLAN splits one physical network into several logical ones: accounting, guests, cameras and IP phones share the same switches but cannot see each other. Here is how it works, what access, trunk and native VLAN mean, and how to set it up on Cisco and MikroTik without the usual mistakes.

How it works

The switch marks each frame with a VLAN number — a 4-byte 802.1Q tag. Numbers range from 1 to 4094. Frames of different VLANs travel over the same wires, but the switch never passes a frame from one VLAN to another. For networks to talk to each other you need a router or an L3 switch — which means you can put a firewall between them, and that is usually the reason for VLANs in the first place.

Access, trunk and native VLAN

Port typeWhat it carriesWhat is connected
AccessOne VLAN, untagged framesComputers, printers, cameras — devices that know nothing about VLANs
TrunkSeveral VLANs, tagged framesOther switches, the router, access points, hypervisors
Access + voiceThe data VLAN untagged and the voice VLAN taggedAn IP phone with a computer plugged into it

The native VLAN is the VLAN whose frames cross the trunk untagged. By default it is VLAN 1. It must match on both ends of a trunk, otherwise traffic of one VLAN quietly "leaks" into another.

Example on Cisco

vlan 10
 name OFFICE
vlan 20
 name GUEST
!
interface GigabitEthernet1/0/5
 switchport mode access
 switchport access vlan 10
 spanning-tree portfast
!
interface GigabitEthernet1/0/48
 switchport mode trunk
 switchport trunk allowed vlan 10,20
 switchport trunk native vlan 999
 switchport nonegotiate

Watch out for switchport trunk allowed vlan. Without the word add the command replaces the whole list: write allowed vlan 30 on a working trunk and VLANs 10 and 20 disappear, leaving half the office offline. For changes, use allowed vlan add 30 or remove 30. Safe commands to move from one list to another come from the Cisco VLAN lists page.

Dozens of user ports with a voice VLAN, PortFast and Port Security at once are set up by Cisco port configuration.

Example on MikroTik

In RouterOS, VLANs are built on a bridge with vlan-filtering turned on. Access ports get a pvid, and the /interface bridge vlan table says which VLANs a port carries tagged and which untagged.

/interface bridge port
set [find interface=ether2] pvid=10
set [find interface=ether3] pvid=20
/interface bridge vlan
add bridge=bridge vlan-ids=10 tagged=bridge,ether5 untagged=ether2
add bridge=bridge vlan-ids=20 tagged=bridge,ether5 untagged=ether3
/interface vlan
add name=vlan10 interface=bridge vlan-id=10
add name=vlan20 interface=bridge vlan-id=20
/interface bridge set bridge vlan-filtering=yes

The bridge itself must be tagged in every VLAN that has an address on the router — without it the VLAN's gateway receives no frames at all. And turn on vlan-filtering as the last step: doing it earlier can cut you off from the router. The bridge, VLAN interfaces, addresses and DHCP for each network are built by MikroTik VLANs.

VLAN security

If you need a fat trunk of several cables between switches, bundle it into an EtherChannel — the EtherChannel generator gives matching VLAN settings for both ends at once.