Skip to content
Linux networking · Chapter 20 of 20 Appendix B: Final exam

Appendix B: Final exam

Goal: You find and fix ten faults from across the book in 120 minutes, each with cause and proof, and grade yourself · Duration: 120 min · Prerequisite: Days 0–16

Rules of the Game

  • Time: 120 minutes, set the clock. Each task counts 10%.
  • There is no certificate. Your own bar: from 70%, you have Linux networking down.
  • An examiner (a colleague or you yourself, without looking) runs the preparation before each task. The task describes only the symptom or the assignment.
  • Allowed: --help, man, the documentation of iproute2, FRR, nftables and dnsmasq. Not allowed: this course during the exam.
  • A task counts only with the cause in one sentence and a proof command. If you remove the symptom (flush the firewall, switch off rp_filter, rebuild the namespace), you get 0%.
  • All commands run on netz. The solutions are at the end. Read them only after the time is up.

Preparation

The playing field from Day 16, once before the first task:

# on netz
for n in r1 r2 r3 h1 h3; do sudo ip netns add $n; sudo ip -n $n link set lo up; done
sudo ip -n r1 link add eth12 type veth peer name eth21 netns r2
sudo ip -n r1 link add eth13 type veth peer name eth31 netns r3
sudo ip -n r2 link add eth23 type veth peer name eth32 netns r3
sudo ip -n r1 link add eth0 type veth peer name eth0 netns h1
sudo ip -n r3 link add eth0 type veth peer name eth0 netns h3
sudo ip -n r1 addr add 10.0.12.1/24 dev eth12
sudo ip -n r2 addr add 10.0.12.2/24 dev eth21
sudo ip -n r1 addr add 10.0.13.1/24 dev eth13
sudo ip -n r3 addr add 10.0.13.3/24 dev eth31
sudo ip -n r2 addr add 10.0.23.2/24 dev eth23
sudo ip -n r3 addr add 10.0.23.3/24 dev eth32
sudo ip -n r1 addr add 10.1.1.1/24 dev eth0
sudo ip -n h1 addr add 10.1.1.10/24 dev eth0
sudo ip -n r3 addr add 10.3.3.1/24 dev eth0
sudo ip -n h3 addr add 10.3.3.10/24 dev eth0
sudo ip -n r1 addr add 10.255.0.1/32 dev lo
sudo ip -n r2 addr add 10.255.0.2/32 dev lo
sudo ip -n r3 addr add 10.255.0.3/32 dev lo
for d in eth12 eth13 eth0; do sudo ip -n r1 link set $d up; done
for d in eth21 eth23; do sudo ip -n r2 link set $d up; done
for d in eth31 eth32 eth0; do sudo ip -n r3 link set $d up; done
sudo ip -n h1 link set eth0 up
sudo ip -n h3 link set eth0 up
sudo ip -n h1 route add default via 10.1.1.1
sudo ip -n h3 route add default via 10.3.3.1
for r in r1 r2 r3; do sudo ip netns exec $r sysctl -qw net.ipv4.ip_forward=1; done
for r in r1 r2 r3; do
  sudo mkdir -p /etc/frr/$r
  sudo sed 's/^ospfd=no/ospfd=yes/' /etc/frr/daemons | sudo tee /etc/frr/$r/daemons >/dev/null
  sudo touch /etc/frr/$r/frr.conf /etc/frr/$r/vtysh.conf
  sudo chown -R frr:frr /etc/frr/$r
  sudo systemctl start frr@$r
done
sudo vtysh -N r1 -c 'configure terminal' -c 'router ospf' -c 'ospf router-id 10.255.0.1' -c 'exit' -c 'interface lo' -c 'ip ospf area 0' -c 'exit' -c 'interface eth12' -c 'ip ospf area 0' -c 'ip ospf network point-to-point' -c 'exit' -c 'interface eth13' -c 'ip ospf area 0' -c 'ip ospf network point-to-point' -c 'exit' -c 'interface eth0' -c 'ip ospf area 0' -c 'ip ospf passive' -c 'end' -c 'write memory' >/dev/null
sudo vtysh -N r2 -c 'configure terminal' -c 'router ospf' -c 'ospf router-id 10.255.0.2' -c 'exit' -c 'interface lo' -c 'ip ospf area 0' -c 'exit' -c 'interface eth21' -c 'ip ospf area 0' -c 'ip ospf network point-to-point' -c 'exit' -c 'interface eth23' -c 'ip ospf area 0' -c 'ip ospf network point-to-point' -c 'end' -c 'write memory' >/dev/null
sudo vtysh -N r3 -c 'configure terminal' -c 'router ospf' -c 'ospf router-id 10.255.0.3' -c 'exit' -c 'interface lo' -c 'ip ospf area 0' -c 'exit' -c 'interface eth31' -c 'ip ospf area 0' -c 'ip ospf network point-to-point' -c 'exit' -c 'interface eth32' -c 'ip ospf area 0' -c 'ip ospf network point-to-point' -c 'exit' -c 'interface eth0' -c 'ip ospf area 0' -c 'ip ospf passive' -c 'end' -c 'write memory' >/dev/null
mkdir -p ~/pruefung/web
head -c 3000000 /dev/urandom > ~/pruefung/web/gross.bin
echo "h3 ist da" > ~/pruefung/web/index.html
sudo ip netns exec h3 sudo -u ubuntu python3 -m http.server 8080 --directory /home/ubuntu/pruefung/web >/dev/null 2>&1 &
sleep 15
for r in r1 r2 r3; do echo "$r $(sudo vtysh -N $r -c 'show ip ospf neighbor' | grep -c Full)"; done
sudo ip netns exec h1 curl -s http://10.3.3.10:8080/

