Skip to content
Linux networking · Chapter 2 of 20 Day 0: The training ground

Day 0: The training ground

Goal: Turn an empty Ubuntu VM into the ground on which a whole company network made of namespaces grows over the next days: tools, FRR, keepalived, kernel modules · Duration: approx. 60 min · Prerequisite: a VM with Ubuntu 24.04, SSH access and sudo

Briefing

  • You rarely learn networking on a live system: one wrong command on the router, and the session is gone. That’s why in this course you build your own network to break, on a single VM.
  • The trick is called network namespace. Each namespace has its own interfaces, its own addresses, its own routes and its own firewall rules. To the kernel it’s a separate machine, but it costs only a few kilobytes instead of a whole VM.
  • By Day 16, this grows into two sites with routers, clients and servers: first by hand with ip, then routed with FRR, then highly available with keepalived. Today you only build the ground.
                 Home network 172.16.0.0/24
 ────────────────────────┬──────────────────────
                     netz .123 (eth0)
             ┌───────────┴───────────────────┐
             │  from Day 2: namespaces       │
             │  r1  r2  r3   c1  c2   srv    │
             │  connected via veth, bridges  │
             └───────────────────────────────┘
Tool Version Source
iproute2 (ip, ss, bridge) 6.1.0 Ubuntu
tcpdump 4.99.4 Ubuntu
tshark 4.2.2 Ubuntu
iperf3 3.16 Ubuntu
mtr 0.95 Ubuntu
conntrack 1.4.8 Ubuntu
FRR 10.7.1 deb.frrouting.org
keepalived 2.2.8 Ubuntu

Drill 1: The starting point

The course was tested on a VM under Proxmox: 2 vCPU, 3.8 GiB RAM, 58 GB disk. First, look at what’s there:

# on netz
lsb_release -ds
nproc
free -h | head -2
dpkg --print-architecture
uname -r
sudo ufw status

Expected:

Ubuntu 24.04.5 LTS
2
               total        used        free      shared  buff/cache   available
Mem:           3.8Gi       449Mi       3.2Gi       1.0Mi       409Mi       3.4Gi
amd64
6.8.0-149-generic
Status: inactive

Then the network from the VM’s point of view: interfaces, routes, DNS.

# on netz
ip -br a
ip r
resolvectl dns eth0

Expected:

lo               UNKNOWN        127.0.0.1/8 ::1/128
eth0             UP             172.16.0.123/24 metric 100 fd0e:fdec:438a:328:be24:11ff:fe4d:d908/64 fe80::be24:11ff:fe4d:d908/64
default via 172.16.0.1 dev eth0 proto dhcp src 172.16.0.123 metric 100
1.1.1.1 via 172.16.0.1 dev eth0 proto dhcp src 172.16.0.123 metric 100
8.8.8.8 via 172.16.0.1 dev eth0 proto dhcp src 172.16.0.123 metric 100
172.16.0.0/24 dev eth0 proto kernel scope link src 172.16.0.123 metric 100
172.16.0.1 dev eth0 proto dhcp scope link src 172.16.0.123 metric 100
172.16.0.15 dev eth0 proto dhcp scope link src 172.16.0.123 metric 100
Link 2 (eth0): 172.16.0.15 8.8.8.8 1.1.1.1

Your addresses will differ. Read every line anyway:

Line Meaning
-br brief: one line per interface instead of a page
proto dhcp The route came from the DHCP server, not from you
proto kernel scope link Your own network: the kernel adds it as soon as the address is set
/32 routes to 1.1.1.1, 8.8.8.8 The DHCP server sends the DNS servers along, systemd-networkd creates routes for them
metric 100 Cost of the route. With two equal destinations, the smaller number wins

If you have ufw active, it won’t interfere with the exercises: everything from Day 2 on runs between namespaces, not over eth0.

Save your progress? Sign up for free

Drill 2: A name that stays

The VM is called netz. If it was cloned from a template, /etc/hosts often still contains the old name:

# on netz
hostname
grep 127.0.1.1 /etc/hosts

Expected (in the lab):

netz
127.0.1.1 kvm2 kvm2

Fix the entry:

