VLANs and trunks: tagging, the native VLAN and inter-VLAN routing
Separate broadcast domains across switches with IEEE 802.1Q VLAN tags, distinguish access ports, voice VLANs, trunk ports and native VLANs, design router-on-a-stick vs Layer 3 SVIs and diagnose VLAN or native-VLAN mismatches.
Contentsand lesson path
On this page
- Why it matters
- Access ports, voice VLANs, 802.1Q trunks and the native VLAN
- Inter-VLAN routing: router-on-a-stick vs Layer 3 SVIs
- Check your understanding
- Apply it
- Review prompt
Lessons of Ethernet Switching & VLANs
- From cable to switch: media, optics, frames, MAC learning and flooding Concept · 25 min
- Lab: a Linux-bridge switch in Containerlab and its forwarding table Lab · 25 min
- VLANs and trunks: tagging, the native VLAN and inter-VLAN routing Concept · 20 min
- Lab: two VLANs, one trunk and a router-on-a-stick Lab · 30 min
- Redundancy without loops: STP/RSTP, edge-port protection and LACP Concept · 25 min
- Check: diagnose four broken layer-2 topologies Knowledge check · 10 questions
What you will learn
- Configure access and 802.1Q trunk ports and route between VLANs with a router-on-a-stick or layer-3 interfaces.
01. Why it matters
Suppose an office grows from 15 machines into three departments—Engineering, Finance, and Guest Wi-Fi—spread across four floors. Buying physically separate switches and running three separate riser cables per floor triples hardware and cabling costs while leaving half the ports idle, yet plugging everyone into one flat bridge lets guest laptops sniff Finance broadcasts and reach Finance servers directly at Layer 2.
Virtual LANs (VLANs) under IEEE 802.1Q solve both problems together: a single switch hosts multiple isolated Layer 2 broadcast domains, and a single uplink cable (trunk) multiplexes all of them between switches and routers.
02. Access ports, voice VLANs, 802.1Q trunks and the native VLAN
Why not run one dedicated patch cable per VLAN between two switches? For two VLANs in the same rack that works, but across 20 VLANs and 10 closets it burns 200 uplink ports. Instead, 802.1Q defines distinct port roles:
- Access port (untagged): Connects an endpoint (workstation, printer, server NIC) that transmits plain Ethernet frames. The port's PVID (Port VLAN ID) places every untagged ingress frame into that single VLAN (for instance, VLAN 20) and strips the tag before transmitting frames to the endpoint.
- Voice VLAN (access + tagged voice): Desk IP phones often sit inline between the wall jack and the user's PC. The switch configures one untagged data VLAN (PVID, say VLAN 10 for the PC) plus one tagged Voice VLAN (say VLAN 50), signalled via LLDP-MED or CDP: the phone tags its own VoIP frames with VLAN 50 while bridging the PC's untagged frames straight into VLAN 10.
- Trunk port (tagged): Links switches together or connects a switch to a router or hypervisor. When a frame from VLAN 20 leaves over a trunk whose native VLAN is 1, the switch inserts a 4-byte 802.1Q header right after the source MAC: 2-byte Tag Protocol Identifier (TPID
0x8100) plus 2-byte Tag Control Information containing 3 priority bits (PCP), 1 drop-eligible bit (DEI), and a 12-bit VLAN ID (1–4094;0marks priority-tagged frames without a VLAN ID and4095is reserved). The receiving switch reads20, keeps the frame isolated to VLAN 20, and strips the tag when delivering out an access port.
Native VLAN rules, mismatches, and double-tagging: Every trunk designates one VLAN (default 1 on most switches) as its native VLAN, whose frames cross untagged. Any untagged frame arriving on the trunk enters the receiving port's native VLAN. If Switch A uses native VLAN 1 while Switch B uses native VLAN 99 on the same trunk, tagged VLANs (10, 20) continue working, but untagged VLAN 1 frames from A drop straight into VLAN 99 on B—silently bridging two segments together! Worse, if user access ports also sit in default VLAN 1 while the trunk's native VLAN is 1, an attacker can craft a double-tagged frame (outer=1, inner=20): the first switch strips outer native tag 1 on trunk egress, exposing the spoofed inner tag 20 to the downstream switch. Best practice moves the trunk native VLAN to an unused parking VLAN on both ends (or tags native frames where supported), moves user ports off VLAN 1, and prunes the trunk's allowed VLAN list.
Access link: [Dst MAC 6B][Src MAC 6B][EtherType 2B][Payload ..........][FCS 4B]
802.1Q trunk:[Dst MAC 6B][Src MAC 6B][0x8100|TCI:VID=20][EtherType 2B][Pay][FCS]
|<---- 4 bytes ---->|03. Inter-VLAN routing: router-on-a-stick vs Layer 3 SVIs
Isolating VLAN 10 (192.0.2.0/24) and VLAN 20 (198.51.100.0/24) at Layer 2 means hosts cannot ARP for each other across VLANs; a Layer 3 router must forward packets between subnets. Choose between two designs:
- Router-on-a-stick (ROAS): One physical trunk links the switch to a router (
eth0). On Linux (ArchWiki VLAN and ip-link(8)), you create one VLAN subinterface per segment (ip link add link eth0 name eth0.10 type vlan id 10andeth0.20) and assign192.0.2.1/24toeth0.10and198.51.100.1/24toeth0.20. The kernel reads the incoming0x8100header oneth0and demultiplexes tagged frames to the matching subinterface (while an address placed directly on bareeth0receives only untagged native frames), automatically installing directly connected kernel routes for each subnet. When not to use ROAS: On a full-duplex 1 Gb/s trunk, switch-to-router (VLAN 10) and router-to-switch (VLAN 20) travel in opposite wire directions, so a single one-way 900 Mb/s transfer still fits. However, because every inter-VLAN packet uses both directions of that single cable, the trunk caps the combined sum of bidirectional inter-VLAN traffic at roughly 1 Gb/s per direction (alongside router CPU forwarding capacity). When VLAN 10 pushes 600 Mb/s to VLAN 20 while VLAN 20 simultaneously pushes 600 Mb/s back (1.2 Gb/sdemand in each direction), the shared trunk saturates and throttles both streams. - Layer 3 Switch Virtual Interfaces (SVIs): A Layer 3 switch terminates
vlan10andvlan20gateways inside its own switching ASIC and routes between them at wire speed without hairpinning out an external cable—the standard choice for campus cores and busy server racks.
Diagnosing a missing allowed VLAN: If VLAN 10 hosts reach external networks through a router-on-a-stick while VLAN 20 hosts cannot ping 198.51.100.1 even though eth0.20 is UP, inspect the switch trunk's allowed VLAN list: omitting VLAN 20 from the trunk drops VLAN 20 frames before they ever reach the router while leaving VLAN 10 untouched. Always confirm both ends of any trunk allow the exact same VLAN IDs.
04. Check your understanding
05. Apply it
Plan a migration from a 1 Gb/s router-on-a-stick serving VLANs 10, 20, 30, and 40 on eth0 to a Layer 3 switch using SVIs: explain where default gateways move, why concurrent bidirectional inter-VLAN transfers bottlenecked on the single ROAS trunk can run at full line rate inside the switching ASIC, and what happens if one switch-to-switch trunk omits VLAN 30 from its allowed list.
Next, configure a live vlan_filtering 1 Linux bridge, 802.1Q trunk, and router-on-a-stick in the VLAN trunking lab.
06. Review prompt
Explain how an untagged PC frame and a tagged IP-phone frame share one switch port, why matching an access VLAN with a trunk native VLAN enables double-tagging, and when Layer 3 SVIs beat router-on-a-stick.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.