Expected:

r1 2
r2 2
r3 2
h3 ist da

Task 1: No network (10%)

Examiner:

# on netz
sudo ip -n h1 route del default
clear

h1 reports an error immediately on every ping to 10.3.3.10, without waiting. Fix it.

Task 2: Only h1 fails (10%)

Examiner:

# on netz
sudo ip -n r1 route add blackhole 10.3.3.0/24 table 100
sudo ip -n r1 rule add from 10.1.1.10 lookup 100 priority 100
clear

h1 can no longer reach h3, without any error message. r1 itself reaches h3, OSPF is healthy, and ip route on r1 shows the correct path.

Task 3: The new service (10%)

Examiner:

# on netz
sudo ip netns exec h3 sudo -u ubuntu python3 -m http.server 9090 --bind 127.0.0.1 --directory /home/ubuntu/pruefung/web >/dev/null 2>&1 &
clear

A second web server has just started on port 9090 on h3. The colleague says it works; he tested it on h3 itself. From h1, no connection can be established.

Task 4: Names (10%)

Examiner:

# on netz
sudo tee /etc/dnsmasq-pruefung.conf >/dev/null <<'EOF'
listen-address=127.0.0.1
bind-interfaces
no-hosts
no-resolv
host-record=web.firma.lan,10.3.3.10
pid-file=/run/dnsmasq-pruefung.pid
EOF
sudo ip netns exec r1 dnsmasq --conf-file=/etc/dnsmasq-pruefung.conf
sudo mkdir -p /etc/netns/h1
echo "nameserver 10.1.1.1" | sudo tee /etc/netns/h1/resolv.conf >/dev/null
clear

A DNS server runs on r1, and h1 is configured to use it. Still, curl http://web.firma.lan:8080/ fails on h1.

Task 5: The stranger (10%)

Examiner:

# on netz
sudo ip netns exec h1 sh -c 'while true; do echo ping | nc -u -w0 10.3.3.10 $((40000 + 1234)); sleep 2; done' >/dev/null 2>&1 &
clear

The firewall of h3 reports regular packets from h1. Find out which protocol, which destination port and which process on h1 sends them, and stop it.

Task 6: Large packets (10%)

Examiner:

# on netz
sudo ip -n h3 link set eth0 mtu 1400
clear

Normal pings from h1 to h3 get through; pings with -s 1472 are lost without any error message.

Task 7: Throttled (10%)

Examiner:

# on netz
sudo ip netns exec r3 tc qdisc add dev eth31 root tbf rate 20mbit burst 32kb latency 50ms
clear

The download of http://10.3.3.10:8080/gross.bin on h1 takes over a second; before, it took milliseconds. Ping looks unremarkable. What is the cause, and at what rate did the download run?

Task 8: A neighbor is missing (10%)

Examiner:

# on netz
sudo vtysh -N r2 -c 'configure terminal' -c 'interface eth23' -c 'no ip ospf area' -c 'ip ospf area 1' -c 'end' >/dev/null
sleep 45
clear

r2 has only one OSPF neighbor left, and so does r3. The link between the two is fine.

Task 9: Distribution (10%)

No preparation. r1 knows the network 10.0.23.0/24 via two equal-cost paths. Show this and prove, with four imagined TCP connections from h1 (source ports 50001 to 50004, destination port 80, destination 10.0.23.2), which paths r1 sends them over. Change the setting so that the connections of a single client are distributed, and prove it.

Task 10: Full table (10%)

Examiner:

