Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 2 of 6 · Lab · 25 min · revision 1

Lab: a Linux-bridge switch in Containerlab and its forwarding table

Create a Linux kernel Ethernet bridge connecting three isolated host namespaces, inspect its Forwarding Database (FDB) with bridge fdb show, verify unicast isolation on a third port with tcpdump and trigger unknown-unicast flooding by deleting one FDB entry.

Contentsand lesson path

What you will learn

  • Explain Ethernet framing, MAC learning, flooding and forwarding, and broadcast domains, and read a switch's forwarding table.

01. Goal and setup

A hardware switch forwards frames in ASICs; the Linux kernel includes an equivalent Layer 2 Ethernet bridge (ip link add br0 type bridge) documented in Linux kernel Ethernet Bridging. This lab proves three forwarding behaviours directly on the wire: a bridge populates its Forwarding Database (FDB) dynamically per port from incoming source MACs, known unicast ICMP frames between h1 and h2 never appear on h3's port, and deleting h2's FDB entry forces a single unknown-unicast flood until h2 replies.

How this relates to Containerlab and what you need on your machine: In Containerlab kind: bridge, Containerlab does not create the bridge itself; it attaches container interfaces to a pre-existing Linux bridge (br0) created on the host with ip link add using sudo and Docker. To keep this lab runnable without root or Docker, we execute the exact underlying Linux bridge, veth virtual Ethernet pairs, and network namespaces directly inside an unprivileged user/network namespace (unshare --map-current-user --net --keep-caps bash). Your machine needs Linux (util-linux >= 2.37.2, iproute2, tcpdump, iputils ping) with unprivileged user namespaces enabled (recorded on Ubuntu 22.04.5 with iproute2-5.15.0 and tcpdump 4.99.1); on macOS or Windows, run inside a Linux VM. Every interface and namespace disappears cleanly when you exit the lab shell.

YAML · Equivalent Containerlab topology (illustrative — requires pre-created br0)
# Illustrative topology after running:
#   sudo ip link add br0 type bridge && sudo ip link set br0 up
name: bridge-fdb-lab
topology:
  nodes:
    br0:
      kind: bridge
    h1: { kind: linux, image: alpine:3.20 }
    h2: { kind: linux, image: alpine:3.20 }
    h3: { kind: linux, image: alpine:3.20 }
  links:
    - endpoints: ["br0:br-p1", "h1:eth1"]
    - endpoints: ["br0:br-p2", "h2:eth1"]
    - endpoints: ["br0:br-p3", "h3:eth1"]

02. Step 1: Enter an isolated namespace, build br0 and attach three hosts

Enter a private user + network namespace with --map-current-user --keep-caps (so your account keeps CAP_NET_ADMIN and CAP_NET_RAW inside the isolated network stack without mapping to UID 0, avoiding tcpdump privilege-drop errors). Inside that shell, create br0 as our software switch, spawn three child host namespaces (h1, h2, h3) running background sleep processes to pin them open, and wire each host through a veth pair—think of a veth pair as a virtual patch cable where every frame entering h1-eth0 exits immediately on br-p1 inside the switch namespace.

Assign deterministic locally administered MAC addresses (02:00:00:00:10:01 through :03) and RFC 5737 documentation IP addresses (192.0.2.1/24–.3/24) so every FDB and tcpdump line is easy to recognise. Notice that bringing each host interface up makes the kernel transmit automatic link-up IPv6 Neighbor Solicitation / Duplicate Address Detection (DAD) and multicast listener frames immediately, teaching br0 all three source MACs before any ping command runs.

Terminal · Start isolated lab shell, build br0 and inspect FDB
unshare --map-current-user --net --keep-caps bash
mkdir -p /tmp/vlan-lab02 && cd /tmp/vlan-lab02
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 & H3=$!
sleep 0.2

ip link add br0 type bridge && ip link set br0 up
ip link add h1-eth0 address 02:00:00:00:10:01 type veth peer name br-p1
ip link add h2-eth0 address 02:00:00:00:10:02 type veth peer name br-p2
ip link add h3-eth0 address 02:00:00:00:10:03 type veth peer name br-p3
ip link set h1-eth0 netns $H1
ip link set h2-eth0 netns $H2
ip link set h3-eth0 netns $H3
for p in br-p1 br-p2 br-p3; do ip link set $p master br0 && ip link set $p up; done

