L2 · switching · reviewed
VLANs
Virtual LANs and 802.1Q tagging
Splits one physical switched network into several independent broadcast domains, and carries them over a shared link with a four-octet tag.
Presenter modeEmbed this figure
Why it exists
A switch floods a frame it has no entry for out of every port. On one flat network that means every broadcast reaches every device, every device’s ARP traffic is everyone’s problem, and anything plugged into any port can talk to anything else. Growing such a network makes all three worse at once.
Buying a second switch for each group solves it and does not scale. VLANs solve it by making the broadcast domain a number the switch keeps against each port, so one physical network behaves as many independent ones. IEEE 802.1Q-2022 §6.9
The separation is real for flooding and for forwarding, and it is not a security boundary on its own. A misconfigured trunk, a negotiated port, or a native VLAN mismatch joins two VLANs without touching a cable.
One cable, two broadcast domains
Two VLANs share a single link between switches. The tag is added on the way out and stripped on the way in, so the hosts never see it.
Four hosts, one pair of switches, and two VLANs. PC-A and PC-C are in VLAN 10; PC-B and PC-D are in VLAN 20. Nothing physically separates them — the separation is a number the switch keeps against each port. PC-A · VLAN 10. PC-B · VLAN 20. SW1: VLANs 10, 20. SW2: VLANs 10, 20. PC-C · VLAN 10. PC-D · VLAN 20.
- Link
- Blocking
- Packet in flight
- Discarded
- Emphasis
Text equivalent of this diagram
| Element | Kind | State |
|---|---|---|
| PC-A · VLAN 10 | host | — |
| PC-B · VLAN 20 | host | — |
| SW1 | switch | VLANs: 10, 20 |
| SW2 | switch | VLANs: 10, 20 |
| PC-C · VLAN 10 | host | — |
| PC-D · VLAN 20 | host | — |
| PC-A · VLAN 10 — SW1 | link | up · access 10 |
| PC-B · VLAN 20 — SW1 | link | up · access 20 |
| SW1 — SW2 | link | up · trunk · 10,20 |
| SW2 — PC-C · VLAN 10 | link | up · access 10 |
| SW2 — PC-D · VLAN 20 | link | up · access 20 |
Four hosts, one pair of switches, and two VLANs. PC-A and PC-C are in VLAN 10; PC-B and PC-D are in VLAN 20. Nothing physically separates them — the separation is a number the switch keeps against each port.
What changed
- SW1: VLANs → 10, 20
- SW2: VLANs → 10, 20
How it works
An access port belongs to one VLAN. Frames arrive untagged, the port assigns the VLAN on ingress, and the frame is flooded or forwarded only among ports in that VLAN. The host is never aware of any of it. IEEE 802.1Q-2022 §6.9
A trunk carries several VLANs over one link, so each frame has to identify itself. The switch inserts four octets after the source address: two for the identifier 0x8100 and two carrying a three-bit priority, a drop-eligible bit and a twelve-bit VLAN identifier. IEEE 802.1Q-2022 §9.6
Twelve bits gives 4096 values, of which 0 and 4095 are reserved — 4094 usable VLANs. That ceiling is why data centres moved to VXLAN, which carries a 24-bit identifier and around sixteen million. IEEE 802.1Q-2022 §9.6
One VLAN per trunk is the exception: the native VLAN travels untagged. It exists so a trunk can interoperate with a device that does not understand tags at all, and it is the source of most of the trouble in this protocol. IEEE 802.1Q-2022 §9.5
Try it
Build a tag
Set the VLAN, priority and drop-eligible bit, and read the four octets they produce.
81 00 a0 14
| Field | Bits | Value |
|---|---|---|
| Tag Protocol Identifier | 0–15 | Customer VLAN tag (C-TAG) (0x8100) |
| Priority Code Point | 16–18 | 5 |
| Drop Eligible Indicator | 19–19 | 0b0 |
| VLAN Identifier | 20–31 | 20 |
On the wire
Constructed examples, encoded from the field table below them — not captured traffic.
- Ethernet frame
- The tag sits after the source address. Everything after it — EtherType and payload — is unchanged. IEEE 802.1Q-2022
Configure it
vlan 10 name users vlan 20 name voice vlan 999 name native-unusedCreates the VLANs in the database. Assigning a port to a VLAN that does not exist leaves the port down on some platforms and silently creates it on others.
Common mistake: Configuring `switchport access vlan 10` and assuming VLAN 10 now exists everywhere. It exists on that switch only, and it still has to be allowed on the trunk.
interface GigabitEthernet1/0/1 switchport mode access switchport access vlan 10 switchport nonegotiate spanning-tree portfast spanning-tree bpduguard enableAn access port, pinned. `nonegotiate` stops the port being talked into becoming a trunk, and BPDU Guard shuts it down if a switch appears.
Common mistake: Leaving the mode dynamic. A device that speaks DTP can negotiate a trunk and reach every VLAN on the switch.
interface GigabitEthernet1/0/24 switchport mode trunk switchport trunk allowed vlan 10,20 switchport trunk native vlan 999A trunk carrying exactly two VLANs, with the native VLAN moved to an unused one so no access port shares it.
Common mistake: Using `switchport trunk allowed vlan 30` to add a VLAN. Without `add` it replaces the whole list, and everything else on the trunk stops working.
IEEE 802.1Q-2022 §9.5
vlan dot1q tag nativeGlobal. Makes the native VLAN tagged as well, so nothing crosses a trunk untagged and double tagging has nothing to work with.
IEEE 802.1Q-2022 §9.5
Verify
show interfaces trunk- Mode, native VLAN and the allowed list per trunk.
show interfaces gigabitEthernet1/0/1 switchport- Administrative and operational mode — check the operational one.
show vlan brief- The VLAN database and which ports are in each.
Caveats
- The operational mode is what matters. A port administratively `dynamic auto` can be operationally a trunk.
- `vlan dot1q tag native` is global and affects every trunk on the switch.
When it breaks
Symptom first, because that is what you have when it happens.
Two VLANs behave as one across a particular trunk. Broadcasts cross, and hosts see neighbours they should not.
Narrow it down
- Run `show interfaces trunk` on both ends and compare the native VLAN column.
- Check CDP or LLDP for a native VLAN mismatch notification.
- Confirm which VLAN untagged frames land in at each end.
Cause
The two ends disagree about the native VLAN. Each classifies untagged frames to its own, so traffic leaks between the two.
Fix
Match the native VLAN at both ends, and tag it so nothing crosses the trunk untagged.
IEEE 802.1Q-2022 §9.5A VLAN works on both switches but not between them. Hosts in it can reach local peers and nothing beyond.
Narrow it down
- Confirm the VLAN exists in the database on both switches, not just on the ports.
- Read the allowed list on the trunk with `show interfaces trunk`.
- Check whether the VLAN is pruned, either manually or by VTP.
Cause
The VLAN is absent from the trunk’s allowed list, or was never created in the VLAN database on one switch.
Fix
Add it to the allowed list and create it in the database. Configuring a port with a VLAN does not always create the VLAN.
Large transfers fail while pings and small requests succeed. Often blamed on the application.
Narrow it down
- Ping with a large payload and the do-not-fragment bit set, and find the size where it stops.
- Compare the interface MTU on every device in the path, including the trunk.
- Check whether the failing path crosses a tagged link.
Cause
The tag adds four octets. A device configured for exactly 1500 drops a full-size tagged frame while everything smaller passes.
Fix
Raise the MTU on tagged links to at least 1504, or lower the host MTU. Most switches accept baby-giant frames by default; routers and firewalls often do not.
A device connected to an access port sees no traffic, or the switch logs frames it cannot classify.
Narrow it down
- Check whether the attached device is tagging its own traffic — a hypervisor, an IP phone, or a NIC with a VLAN sub-interface.
- Read the port mode and compare it to what the device expects.
Cause
A tagged frame arrived on a port configured as access. Behaviour is platform-specific: some switches drop it, some classify it to the access VLAN and forward it anyway.
Fix
Make the port a trunk with a restricted allowed list, or stop the device tagging. A hypervisor uplink is nearly always a trunk.
A port that should be an access port has become a trunk, and a device has access to VLANs it should not.
Narrow it down
- Read the operational mode, not the administrative one, in `show interfaces switchport`.
- Check whether negotiation is enabled on the port.
Cause
The port was left at the default dynamic mode and the attached device negotiated a trunk.
Fix
Set the mode explicitly and disable negotiation with `switchport nonegotiate`. Do this on every edge port as policy, not per incident.
A phone works and the PC behind it does not, or the PC lands in the voice VLAN.
Narrow it down
- Check which VLAN the port assigns to untagged traffic and which to tagged.
- Confirm the phone is tagging voice and passing PC traffic untagged.
- Verify the phone learned the voice VLAN, usually over CDP or LLDP-MED.
Cause
A voice VLAN port is a trunk with a restricted personality: untagged goes to the data VLAN, tagged with the voice identifier goes to voice. If the phone does not learn the voice VLAN it tags nothing, or tags the wrong thing.
Fix
Confirm the discovery protocol is running and the phone is receiving the voice VLAN, then re-check what each device is tagging.
Design notes
Do not use VLAN 1 for anything. It is the default everywhere, so an unconfigured port, a forgotten trunk, or a switch straight out of a box all land in it. Move management, the native VLAN and every user VLAN off it, and leave it empty.
Prune trunks explicitly. A trunk that allows every VLAN carries every broadcast, and a VLAN that reaches a switch with no ports in it is pure overhead and extra attack surface.
A tagged frame is 1522 octets at full size, not 1518. Equipment that has not had its MTU raised drops the largest frames while everything smaller works — which presents as an application-specific fault rather than a network one.
VLANs and subnets are a convention, not a rule. Nothing stops two subnets sharing a VLAN or one subnet spanning two, and both make troubleshooting substantially harder for no benefit.
Misconceptions
- “Putting a device in its own VLAN isolates it.”
- It isolates the broadcast domain. Anything routing between VLANs — and something usually is — will happily forward between them unless an access control list says otherwise. VLANs separate; firewalls enforce.
- “The VLAN tag wraps the frame, like an outer header.”
- It is inserted into the frame, after the source address and before the EtherType. That is why a tagged frame is exactly four octets longer and why the FCS has to be recomputed. IEEE 802.1Q-2022 §9.5
- “VID 0 means VLAN 0.”
- It means priority-tagged: the frame carries a class of service and no VLAN, and the receiving port assigns one. IP phones use it, which is why it turns up in captures more often than people expect. IEEE 802.1Q-2022 §9.6
- “An access port strips the tag.”
- There is usually nothing to strip. Traffic between hosts on the same switch in the same VLAN may never be tagged at all — tagging happens on egress to a trunk. The VLAN lives in the switch’s internal state, not necessarily on the wire.
- “More VLANs is more secure.”
- More VLANs is more routing, more access control lists, and more places for a rule to be missing. A VLAN nobody wrote a policy for is a broadcast domain with extra steps.
More walkthroughs
A native VLAN mismatch merges two networksfailure
Each end of a trunk sends its native VLAN untagged. When the two ends disagree, traffic silently crosses between VLANs and nothing logs an error.
A trunk between two switches. SW1 leaves the native VLAN at the default of 1; someone set SW2’s to 99, sensibly, to keep untagged traffic off VLAN 1. SW1 · native 1: Native VLAN 1. SW2 · native 99: Native VLAN 99. VLAN 1 host. VLAN 99 host.
- Link
- Blocking
- Packet in flight
- Discarded
- Emphasis
Text equivalent of this diagram
| Element | Kind | State |
|---|---|---|
| SW1 · native 1 | switch | Native VLAN: 1 |
| SW2 · native 99 | switch | Native VLAN: 99 |
| VLAN 1 host | host | — |
| VLAN 99 host | host | — |
| SW1 · native 1 — SW2 · native 99 | link | up · trunk |
| SW1 · native 1 — VLAN 1 host | link | up · access 1 |
| SW2 · native 99 — VLAN 99 host | link | up · access 99 |
A trunk between two switches. SW1 leaves the native VLAN at the default of 1; someone set SW2’s to 99, sensibly, to keep untagged traffic off VLAN 1.
What changed
- SW1 · native 1: Native VLAN → 1
- SW2 · native 99: Native VLAN → 99
Double tagging, and why the native VLAN should be taggeddesign-choice
An attacker on the native VLAN sends a frame with two tags. The first trunk strips one and forwards the rest into a VLAN the attacker was never in.
The attacker sits on an access port in VLAN 1, which is also the trunk’s native VLAN. That coincidence is the entire vulnerability. Attacker · VLAN 1. SW1 · native 1: Native VLAN 1. SW2. Target · VLAN 20.
- Link
- Blocking
- Packet in flight
- Discarded
- Emphasis
Text equivalent of this diagram
| Element | Kind | State |
|---|---|---|
| Attacker · VLAN 1 | host | — |
| SW1 · native 1 | switch | Native VLAN: 1 |
| SW2 | switch | — |
| Target · VLAN 20 | host | — |
| Attacker · VLAN 1 — SW1 · native 1 | link | up · access 1 |
| SW1 · native 1 — SW2 | link | up · trunk · native 1 |
| SW2 — Target · VLAN 20 | link | up · access 20 |
The attacker sits on an access port in VLAN 1, which is also the trunk’s native VLAN. That coincidence is the entire vulnerability.
What changed
- Emphasis: On the native VLAN
- SW1 · native 1: Native VLAN → 1
Terms
- VLAN
- A broadcast domain defined by configuration rather than cabling. A switch keeps a VLAN identifier against each port and scopes flooding and forwarding to it.
- Access port
- A port belonging to one VLAN. Frames arrive untagged and are classified on ingress; frames leave with no tag.
- Trunk port
- A port carrying several VLANs over one link. Each frame is tagged so the far end knows which VLAN it belongs to — except the native VLAN.
- Native VLAN
- The one VLAN a trunk carries untagged. It exists for interoperability with devices that do not understand tags, and it is where most VLAN misconfiguration lives.
- Broadcast domain
- The set of ports a broadcast frame reaches. One per VLAN, which is what VLANs are for.