VLAN Hopping and How to Prevent It
Segmentation by VLAN rests on one assumption: a device on an access port can only ever reach its own VLAN. VLAN hopping is any way of sending frames into a VLAN you were not assigned. There are two classic techniques, both caused by default switch settings rather than by bugs: switch spoofing, where a computer convinces the switch port to become a trunk, and double tagging, where a frame carries two 802.1Q tags and the outer one is stripped on the way. This lesson explains both on a simulated pair of switches and a synthetic capture, then shows how each is detected and the configuration that ends it. It needs the tag format from VLANs, 802.1Q Tags and Trunks.
Switch spoofing (concept)
Some switches ship with ports in a "dynamic" mode: if the other end asks to form a trunk (with Cisco's Dynamic Trunking Protocol, DTP, or similar), the port becomes a trunk carrying all VLANs. A computer that speaks DTP can therefore turn its desk port into a trunk and then send and receive tagged frames for any VLAN.
- Detection: DTP frames (destination MAC
01:00:0c:cc:cc:cc, SNAP protocol 0x2004) arriving from user ports; a port that changes from access to trunk in the switch logs. - Fix: configure every user port as access explicitly and turn negotiation off (
switchport mode accessandswitchport nonegotiateon Cisco IOS; most other vendors' switches have no DTP-style trunk negotiation, but check). Unused ports: shut down and put in an unused VLAN.
Double tagging
The second technique works even when ports are configured as access ports, if three conditions hold: the attacker's access VLAN is the same as the trunk's native VLAN, the switch accepts a tagged frame on an access port when the tag matches the port's VLAN, and the native VLAN is sent untagged on the trunk.
The attack is one-way: the victim's replies go to VLAN 20 hosts, never back to the attacker. It still suffices for some damage, for example a single UDP packet to a vulnerable service or a spoofed syslog line, and it shows that the boundary leaks.
The two switches as a simulation
The model below follows a frame through switch A's access port and the trunk. Change the native VLAN or the access VLAN and the hop disappears.
def switch_a(frame_tags, access_vlan, native_vlan, tag_native=False):
"""Access port in access_vlan; returns the tag stack sent on the trunk, or None if dropped."""
tags = list(frame_tags)
if tags: # tagged frame on an access port
if tags[0] != access_vlan:
return None # tag for a foreign VLAN: dropped
tags.pop(0) # switch accepts and strips the matching tag
vlan = access_vlan
if vlan == native_vlan and not tag_native:
return tags # native VLAN goes untagged on the trunk
return [vlan] + tags
def switch_b(trunk_tags, native_vlan):
return trunk_tags[0] if trunk_tags else native_vlan # first tag decides; none = native
cases = [("default: access 1, native 1", 1, 1, False),
("native moved to unused 999", 1, 999, False),
("native VLAN tagged", 1, 1, True),
("attacker in VLAN 10", 10, 1, False)]
for name, access, native, tag_native in cases:
sent = [access, 20] # outer tag = own VLAN, inner = target
trunk = switch_a(sent, access, native, tag_native)
if trunk is None:
print(f"{name:<29} dropped at switch A")
continue
vlan = switch_b(trunk, native)
verdict = "HOPPED into VLAN 20" if vlan == 20 else f"stays in VLAN {vlan}"
print(f"{name:<29} trunk tags={trunk!s:<8} -> {verdict}")default: access 1, native 1 trunk tags=[20] -> HOPPED into VLAN 20
native moved to unused 999 trunk tags=[1, 20] -> stays in VLAN 1
native VLAN tagged trunk tags=[1, 20] -> stays in VLAN 1
attacker in VLAN 10 trunk tags=[10, 20] -> stays in VLAN 10
Only the default case hops. Moving the native VLAN to an unused number or tagging it means the outer tag is replaced by a real tag on the trunk, and switch B delivers the frame to the attacker's own VLAN.
How it is detected
Double-tagged frames have no business on an access port. A sensor on a SPAN of user ports, or a trunk tap, can match them with the BPF expression vlan and vlan (a tag followed by another tag). The session writes a synthetic capture with one normal tagged frame and one double-tagged frame, then filters:
python3 - <<'PY'
from scapy.all import Ether, Dot1Q, IP, UDP, Raw, wrpcap
t0 = 1768471200.0
normal = Ether(src="02:00:00:0a:0a:05", dst="02:00:00:0a:0a:0a")/Dot1Q(vlan=1)/IP(src="10.10.0.5", dst="10.10.0.10")/UDP(sport=40000, dport=514)/Raw(b"<14>ok")
hop = Ether(src="02:00:00:0a:0a:66", dst="ff:ff:ff:ff:ff:ff")/Dot1Q(vlan=1)/Dot1Q(vlan=20)/IP(src="10.10.0.102", dst="10.10.20.22")/UDP(sport=40000, dport=514)/Raw(b"<14>forged")
normal.time, hop.time = t0, t0 + 1
wrpcap("edge.pcap", [normal, hop])
PY
echo "all frames:"
tcpdump -nn -e -r edge.pcap 2>/dev/null
echo "double-tagged frames:"
tcpdump -nn -r edge.pcap 'vlan and vlan' 2>/dev/nullall frames:
10:00:00.000000 02:00:00:0a:0a:05 > 02:00:00:0a:0a:0a, ethertype 802.1Q (0x8100), length 52: vlan 1, p 0, ethertype IPv4 (0x0800), 10.10.0.5.40000 > 10.10.0.10.514: SYSLOG user.info, length: 6
10:00:01.000000 02:00:00:0a:0a:66 > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 60: vlan 1, p 0, ethertype 802.1Q (0x8100), vlan 20, p 0, ethertype IPv4 (0x0800), 10.10.0.102.40000 > 10.10.20.22.514: SYSLOG user.info, length: 10
double-tagged frames:
10:00:01.000000 IP 10.10.0.102.40000 > 10.10.20.22.514: SYSLOG user.info, length: 10
Also watch for: DTP or other trunk-negotiation frames from user ports, ports that change to trunk mode, and in switch configuration audits every port left in a dynamic mode or in VLAN 1.
How it is prevented
| Control | Stops |
|---|---|
| user ports in access mode, negotiation off | switch spoofing |
| native VLAN = an unused VLAN with no hosts (never VLAN 1), or tag the native VLAN | double tagging |
| trunk allowed list limited to the VLANs it needs | both: limits what a trunk can reach |
| unused ports shut down, in a "parking" VLAN | rogue devices |
| filtering between VLANs at layer 3 | the damage if a hop happens anyway |
Pitfalls
- Believing "we don't use VLAN 1" while the trunks still use VLAN 1 as native.
- Configuring access mode but leaving negotiation on, on platforms where both settings exist.
- Testing VLAN hopping on production switches. Use a lab switch: the test frames can disrupt spanning tree or trigger port shutdowns.
Practice
1. Why can't a double-tagging attacker complete a TCP handshake with the victim?
The victim's SYN-ACK is sent within VLAN 20 to the attacker's claimed address and is never carried back into VLAN 1. Without the reply the attacker can't learn the server's sequence number, so only one-way, connectionless traffic works.
2. In the simulation, add a case where the attacker puts tag 20 alone on its frame. What happens and why?
switch_a([20], 1, 1) drops it: a tag for a foreign VLAN on an access port is rejected. The double tag exists precisely to get past this check, because the outer tag matches the port's own VLAN.
3. A trunk to a hypervisor carries VLANs 10, 20, 30 with native VLAN 1, and VLAN 1 also has user ports. List two changes.
Set the native VLAN to an unused VLAN (e.g. 999) on both ends or tag it, and restrict the allowed list to 10, 20, 30. Move the user ports out of VLAN 1.
Test yourself
Which condition is required for double tagging to work?
- The attacker's access VLAN equals the trunk's native VLAN
- The trunk carries only one VLAN
- The victim uses IPv6
- DHCP snooping is enabled
Why is double tagging a one-way attack?
- Switches drop all replies
- Replies stay in the target VLAN and never return to the attacker's VLAN
- The second tag encrypts the frame
- It only works for broadcast
Which BPF expression matches frames with two VLAN tags?
- vlan 20
- vlan and vlan
- ether proto 0x8100
- tcp and vlan
What prevents switch spoofing?
- Setting user ports to access mode and disabling trunk negotiation
- Using longer VLAN IDs
- Enabling SYN cookies
- Static ARP entries