Lab: two VLANs, one trunk and a router-on-a-stick
Enable vlan_filtering on a Linux bridge with access ports for VLAN 10 and VLAN 20, configure an 802.1Q trunk to a router-on-a-stick, observe 0x8100 VLAN tags in tcpdump, compare live vs offline pcap VLAN filters and diagnose a missing allowed VLAN.
Contentsand lesson path
On this page
- Goal and setup
- Step 1: Configure VLAN-aware bridge ports and router subinterfaces
- Step 2: Route between VLANs and capture 802.1Q tags on the trunk
- Step 3: Check offline pcap VLAN filtering, break the trunk and clean up
- 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. Goal and setup
By default, a Linux bridge runs with vlan_filtering 0, meaning it ignores 802.1Q tags and forwards every frame as one flat broadcast domain—helpful when a hypervisor wants transparent bridging, but useless for segmenting tenants. Enabling vlan_filtering 1 turns the kernel bridge into an IEEE 802.1Q-aware switch governed by per-port bridge vlan rules documented in bridge(8): once filtering is active, any port lacking explicit membership in a VLAN drops both tagged and untagged frames for that VLAN instead of leaking them across ports.
In this lab you build a VLAN-aware switch (br0) connecting h1 (access port in VLAN 10, 192.0.2.10/24) and h2 (access port in VLAN 20, 198.51.100.10/24) to a router namespace (r1) over a single 802.1Q trunk (br-trunk <-> r-eth0). Because h1 and h2 sit in separate broadcast domains, h1 cannot resolve h2 via ARP directly; every inter-VLAN packet must travel up the trunk tagged as VLAN 10, pass through r1's Layer 3 routing table, and return down the same trunk wire tagged as VLAN 20. You will verify 0x8100 VLAN tags on br-trunk with tcpdump -e, prove why offline -r pcap filters need vlan while live Linux socket filters match without it, and delete VLAN 20 from br-trunk to trigger an allowed-VLAN outage.
What you need on your machine: Linux (util-linux >= 2.37.2, iproute2, tcpdump, iputils ping) allowing unprivileged user namespaces; on macOS or Windows, run inside a Linux VM. All addresses come from RFC 5737 and outputs were recorded unprivileged on Ubuntu 22.04.5 (iproute2-5.15.0, tcpdump 4.99.1).
[h1: 192.0.2.10/24] --(access VLAN 10)--+
| [br0 vlan_filtering=1] ==trunk(10,20)==> [r1]
[h2: 198.51.100.10/24]-(access VLAN 20)--+ br-trunk <-> r-eth0 (.10: .2.1, .20: .100.1)02. Step 1: Configure VLAN-aware bridge ports and router subinterfaces
Enter an unprivileged namespace (unshare --map-current-user --net --keep-caps bash) and create br0 with vlan_filtering 1. Notice why the two flags on access ports (br-h1 and br-h2) do different jobs: pvid assigns the VLAN ID to untagged ingress frames arriving from the host NIC, whereas untagged instructs the bridge to strip the 802.1Q tag on egress back to the host. First delete the default VLAN 1 membership (bridge vlan del ... vid 1)—otherwise br-h1 and br-h2 remain members of VLAN 1 alongside VLAN 10 or 20—and then add vid 10 pvid untagged and vid 20 pvid untagged.
On br-trunk, add vid 10 and vid 20 without untagged so frames for both VLANs cross the trunk with a 4-byte 0x8100 header (we leave VLAN 1 as the untagged native PVID on br-trunk here so bridge vlan show makes the difference between native 1 PVID Egress Untagged and tagged 10/20 obvious). Inside r1, create two 802.1Q subinterfaces (r-eth0.10 and r-eth0.20), assign their .1/24 gateway addresses—which installs directly connected routes for 192.0.2.0/24 and 198.51.100.0/24—and enable IPv4 forwarding via sysctl -wq net.ipv4.ip_forward=1. Bare r-eth0 keeps no IP because it acts solely as the physical trunk carrier.
unshare --map-current-user --net --keep-caps bash
mkdir -p /tmp/vlan-lab04 && cd /tmp/vlan-lab04
unshare --net sleep infinity </dev/null >/dev/null 2>&1 & H1=$!
unshare --net sleep infinity </dev/null >/dev/null 2>&1 & H2=$!
unshare --net sleep infinity </dev/null >/dev/null 2>&1 & R1=$!
sleep 0.2
ip link add br0 type bridge vlan_filtering 1 && ip link set br0 up
ip link add h1-eth0 address 02:00:00:00:20:01 type veth peer name br-h1
ip link add h2-eth0 address 02:00:00:00:20:02 type veth peer name br-h2
ip link add r-eth0 address 02:00:00:00:20:fe type veth peer name br-trunk
ip link set h1-eth0 netns $H1 && ip link set h2-eth0 netns $H2
ip link set r-eth0 netns $R1
for p in br-h1 br-h2 br-trunk; do ip link set $p master br0 && ip link set $p up; done
bridge vlan del dev br-h1 vid 1 && bridge vlan del dev br-h2 vid 1
bridge vlan add dev br-h1 vid 10 pvid untagged
bridge vlan add dev br-h2 vid 20 pvid untagged
bridge vlan add dev br-trunk vid 10 && bridge vlan add dev br-trunk vid 20
nsenter -t $H1 -n sh -c "ip link set lo up && ip addr add 192.0.2.10/24 \
dev h1-eth0 && ip link set h1-eth0 up && ip route add default via 192.0.2.1"
nsenter -t $H2 -n sh -c "ip link set lo up && ip addr add 198.51.100.10/24 \
dev h2-eth0 && ip link set h2-eth0 up && ip route add default via 198.51.100.1"
nsenter -t $R1 -n sh -c "ip link set lo up && ip link set r-eth0 up && \
ip link add link r-eth0 name r-eth0.10 type vlan id 10 && \
ip link add link r-eth0 name r-eth0.20 type vlan id 20 && \
ip addr add 192.0.2.1/24 dev r-eth0.10 && ip link set r-eth0.10 up && \
ip addr add 198.51.100.1/24 dev r-eth0.20 && ip link set r-eth0.20 up && \
sysctl -wq net.ipv4.ip_forward=1"
bridge vlan showRead bridge vlan show row by row: br-h1 lists only 10 PVID Egress Untagged and br-h2 lists only 20 PVID Egress Untagged, proving VLAN 1 was cleanly removed from both access ports. Meanwhile br-trunk carries 1 PVID Egress Untagged (the native VLAN) alongside tagged 10 and 20. Because neither 10 nor 20 says Egress Untagged on br-trunk, the bridge preserves their 4-byte 0x8100 headers when sending frames to r-eth0, so r-eth0.10 and r-eth0.20 receive tagged frames and strip the tags inside r1.
port vlan-id
br0 1 PVID Egress Untagged
br-h1 10 PVID Egress Untagged
br-h2 20 PVID Egress Untagged
br-trunk 1 PVID Egress Untagged
10
2003. Step 2: Route between VLANs and capture 802.1Q tags on the trunk
Predict before running: When h1 (192.0.2.10, VLAN 10) pings h2 (198.51.100.10, VLAN 20), write down how many times each ICMP echo request crosses br-trunk, which VLAN IDs tcpdump will print on each pass, and what happens to the IPv4 TTL and Ethernet frame length (length).
tcpdump --immediate-mode -i br-trunk -e -nn -w trunk.pcap 2>/dev/null &
TT=$!
sleep 0.4
nsenter -t $H1 -n ping -c 2 -W 1 198.51.100.10
sleep 0.3 && kill -INT $TT && wait $TT 2>/dev/null || true
tcpdump -r trunk.pcap -e -nn 2>/dev/null | grep "802.1Q" | grep -v "ICMP6" | head -n 6PING 198.51.100.10 (198.51.100.10) 56(84) bytes of data.
64 bytes from 198.51.100.10: icmp_seq=1 ttl=63 time=0.118 ms
64 bytes from 198.51.100.10: icmp_seq=2 ttl=63 time=0.096 ms
...
11:09:59.937691 02:00:00:00:20:01 > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100),
length 46: vlan 10, p 0, ethertype ARP (0x0806),
Request who-has 192.0.2.1 tell 192.0.2.10, length 28
11:09:59.937716 02:00:00:00:20:fe > 02:00:00:00:20:01, ethertype 802.1Q (0x8100),
length 46: vlan 10, p 0, ethertype ARP (0x0806),
Reply 192.0.2.1 is-at 02:00:00:00:20:fe, length 28
11:09:59.937727 02:00:00:00:20:01 > 02:00:00:00:20:fe, ethertype 802.1Q (0x8100),
length 102: vlan 10, p 0, ethertype IPv4 (0x0800),
192.0.2.10 > 198.51.100.10: ICMP echo request, id 15882, seq 1, length 64
11:09:59.937738 02:00:00:00:20:fe > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100),
length 46: vlan 20, p 0, ethertype ARP (0x0806),
Request who-has 198.51.100.10 tell 198.51.100.1, length 28
11:09:59.937751 02:00:00:00:20:02 > 02:00:00:00:20:fe, ethertype 802.1Q (0x8100),
length 46: vlan 20, p 0, ethertype ARP (0x0806),
Reply 198.51.100.10 is-at 02:00:00:00:20:02, length 28
11:09:59.937755 02:00:00:00:20:fe > 02:00:00:00:20:02, ethertype 802.1Q (0x8100),
length 102: vlan 20, p 0, ethertype IPv4 (0x0800),
192.0.2.10 > 198.51.100.10: ICMP echo request, id 15882, seq 1, length 64Look closely at the frame trace in trunk.pcap: every single packet crossed br-trunk twice, wearing two different tags. First, h1 (02:00:00:00:20:01) ARPed for its default gateway 192.0.2.1 on VLAN 10 and transmitted ICMP echo request, id 15882, seq 1 toward gateway MAC 02:00:00:00:20:fe, tagged vlan 10 (length 102, 4 bytes longer than an untagged 98-byte ping). Inside r1, r-eth0.10 stripped tag 10, the kernel routed 192.0.2.10 -> 198.51.100.10 out r-eth0.20 (decrementing TTL from 64 to 63, printed as ttl=63 by ping), ARPed for 198.51.100.10 on VLAN 20, and sent the exact same ICMP request (id 15882, seq 1) back down br-trunk 28 microseconds later wearing vlan 20. Finally, br-h2 stripped tag 20 (Egress Untagged) before delivering the plain Ethernet frame to h2.
04. Step 3: Check offline pcap VLAN filtering, break the trunk and clean up
Predict before running: First compare how pcap-filter(7) evaluates trunk.pcap offline with "icmp" vs "vlan and icmp"—predict whether bare "icmp" matches the 8 saved ICMP frames inside trunk.pcap (4 packets from ping 1 and 4 from ping 2, counting both VLAN 10 and VLAN 20 passes). Next, inject a classic production outage by deleting vid 20 from br-trunk (bridge vlan del dev br-trunk vid 20) while leaving r-eth0.20 UP on the router and leaving br-h2 in VLAN 20.
Notice why this asymmetric fault confuses operators: every interface link state remains UP, bridge vlan show still lists br-h2 as 20 PVID Egress Untagged, and h1 still reaches 192.0.2.1 cleanly—yet h2 hits 100% packet loss to 198.51.100.1 because br0 has no trunk port left permitting VLAN 20 toward r1. If you captured on br-trunk during h2's failing ping, you would see zero VLAN 20 ARP requests leaving br0, proving the drop happens via VLAN egress filtering on br-trunk before packets ever reach the router. Run the checks and tear down the lab shell.
tcpdump -r trunk.pcap -e -nn "icmp" 2>/dev/null | wc -l
tcpdump -r trunk.pcap -e -nn "vlan and icmp" 2>/dev/null | wc -l
bridge vlan del dev br-trunk vid 20
nsenter -t $H1 -n ping -c 1 -W 1 192.0.2.1
nsenter -t $H2 -n ping -c 1 -W 1 198.51.100.1 || true
kill $H1 $H2 $R1 2>/dev/null || true
rm -rf /tmp/vlan-lab04 && exit0
8
PING 192.0.2.1 (192.0.2.1) 56(84) bytes of data.
64 bytes from 192.0.2.1: icmp_seq=1 ttl=64 time=0.027 ms
...
PING 198.51.100.1 (198.51.100.1) 56(84) bytes of data.
--- 198.51.100.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms05. Check your understanding
06. Apply it
Re-run Step 1 without creating r-eth0.20 while keeping vid 20 on br-trunk: predict what tcpdump -e -r trunk.pcap shows when h2 ARPs for 198.51.100.1 (tagged vlan 20 ARP Requests arriving on r-eth0 with zero replies because the router has no interface bound to VLAN 20), then verify it.
Next, move to redundancy without loops to see what happens when you add a parallel trunk between two bridges—and how STP/RSTP and LACP prevent broadcast storms.
07. Review prompt
Explain the distinct roles of pvid and untagged in bridge vlan, why ICMP echo request seq 1 appeared twice on br-trunk with length 102 and ttl=63, and why "icmp" worked live on br-trunk yet returned 0 lines on trunk.pcap.
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.