VLANs
Trunk
One link that carries several VLANs, each frame tagged with its VLAN, usually between switches.
The problem
Sales spans two switches, and the one cable between them must carry sales, engineering and voice without mixing them.
- floorSwitch's port to coreSwitch carries VLANs
10,20and30, each frame tagged: a trunk. Those are its allowed VLANs. - One VLAN, the native VLAN, crosses untagged: here VLAN
1, the default VLAN every port starts in, where the printer (10.0.1.11) sits. - An untagged frame arriving on the trunk is filed in the native VLAN, so both ends must name the same one.
- Remove VLAN 20 from the trunk and carol can no longer reach the build server, while bob still reaches alice: the cable stays up.
What you'd see
$ bridge vlan show dev coreSwitch
port vlan-id
coreSwitch 1 PVID Egress Untagged
10
20
30
- Run on floorSwitch: its port named
coreSwitch, the trunk. 1 PVID Egress Untagged: VLAN 1 is native. Untagged frames coming in join it (PVID, port VLAN ID), and its frames leave without a tag.10,20,30with no flags: carried tagged. A VLAN missing here is cut in two at this cable.
Guess first
The printer pings coreSwitch (10.0.1.2) across the trunk. Is its frame tagged on the cable?
Show answer
No. VLAN 1 is the native VLAN, so it crosses as a plain ethertype IPv4 (0x0800) frame, with no vlan in it.
In short
A trunk carries its allowed VLANs tagged, and one, the native VLAN (1 unless set), untagged: an untagged
frame arriving on a trunk is filed in it, so both ends must agree. VLAN 1 is the default VLAN every port starts
in. A VLAN missing from the allowed list at either end of a trunk is cut in two there. On IOS: switchport mode trunk, switchport trunk allowed vlan, switchport trunk native vlan, show interfaces trunk.
How a VLAN trunk works, step by step
A trunk is one link that carries several VLANs, each frame tagged with an IEEE 802.1Q header
naming its VLAN. It is how VLANs cross from switch to switch, so a department can sit on any floor. In the
VLAN trunks lab showroomSwitch and garageSwitch are joined by one trunk carrying VLANs 1,
30 (office, 10.0.30.0/24) and 40 (workshop, 10.0.40.0/24).
- A PC sends an untagged frame into its access port. The switch files it in that port's VLAN, say 30 for
advisorDesk. - The frame reaches the trunk and leaves tagged. The switch inserts the 4-byte 802.1Q tag (
0x8100, then a 3-bit priority, 1 drop-eligible bit and the 12-bit VLAN ID) so the far switch knows which VLAN it belongs to. - The far switch reads the tag and forwards only within VLAN 30, then strips the tag at
financeDesk's access port, so the receiving PC never sees it. - The allowed VLANs decide what crosses. A trunk carries only the VLANs on its allowed list; a frame for any other VLAN is dropped at the port. A VLAN missing from the list at either end is cut in two there.
- One VLAN crosses untagged: the native VLAN, 1 unless set. An untagged frame arriving on a trunk is filed in the native VLAN, so both ends must agree, or frames leak between VLANs.
The default VLAN every port starts in is VLAN 1, and it cannot be deleted. Routing between the VLANs still needs a router or a layer 3 switch with an address in each.
What it looks like on a Linux machine
The switches are Linux bridges with VLAN filtering, so bridge vlan show is their show interfaces trunk. An
access port carries one VLAN, untagged both ways:
$ bridge vlan show dev advisorDesk
port vlan-id
advisorDesk 30 PVID Egress Untagged
PVID means untagged frames coming in join VLAN 30; Egress Untagged means VLAN 30 leaves without a tag. A trunk
port is different: several VLANs tagged (no flags), and the native VLAN untagged:
$ bridge vlan show dev garageSwitch
port vlan-id
garageSwitch 1 PVID Egress Untagged
30
40
On the cable, a capture shows the tag. tcpdump -e prints the link layer:
$ tcpdump -e -nn -i garageSwitch
... 802.1Q (0x8100), length 102: vlan 30, p 0, ethertype IPv4 (0x0800), 10.0.30.10 > 10.0.30.20: ICMP echo request
Length 102 is a 98-byte ping frame plus the 4-byte tag. Removing a VLAN from the trunk is one command:
$ bridge vlan del dev garageSwitch vid 40
and VLAN 40 is cut at that port while VLAN 30 keeps crossing the same cable.
What goes wrong, and how you see it
A VLAN missing from the trunk's allowed list. Devices in that VLAN on different switches cannot reach each
other, while every other VLAN works over the same cable. bridge vlan show on the trunk port is missing the VLAN;
add it back with bridge vlan add dev <port> vid 40.
Native VLAN mismatch. Each end sends untagged frames for a different VLAN, so traffic leaks from one into the other. A plain Linux bridge gives no warning (managed switches log a native VLAN mismatch); the fix is a native VLAN that both ends agree on and no host uses.
The allowed list clobbered. Editing one VLAN out of a trunk by hand can take the rest with it, when the
command sets the whole allowed list instead of adding or removing one VLAN. On a Linux bridge each bridge vlan del
or add names one VLAN, so it changes only that one; check bridge vlan show on both ends after any change.
VLAN hopping by double tagging. An attacker on the native VLAN sends a frame with two tags; the first switch strips the native outer tag and the inner tag carries it into another VLAN, one way. Keeping hosts off the native VLAN stops it. The VLAN trunks lab moves the native VLAN to an empty one at both ends.
Questions people ask
Trunk port vs access port? An access port belongs to one VLAN and carries untagged frames for an end device; a trunk carries many VLANs, tagged, between switches, routers and hypervisors.
What is the native VLAN? The one VLAN a trunk carries untagged. An untagged frame on the trunk is filed in it. Best practice is to set it to an unused VLAN so nothing rides it by accident.
Is VLAN 1 special? It is the default VLAN every port starts in and cannot be deleted. Leaving users or the native VLAN on VLAN 1 is discouraged; give management its own VLAN. See VLAN and the VLANs lab.
Read next
- VLAN Several separate networks on one switch, kept apart by a tag in each frame.
- Voice VLAN A second VLAN on a desk port, tagged, for the IP phone in front of the computer.
- Switch Joins devices into one network, forwarding each frame toward the port its destination MAC was seen on.
- VLAN hopping Escaping the VLAN your port is assigned to and reaching another one — classically by wrapping a frame in two 802.1Q tags so the first switch strips the outer and forwards the inner into a VLAN you were never meant to touch.