# on netz
sudo sed -i 's/^127.0.1.1.*/127.0.1.1 netz/' /etc/hosts
grep 127.0.1.1 /etc/hosts

Expected:

127.0.1.1 netz

Tried it: After a reboot, the file said 127.0.1.1 kvm2 kvm2 again. The header of /etc/hosts reveals why: manage_etc_hosts is on, and cloud-init rewrites the file at every boot from its template, with the name from the VM’s user data. A file /etc/cloud/cloud.cfg.d/99-netz.cfg with manage_etc_hosts: false didn’t help: the user data takes precedence over the system configuration and wins.

A lab VM no longer needs cloud-init after the first boot. The network configuration is already in /etc/netplan/50-cloud-init.yaml and stays. So turn it off:

# on netz
sudo touch /etc/cloud/cloud-init.disabled
sudo sed -i 's/^127.0.1.1.*/127.0.1.1 netz/' /etc/hosts
sudo reboot

Log in again after the reboot:

# on netz
hostname
getent hosts netz
cloud-init status
ip r show default

Expected:

netz
127.0.1.1       netz
status: disabled
default via 172.16.0.1 dev eth0 proto dhcp src 172.16.0.123 metric 100

The default route is still there: DHCP is handled by systemd-networkd, not cloud-init.

Save your progress? Sign up for free

Drill 3: The toolbox

Everything Part A needs comes from Ubuntu. Only tshark asks a question during installation (may normal users capture?). Set the answer beforehand, and the installation stays quiet:

# on netz
echo "wireshark-common wireshark-common/install-setuid boolean false" | sudo debconf-set-selections
sudo apt-get update -qq
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y \
  iproute2 tcpdump tshark iperf3 mtr-tiny conntrack ethtool dnsutils arping >/dev/null
ip -V
tcpdump --version | head -1
tshark --version | head -1
iperf3 --version | head -1
mtr --version
conntrack --version
ethtool --version
dig -v

Expected:

ip utility, iproute2-6.1.0, libbpf 1.3.0
tcpdump version 4.99.4
TShark (Wireshark) 4.2.2 (Git v4.2.2 packaged as 4.2.2-1.1build3).
iperf 3.16 (cJSON 1.7.15)
mtr 0.95
conntrack v1.4.8 (conntrack-tools)
ethtool version 6.7
DiG 9.18.39-0ubuntu0.24.04.9-Ubuntu

false for the tshark question means: capturing only with sudo. For a lab VM with one user that’s enough, and no file with special privileges is left behind.

iperf3 could also run as a service. The package asks about it and leaves it out with noninteractive:

# on netz
systemctl is-enabled iperf3

Expected:

disabled

Good: from Day 9 on, you start the iperf3 server deliberately in the namespace you want to measure.

Save your progress? Sign up for free

Drill 4: FRR 10.7

FRR (FRRouting) turns Linux into a router with OSPF, BGP, BFD and more. Ubuntu 24.04 ships version 8.4.4; the FRR project has its own package archive with current versions. The channel frr-10.7 keeps you on this major version; frr-stable would jump along with the next release.

# on netz
curl -fsSL https://deb.frrouting.org/frr/keys.gpg | sudo tee /usr/share/keyrings/frrouting.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/frrouting.gpg] https://deb.frrouting.org/frr noble frr-10.7" \
  | sudo tee /etc/apt/sources.list.d/frr.list
sudo apt-get update -qq
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y frr frr-pythontools >/dev/null
apt-cache policy frr | head -8

Expected:

deb [signed-by=/usr/share/keyrings/frrouting.gpg] https://deb.frrouting.org/frr noble frr-10.7
frr:
  Installed: 10.7.1-0~ubuntu24.04.1
  Candidate: 10.7.1-0~ubuntu24.04.1
  Version table:
 *** 10.7.1-0~ubuntu24.04.1 500
        500 https://deb.frrouting.org/frr noble/frr-10.7 amd64 Packages
        100 /var/lib/dpkg/status
     8.4.4-1.1ubuntu6.8 500

The asterisks mark the installed version; below it waits Ubuntu’s. Both have priority 500, and apt takes the higher version.

Now into FRR’s command line:

# on netz
vtysh -c "show version"