nsenter -t $H1 -n sh -c \
  "ip link set lo up && ip addr add 192.0.2.1/24 dev h1-eth0 && ip link set h1-eth0 up"
nsenter -t $H2 -n sh -c \
  "ip link set lo up && ip addr add 192.0.2.2/24 dev h2-eth0 && ip link set h2-eth0 up"
nsenter -t $H3 -n sh -c \
  "ip link set lo up && ip addr add 192.0.2.3/24 dev h3-eth0 && ip link set h3-eth0 up"
sleep 0.3
bridge fdb show br br0 | grep "02:00:00:00:10" | sort
Expected output
02:00:00:00:10:01 dev br-p1 master br0
02:00:00:00:10:02 dev br-p2 master br0
02:00:00:00:10:03 dev br-p3 master br0

Inspecting bridge fdb show br br0 without grep reveals two distinct entry classes:

  • Dynamic learned entries (shown above): Printed as <MAC> dev br-pX master br0 with no permanent flag. Every incoming frame resets that MAC's countdown to ageing_time (300 s default), and unplugging a cable into another bridge port overwrites the mapping immediately on the next ingress frame.
  • Permanent local entries: Entries tagged permanent belong to br0 and its local slave interfaces (br-p1–br-p3); they never age out and represent the bridge's own local ports rather than external hosts.

03. Step 2: Capture on h3 while h1 pings h2

Predict before running: Start tcpdump --immediate-mode on h3 (h3-eth0) and then run ping -c 2 192.0.2.2 from h1. Write down which frames h3 will capture: the initial ARP broadcast who-has 192.0.2.2, h2's unicast ARP reply, and the four unicast ICMP packets—or only a subset?

Terminal · Capture on h3 while h1 pings h2
nsenter -t $H3 -n tcpdump --immediate-mode -i h3-eth0 -e -nn -w h3.pcap 2>/dev/null &
T3=$!
sleep 0.4
nsenter -t $H1 -n ping -c 2 -W 1 192.0.2.2
sleep 0.3 && kill -INT $T3 && wait $T3 2>/dev/null || true
tcpdump -r h3.pcap -e -nn 2>/dev/null | grep -E "ARP|ICMP echo"
Expected output (illustrative: timestamps and RTTs vary; wrapped)
PING 192.0.2.2 (192.0.2.2) 56(84) bytes of data.
64 bytes from 192.0.2.2: icmp_seq=1 ttl=64 time=0.064 ms
64 bytes from 192.0.2.2: icmp_seq=2 ttl=64 time=0.048 ms
...
11:10:29.176123 02:00:00:00:10:01 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806),
  length 42: Request who-has 192.0.2.2 tell 192.0.2.1, length 28

h3 received only the broadcast ARP Request (> ff:ff:ff:ff:ff:ff), and zero unicast ARP replies or ICMP packets. Because br0 already learned 02:00:00:00:10:01 on br-p1 and 02:00:00:00:10:02 on br-p2, it kept every unicast frame strictly between br-p1 and br-p2. Notice why the filter matches "ARP|ICMP echo" instead of "ICMP": bringing up interfaces in Step 1 triggers automatic link-local IPv6 multicast (ICMP6 DAD, MLD, and router solicitations), which br0 also floods to h3 if Steps 1 and 2 run back-to-back. Remember why the ARP Request itself still appeared on h3-eth0: h1 did not yet know which MAC owned 192.0.2.2, so it addressed the ARP Request to Ethernet broadcast ff:ff:ff:ff:ff:ff, and every Layer 2 switch must flood broadcasts out of every other port in the same broadcast domain. h2's ARP Reply, by contrast, is unicast straight back to 02:00:00:00:10:01, so br0 delivered it solely out br-p1.

04. Step 3: Delete one FDB entry to trigger unknown-unicast flooding and clean up

Predict before running: Check ageing_time (30000 centiseconds = 300 seconds), start a fresh capture on h3, delete only h2's dynamic entry from br0 (bridge fdb del 02:00:00:00:10:02 dev br-p2 master) while h1 still holds 192.0.2.2 in its ARP cache, and immediately run ping -c 2 192.0.2.2 from h1. Think carefully about both tables involved—h1's Layer 3-to-MAC ARP cache and br0's Layer 2 FDB—and predict how many ICMP frames h3 will capture before br0 re-learns h2. Then run the block, compare your prediction with h3-flood.pcap, and exit the lab shell to tear down every virtual link and namespace.