# on netz
sudo ip netns exec r3 nft add table ip nat
sudo ip netns exec r3 nft add chain ip nat post '{ type nat hook postrouting priority srcnat; }'
sudo ip netns exec r3 nft add rule ip nat post oifname eth0 masquerade
sudo sysctl -qw net.netfilter.nf_conntrack_max=40
clear

After a change on r3, many requests to the web server from h1 fail, others succeed. The web server itself is healthy. Find the cause.

Solutions

Solution 1

# on netz
sudo ip netns exec h1 ping -c1 -W1 10.3.3.10 2>&1 | head -1
sudo ip -n h1 route

Expected:

ping: connect: Network is unreachable
10.1.1.0/24 dev eth0 proto kernel scope link src 10.1.1.10

Cause: h1 has no default route. The kernel finds no entry for 10.3.3.10 and rejects it locally, hence the immediate error (Day 1).

# on netz
sudo ip -n h1 route add default via 10.1.1.1
sudo ip netns exec h1 ping -c1 -W1 10.3.3.10 | grep -o '1 received'

Expected: 1 received

Solution 2

# on netz
sudo ip -n r1 route get 10.3.3.10
sudo ip -n r1 rule
sudo ip -n r1 route show table 100

Expected:

10.3.3.10 via 10.0.13.3 dev eth13 src 10.0.13.1 uid 0
    cache
0:  from all lookup local
100:    from 10.1.1.10 lookup 100
32766:  from all lookup main
32767:  from all lookup default
blackhole 10.3.3.0/24

Cause: A policy rule sends everything with source 10.1.1.10 to table 100, and there sits a blackhole for the network of h3 (Day 4). ip route shows only the table main, which is why everything looks correct. A blackhole drops silently, without an ICMP message.

# on netz
sudo ip -n r1 rule del priority 100
sudo ip -n r1 route flush table 100
sudo ip netns exec h1 ping -c1 -W1 10.3.3.10 | grep -o '1 received'

Expected: 1 received

Solution 3

# on netz
sudo ip netns exec h1 curl -sS -m 2 http://10.3.3.10:9090/ 2>&1
sudo ip netns exec h3 ss -Htlnp 'sport = :9090'

Expected:

curl: (7) Failed to connect to 10.3.3.10 port 9090 after 0 ms: Couldn't connect to server
LISTEN 0      5      127.0.0.1:9090 0.0.0.0:* users:(("python3",pid=30819,fd=3))

Cause: The service listens only on 127.0.0.1. It works on h3 itself; from outside, the port looks closed (Day 5).

# on netz
for p in $(pgrep -f '^python3 -m http.server 9090'); do sudo kill $p; done
sudo ip netns exec h3 sudo -u ubuntu python3 -m http.server 9090 --bind 0.0.0.0 --directory /home/ubuntu/pruefung/web >/dev/null 2>&1 &
sleep 1
sudo ip netns exec h1 curl -s http://10.3.3.10:9090/

Expected: h3 ist da

Solution 4

# on netz
sudo ip netns exec h1 curl -sS -m 3 http://web.firma.lan:8080/ 2>&1
sudo ip netns exec h1 dig +tries=1 +time=1 web.firma.lan 2>&1 | grep -E 'refused|timed out|status' | head -1
sudo ip netns exec r1 ss -Hulnp | grep dnsmasq

Expected:

curl: (6) Could not resolve host: web.firma.lan
;; communications error to 10.1.1.1#53: connection refused
UNCONN 0      0      127.0.0.1:53 0.0.0.0:* users:(("dnsmasq",pid=30888,fd=4))

Cause: dnsmasq listens only on 127.0.0.1 (listen-address); the kernel rejects queries to 10.1.1.1 (Day 6).

# on netz
sudo kill $(cat /run/dnsmasq-pruefung.pid)
sudo sed -i 's/^listen-address=127.0.0.1/listen-address=10.1.1.1/' /etc/dnsmasq-pruefung.conf
sudo ip netns exec r1 dnsmasq --conf-file=/etc/dnsmasq-pruefung.conf
sudo ip netns exec h1 curl -s http://web.firma.lan:8080/

Expected: h3 ist da

Solution 5

# on netz
sudo ip netns exec r3 tcpdump -i eth31 -n -c 2 udp 2>/dev/null
sudo ip netns pids h1 | xargs ps -o pid=,args= -p | cut -c1-90

Expected:

01:36:57.154988 IP 10.1.1.10.60333 > 10.3.3.10.41234: UDP, length 5
01:36:59.164735 IP 10.1.1.10.42854 > 10.3.3.10.41234: UDP, length 5
  30924 sh -c while true; do echo ping | nc -u -w0 10.3.3.10 $((40000 + 1234)); sleep 2; d
  30971 sleep 2

