TTR Networks

Beginner · Switching basics: layer 2, VLANs and IP addressing · section 7 of 7

Build the lab yourself

✓ Lab-tested 17 October 2026 on VyOS 2026.10.16-0024-rolling, Debian 12 (Linux bridge)

The whole lab runs in a single container with no Docker networking: the switch is a Linux bridge, the PCs are network namespaces joined to it by veth pairs (virtual cables), and the VyOS VM's network card is the switch's eth4. The prompts in this lesson (root@pc1, root@sw1) show which namespace each command ran in. Put ./vyos (from the Packets That Never Come Back lesson's get-vyos.sh) next to these files and run docker compose up -d --build, then apply the switch scripts and VyOS configuration in the order the lesson shows.

lab-compose.yaml
# Needs ./vyos (from the tcpdump-and-vyos lesson's get-vyos.sh). Then: docker compose up -d --build
# Switch and PC commands:  docker compose exec lab sh        (the switch: bridge, tcpdump, ...)
#                          docker compose exec lab ip netns exec pc1 sh
# VyOS console:            docker compose exec -it lab socat -,raw,echo=0,escape=0x1d UNIX-CONNECT:/run/console.sock
name: switching-lab
services:
  lab:
    build:
      context: .
      dockerfile_inline: |
        FROM debian:bookworm-slim
        RUN apt-get update && apt-get install -y --no-install-recommends \
          qemu-system-x86 iproute2 socat procps tcpdump iputils-ping traceroute
        COPY start-switchlab.sh /usr/local/bin/start-switchlab.sh
        CMD ["/usr/local/bin/start-switchlab.sh"]
    hostname: sw1
    privileged: true
    network_mode: none
    volumes: ["./vyos:/vyos:ro"]
  • Lines 2–3: How to get a shell on the switch, or on a PC.
  • Line 18: No Docker networking at all: every cable is created inside the container.
start-switchlab.sh
#!/bin/sh
# Everything in one container, no Docker networking: three PCs as network namespaces, cabled with veth pairs
# to switch ports eth1-eth3, and the VyOS VM's NIC as switch port eth4 (a tap). The switch itself (br0) is
# configured later, so each stage of the lesson can be shown.
set -e
sysctl -qw net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1
for n in 1 2 3; do
  ip netns add "pc$n"
  ip link add "eth$n" type veth peer name eth0 netns "pc$n"
  ip -n "pc$n" link set eth0 address "02:00:00:00:00:0$n"
  ip netns exec "pc$n" sysctl -qw net.ipv6.conf.all.disable_ipv6=1
  ip -n "pc$n" link set lo up
  ip -n "pc$n" link set eth0 up
  ip link set "eth$n" up
done
ip tuntap add eth4 mode tap
ip link set eth4 up
exec qemu-system-x86_64 -m 1536 -smp 1 -cpu max -accel tcg,thread=multi \
  -uuid 00000000-0000-4000-8000-000000000001 \
  -kernel /vyos/vmlinuz -initrd /vyos/initrd.img \
  -append "boot=live components hostname=vyos username=live nopersistence noautologin nonetworking union=overlay console=ttyS0,115200 net.ifnames=0 biosdevname=0" \
  -cdrom /vyos/vyos.iso -netdev tap,id=n0,ifname=eth4,script=no,downscript=no -device virtio-net-pci,netdev=n0,mac=52:54:00:01:00:01 \
  -display none -serial unix:/run/console.sock,server=on,wait=off -monitor none
  • Line 8: Each PC is a network namespace…
  • Line 9: …cabled to switch port ethN with a veth pair.
  • Line 10: Fixed, readable MAC addresses.
  • Lines 16–17: The VyOS VM's NIC becomes switch port eth4.

Where next

  • Office gateway: DHCP, DNS and VRRP on VyOSBuilds on this lesson · Beginner · 40 min

    Two VyOS routers serving one office LAN: VRRP for a gateway that survives a router failure, DHCP with split pools and a printer reservation, and DNS forwarding. Then a real failover, the DNS outage it exposed, and the fix.

  • EVPN and VXLAN: layer 2 over a routed fabricBuilds on this lesson · Advanced · 45 min

    Stretch a layer-2 segment across a routed leaf-spine fabric: VXLAN for the data plane, BGP EVPN for the control plane. Built with FRR: the underlay, VNIs, type-2 and type-3 routes, route targets, and the VXLAN packets on the wire.

  • Building a network lab on an Apple Silicon MacAlso in Foundations · Beginner · 45 min

    Run real network labs on an M-series Mac: native FRR and Linux containers, x86-only images through Rosetta, and full x86 VyOS VMs under QEMU in Docker, with the pitfalls that stop most people and a starter lab that mixes all three.

  • Why not just keep it simple?Also in Foundations · Beginner · 25 min

    Why networks use routing protocols, BGP and redundant links instead of a few static routes, when they shouldn't, and what the extra complexity buys. With a real experiment: one quiet link failure, three designs, measured.