Terminal · Trigger single-frame unknown-unicast flood and clean up
ip -d link show br0 | grep -o "ageing_time [0-9]*"
nsenter -t $H3 -n tcpdump --immediate-mode -i h3-eth0 -e -nn -w h3-flood.pcap \
  2>/dev/null &
T3B=$!
sleep 0.4
bridge fdb del 02:00:00:00:10:02 dev br-p2 master
nsenter -t $H1 -n ping -c 2 -W 1 192.0.2.2
sleep 0.3 && kill -INT $T3B && wait $T3B 2>/dev/null || true
tcpdump -r h3-flood.pcap -e -nn 2>/dev/null | grep -E "ARP|ICMP echo"
bridge fdb show br br0 | grep "02:00:00:00:10" | sort
kill $H1 $H2 $H3 2>/dev/null || true
rm -rf /tmp/vlan-lab02 && exit
Expected output (illustrative: timestamps, IDs and RTTs vary; wrapped)
ageing_time 30000
PING 192.0.2.2 (192.0.2.2) 56(84) bytes of data.
64 bytes from 192.0.2.2: icmp_seq=1 ttl=64 time=0.057 ms
64 bytes from 192.0.2.2: icmp_seq=2 ttl=64 time=0.046 ms
...
11:10:30.929017 02:00:00:00:10:01 > 02:00:00:00:10:02, ethertype IPv4 (0x0800),
  length 98: 192.0.2.1 > 192.0.2.2: ICMP echo request, id 57086, seq 1, length 64
02:00:00:00:10:01 dev br-p1 master br0
02:00:00:00:10:02 dev br-p2 master br0
02:00:00:00:10:03 dev br-p3 master br0

Look at h3-flood.pcap: h3 captured ICMP echo request, ... seq 1 addressed unicast from 02:00:00:00:10:01 to 02:00:00:00:10:02 (length 98), and zero other ICMP frames (seq 1 reply or seq 2 request/reply). Why did only seq 1 leak to h3? Because h1 already held h2's MAC in its ARP table, it skipped ARP and sent a unicast Ethernet frame straight to 02:00:00:00:10:02; br0 had no FDB entry for 02:00:00:00:10:02 after our bridge fdb del, so it flooded seq 1 out both br-p2 and br-p3. The instant h2 answered with its ICMP echo reply on br-p2, br0 re-learned 02:00:00:00:10:02 dev br-p2 from that ingress source MAC, so the seq 1 reply and both seq 2 frames flowed privately without touching h3. Notice also why bridge fdb del ran immediately after starting tcpdump: waiting several seconds can let the host kernel emit an unsolicited multicast/DAD frame that re-teaches br0 before your ping runs.

05. Check your understanding

Practice check · 2 questions

Reading Linux bridge FDBs and unknown-unicast flooding

Apply what you observed in `bridge fdb show` and `tcpdump`.

Q1. In Step 3, `br0` knows `h1` on `br-p1`, and `h1` already holds `h2`'s MAC in its ARP cache. Immediately after `bridge fdb del 02:00:00:00:10:02 dev br-p2 master`, `h1` runs `ping -c 2 192.0.2.2`. Which frames reach `h3`?
Q2. Running `bridge fdb show br br0` lists local MACs tagged `master br0 permanent` and host MACs simply `master br0`. You unplug `h1` from `br-p1`, plug it into `br-p3`, and `h1` sends one frame. What happens to `h1`'s dynamic entry?
Practice only: not graded, not saved, not evidence.

06. Apply it

Repeat Step 3 after also running nsenter -t $H1 -n ip neigh flush all, and observe how h3 now sees the ARP Request broadcast rather than an unknown-unicast ICMP frame (because ARP resolves before ICMP is transmitted and teaches br0 h2's MAC during the ARP Reply).

Next, move to VLANs and trunks to divide one physical switch into multiple isolated broadcast domains.

07. Review prompt

Explain why h3 saw the ARP Request in Step 2 and only seq 1 in Step 3, why bridge fdb show already showed host MACs right after bringing the ports up, and why --map-current-user --keep-caps avoids tcpdump privilege-drop failures.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check