Cause: A shell loop in h1 sends five bytes via UDP to port 41234 every 2 seconds (Day 7). ss does not help here: connectionless UDP leaves no persistent socket. ip netns pids lists all processes of a namespace, ps shows what they are.

# on netz
for p in $(sudo ip netns pids h1); do ps -o args= -p $p | grep -q '^sh -c while' && sudo kill $p; done
sleep 3
sudo ip netns pids h1 | wc -l

Expected: 0

Solution 6

# on netz
sudo ip netns exec h1 ping -c3 -W1 -q -s 1472 10.3.3.10 | grep received
sudo ip -n r3 link show eth0 | grep -o 'mtu [0-9]*'
sudo ip -n h3 link show eth0 | grep -o 'mtu [0-9]*'
sudo ip netns exec h3 ip -s link show eth0 | sed -n '/RX:/,+1p'

Expected:

3 packets transmitted, 0 received, 100% packet loss, time 2086ms
mtu 1500
mtu 1400
    RX:  bytes packets errors dropped  missed   mcast
        104580      63      0      78       0       0

Cause: The MTUs differ on the link between r3 and h3. r3 sends 1500 bytes, h3 accepts at most 1400 and silently drops the rest (the dropped counter rises with every large ping). r3 reports nothing back; for it, the packet fit (Day 8). TCP does not notice, because h3 announces a smaller MSS during connection setup, which is why such a fault often goes unnoticed for a long time.

# on netz
sudo ip -n h3 link set eth0 mtu 1500
sudo ip netns exec h1 ping -c2 -W1 -q -s 1472 10.3.3.10 | grep received

Expected: 2 packets transmitted, 2 received, 0% packet loss, time 1001ms

Solution 7

# on netz
sudo ip netns exec h1 curl -s -o /dev/null -m 20 -w '%{http_code} %{size_download} Byte in %{time_total} s, %{speed_download} Byte/s\n' http://10.3.3.10:8080/gross.bin
for r in r1 r2 r3; do for d in $(sudo ip -n $r -o link show | grep -o 'eth[0-9]*@' | tr -d @); do q=$(sudo ip netns exec $r tc qdisc show dev $d | grep -v noqueue); [ -n "$q" ] && echo "$r $d: $q"; done; done
sudo ip netns exec r3 tc -s qdisc show dev eth31 | head -2

Expected:

200 3000000 Byte in 1.249952 s, 2400092 Byte/s
r3 eth31: qdisc tbf 8010: root refcnt 3 rate 20Mbit burst 32Kb lat 50ms
qdisc tbf 8010: root refcnt 3 rate 20Mbit burst 32Kb lat 50ms
 Sent 3137655 bytes 2081 pkt (dropped 3, overlimits 1415 requeues 0)

Cause: A token bucket filter on eth31 of r3 throttles the direction toward h1 to 20 Mbit/s. The download ran at 2.4 MB/s, a good 19 Mbit/s, just below the limit (Day 9). Unlike with loss, tbf hardly drops anything (dropped 3); it delays (overlimits).

# on netz
sudo ip netns exec r3 tc qdisc del dev eth31 root
sudo ip netns exec h1 curl -s -o /dev/null -w '%{http_code} %{size_download} Byte in %{time_total} s\n' http://10.3.3.10:8080/gross.bin

Expected: 200 3000000 Byte in 0.010076 s

Solution 8

# on netz
for r in r1 r2 r3; do echo "$r $(sudo vtysh -N $r -c 'show ip ospf neighbor' | grep -c Full)"; done
sudo vtysh -N r2 -c 'show ip ospf interface eth23' | grep -E 'Area'
sudo vtysh -N r3 -c 'show ip ospf interface eth32' | grep -E 'Area'

Expected:

r1 2
r2 1
r3 1
  Internet Address 10.0.23.2/24, Broadcast 10.0.23.255, Area 0.0.0.1
  Internet Address 10.0.23.3/24, Broadcast 10.0.23.255, Area 0.0.0.0

Cause: The two ends of the link r2–r3 are in different OSPF areas (1 and 0). Hello packets with a different area are discarded, and an adjacency never forms (Day 10). FRR requires removing the old assignment before a new one takes effect:

# on netz
sudo vtysh -N r2 -c 'configure terminal' -c 'interface eth23' -c 'no ip ospf area' -c 'ip ospf area 0' -c 'end' -c 'write memory' >/dev/null
sleep 12
for r in r1 r2 r3; do echo "$r $(sudo vtysh -N $r -c 'show ip ospf neighbor' | grep -c Full)"; done