Expected:

% Can't open configuration file /etc/frr/vtysh.conf due to 'Permission denied'.
Configuration file[/etc/frr/frr.conf] processing failure: 11
Exiting: failed to connect to any daemons.
Hint: if this seems wrong, try running me as a privileged user!

Tried it: vtysh without sudo may neither read the configuration nor talk to the daemons. The hint in the last line is right: throughout the course, vtysh is preceded by sudo.

# on netz
sudo vtysh -c "show version" | head -1
sudo grep -E "^(bgpd|ospfd|bfdd|vrrpd)=" /etc/frr/daemons

Expected:

FRRouting 10.7.1 (netz) on Linux(6.8.0-149-generic).
bgpd=no
ospfd=no
bfdd=no
vrrpd=no

In /etc/frr/daemons you enable each protocol individually. From Day 10 on, FRR doesn’t run on the VM itself but in the router namespaces, one instance per router. The service for the VM therefore stays off:

# on netz
sudo systemctl disable --now frr
systemctl is-active frr
systemctl is-enabled frr

Expected (end):

Removed "/etc/systemd/system/multi-user.target.wants/frr.service".
inactive
disabled

Save your progress? Sign up for free

Drill 5: keepalived

keepalived brings VRRP: two routers share a virtual IP; if one fails, the other takes over. Ubuntu’s version 2.2.8 is enough for everything in Part C.

# on netz
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y keepalived >/dev/null
keepalived --version 2>&1 | head -1
systemctl is-enabled keepalived
systemctl is-active keepalived
ls /etc/keepalived/

Expected:

Keepalived v2.2.8 (04/04,2023), git commit v2.2.7-154-g292b299e+
enabled
inactive
keepalived.conf.sample

Enabled, but not started: the systemd unit only starts if /etc/keepalived/keepalived.conf exists. So far there’s only a sample. So that nothing starts unexpectedly after a reboot once there is a configuration, turn it off here too:

# on netz
sudo systemctl disable --now keepalived
systemctl is-enabled keepalived

Expected (end):

Removed "/etc/systemd/system/multi-user.target.wants/keepalived.service".
disabled

Save your progress? Sign up for free

Drill 6: Kernel modules

VLANs, bonds, VXLAN and VRFs are kernel modules. They usually load themselves as soon as you create an interface of that type. First check whether they exist at all:

# on netz
for m in vrf 8021q bonding vxlan; do modinfo -F filename $m; done

Expected (in the lab):

modinfo: ERROR: Module vrf not found.
/lib/modules/6.8.0-149-generic/kernel/net/8021q/8021q.ko.zst
/lib/modules/6.8.0-149-generic/kernel/drivers/net/bonding/bonding.ko.zst
/lib/modules/6.8.0-149-generic/kernel/drivers/net/vxlan/vxlan.ko.zst

Tried it: Ubuntu’s cloud image comes with the lean kernel linux-virtual. It lacks the package linux-modules-extra, and that’s where vrf lives. Without it, Day 4 fails only in the middle of the exercise.

# on netz
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y linux-modules-extra-$(uname -r) >/dev/null
modinfo -F filename vrf

Expected:

/lib/modules/6.8.0-149-generic/kernel/drivers/net/vrf.ko.zst

The package applies only to the running kernel. If an update brings a new kernel, you install it again for that one (or permanently install the metapackage linux-image-extra-virtual).

So that all four modules are loaded at every boot from now on:

# on netz
printf 'vrf\n8021q\nbonding\nvxlan\n' | sudo tee /etc/modules-load.d/netz.conf >/dev/null
for m in vrf 8021q bonding vxlan; do sudo modprobe $m; done
lsmod | grep -E "^(vrf|8021q|bonding|vxlan) " | awk '{print $1}' | sort

Expected:

8021q
bonding
vrf
vxlan

Save your progress? Sign up for free

Drill 7: The first namespace

A namespace is created quickly:

# on netz
sudo ip netns add probe
ip netns list
ls -l /run/netns/
sudo ip netns exec probe ip -br a
sudo ip netns exec probe ip r

Expected:

probe
total 0
-r--r--r-- 1 root root 0 Nov 23 16:36 probe
lo               DOWN