Expected:

r1 2
r2 2
r3 2

Without no ip ospf area, FRR reports Must remove previous area config before changing ospf area and leaves everything as it was.

Solution 9

# on netz
sudo ip -n r1 route show 10.0.23.0/24
sudo ip netns exec r1 sysctl net.ipv4.fib_multipath_hash_policy
for sp in 50001 50002 50003 50004; do sudo ip -n r1 route get 10.0.23.2 from 10.1.1.10 iif eth0 ipproto tcp sport $sp dport 80 | head -1; done

Expected:

10.0.23.0/24 nhid 20 proto ospf metric 20
    nexthop via 10.0.12.2 dev eth12 weight 1
    nexthop via 10.0.13.3 dev eth13 weight 1
net.ipv4.fib_multipath_hash_policy = 0
10.0.23.2 from 10.1.1.10 via 10.0.13.3 dev eth13
10.0.23.2 from 10.1.1.10 via 10.0.13.3 dev eth13
10.0.23.2 from 10.1.1.10 via 10.0.13.3 dev eth13
10.0.23.2 from 10.1.1.10 via 10.0.13.3 dev eth13

Answer: Two next hops, but hash policy 0 (addresses only): all connections of one client to the same destination take the same path (Day 13). With policy 1, the ports count too:

# on netz
sudo ip netns exec r1 sysctl -w net.ipv4.fib_multipath_hash_policy=1
for sp in 50001 50002 50003 50004; do sudo ip -n r1 route get 10.0.23.2 from 10.1.1.10 iif eth0 ipproto tcp sport $sp dport 80 | head -1; done

Expected:

net.ipv4.fib_multipath_hash_policy = 1
10.0.23.2 from 10.1.1.10 via 10.0.13.3 dev eth13
10.0.23.2 from 10.1.1.10 via 10.0.13.3 dev eth13
10.0.23.2 from 10.1.1.10 via 10.0.12.2 dev eth12
10.0.23.2 from 10.1.1.10 via 10.0.13.3 dev eth13

One of four via eth12. Four samples are few; the hash only distributes evenly across many connections.

Solution 10

# on netz
ok=0; fail=0; for i in $(seq 1 60); do if sudo ip netns exec h1 curl -s -m1 -o /dev/null http://10.3.3.10:8080/; then ok=$((ok+1)); else fail=$((fail+1)); fi; done; echo "ok=$ok fail=$fail"
sudo ip netns exec r3 conntrack -C
sysctl net.netfilter.nf_conntrack_max
sudo dmesg | grep -i 'table full' | tail -1 | cut -c16-

Expected:

ok=40 fail=20
40
net.netfilter.nf_conntrack_max = 40
nf_conntrack: nf_conntrack: table full, dropping packet

Cause: With the NAT on r3, the kernel tracks every connection there. The table holds only 40 entries, TIME_WAIT entries live for 120 seconds, so every 41st connection attempt is dropped (Day 5). The value applies to the whole VM and can only be set in the root namespace:

# on netz
sudo sysctl -w net.netfilter.nf_conntrack_max=65536
sudo ip netns exec r3 conntrack -F
sudo ip netns exec h1 curl -s -m1 -o /dev/null -w '%{http_code}\n' http://10.3.3.10:8080/
sudo ip netns exec r3 nft delete table ip nat

Expected:

net.netfilter.nf_conntrack_max = 65536
conntrack v1.4.8 (conntrack-tools): connection tracking table has been emptied.
200

The NAT itself was not the fault, but it is unnecessary here, so it goes too.

Grading

Result Rating
90–100% A network engineer with Linux as a toolbox
70–80% The basics are solid; now you know your gaps
under 70% Revisit the days behind the tasks you missed

Clean-up

# on netz
sudo kill $(cat /run/dnsmasq-pruefung.pid)
sudo rm -f /etc/dnsmasq-pruefung.conf
sudo rm -r /etc/netns
for p in $(pgrep -f '^python3 -m http.server'); do sudo kill $p; done
sudo systemctl stop frr@r1 frr@r2 frr@r3
sudo rm -rf /etc/frr/r1 /etc/frr/r2 /etc/frr/r3
for n in r1 r2 r3 h1 h3; do sudo ip netns del $n; done
rm -rf ~/pruefung
ip netns list | wc -l
pgrep -a 'zebra|ospfd|dnsmasq|python3' || echo "keine Labor-Prozesse"
sysctl net.netfilter.nf_conntrack_max

Expected:

0
keine Labor-Prozesse
net.netfilter.nf_conntrack_max = 65536

Passed the exam? With a free account it counts towards your belt. Sign up for free

Contents

More