ip netns exec probe <command> runs a command in the namespace. Inside there’s only lo, without an address and without a single route. eth0 belongs to the VM and is invisible from here. The name probe is just a file under /run/netns, and /run is empty after a reboot: namespaces don’t survive a reboot.

Is there forwarding? Ask on the VM and in the namespace separately:

# on netz
sysctl net.ipv4.ip_forward net.ipv6.conf.all.forwarding
sudo ip netns exec probe sysctl net.ipv4.ip_forward

Expected:

net.ipv4.ip_forward = 0
net.ipv6.conf.all.forwarding = 0
net.ipv4.ip_forward = 0

Each namespace has its own network settings. So from Day 4 on, a router namespace needs its own forwarding, while the VM itself stays a normal machine that forwards nothing. That’s why ip_forward on the VM stays at 0 today.

Save your progress? Sign up for free

Exercise: Speed drills

  1. Show the default route and the DNS servers of eth0. Target time: 30 s
  2. Create a namespace, show its interfaces and delete it again. Target time: 1 min
  3. Show which FRR version is installed, without FRR running. Target time: 30 s

Solution

# on netz
ip r show default
resolvectl dns eth0
sudo ip netns add probe2
sudo ip netns exec probe2 ip -br link
sudo ip netns del probe2
dpkg-query -W -f='${Package} ${Version}\n' frr keepalived

Expected:

default via 172.16.0.1 dev eth0 proto dhcp src 172.16.0.123 metric 100
Link 2 (eth0): 172.16.0.15 8.8.8.8 1.1.1.1
lo               DOWN           00:00:00:00:00:00 <LOOPBACK>
frr 10.7.1-0~ubuntu24.04.1
keepalived 1:2.2.8-1build2

sudo vtysh -c "show version" doesn’t help with number 3: without running daemons it ends with Exiting: failed to connect to any daemons.

Save your progress? Sign up for free

Checkpoint

# on netz
getent hosts netz

Expected: 127.0.1.1 netz

# on netz
systemctl is-enabled frr keepalived

Expected: disabled twice

# on netz
lsmod | grep -cE "^(vrf|8021q|bonding|vxlan) "

Expected: 4

# on netz
sysctl -n net.ipv4.ip_forward

Expected: 0

Challenge

In the namespace probe from Drill 7, even a ping to its own loopback address fails:

# on netz
sudo ip netns exec probe ping -c1 -W1 127.0.0.1

Expected:

ping: connect: Network is unreachable

Get the ping working without recreating the namespace. Why does the ping to the gateway 172.16.0.1 still fail afterwards?

Hint: Take another close look at the lo line in ip -br a.

Solution

In a new namespace, lo is DOWN. Only together with the interface does it get its address 127.0.0.1/8 and the matching route:

# on netz
sudo ip netns exec probe ip link set lo up
sudo ip netns exec probe ip -br a
sudo ip netns exec probe ping -c1 -W1 127.0.0.1 | sed -n 2p
sudo ip netns exec probe ping -c1 -W1 172.16.0.1

Expected:

lo               UNKNOWN        127.0.0.1/8 ::1/128
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.137 ms
ping: connect: Network is unreachable

Everything is missing toward the gateway: no interface to the outside, no address, no route. That’s exactly what you build on Day 2 with a veth pair. Remember the message: Network is unreachable almost always means “no matching route,” not “the other side doesn’t answer.”

UNKNOWN instead of UP for lo is normal: loopback has no carrier the kernel could report.

Save your progress? Sign up for free

Clean-up

# on netz
sudo ip netns del probe
ip netns list

Expected: no output

FRR, keepalived, the modules and the tools stay: they are the ground for all the following days.

Practice note

  • Why namespaces instead of VMs? Ten routers as VMs need ten times the memory and boot time. As namespaces, they run on one VM with 4 GB, start in milliseconds and are gone with one command. Container platforms use exactly the same thing: every Pod in Kubernetes has its own network namespace.
  • And what’s different from real routers? All namespaces share one kernel. A kernel crash hits the whole network, and timing measurements fluctuate with the VM’s load. For understanding routing, VRRP and faults, that doesn’t matter.

Contents

More