Day 9: Measure and Disturb: iperf3, mtr, ethtool, and tc netem
Goal: Measure throughput, delay, and loss instead of guessing. Build a bad link with
tc netemand see how little loss it takes for TCP to collapse. Recognize the trap in mtr, understand offloads, and fix bufferbloat with one line · Duration: approx. 90 min · Prerequisite: Days 4 and 7
Briefing
- iperf3 measures throughput between two points: one server, one client, numbers per second. With TCP you see what a connection can do, with UDP what arrives when nobody brakes.
- mtr combines traceroute and ping: loss and round-trip time for every hop, measured continuously.
- ethtool shows what an interface can do and is doing: driver, speed, offloads, counters.
- tc (traffic control) controls the queue of an interface. With netem it delays, drops, or reorders packets, with tbf it throttles, with fq_codel it keeps the waiting time short. This lets you rebuild in the lab any bad link you run into in operations.
┌─────┐ 10.90.1.0/24 ┌──────────────┐ 10.90.2.0/24 ┌──────────────────┐
│ cli ├───────────────┤ eth1 r eth2├───────────────┤ srv: iperf3 5201 │
│ .10 │ │ tc netem/tbf │ │ .20 │
└─────┘ └──────────────┘ └──────────────────┘
One rule applies to everything that follows today: tc only
affects outgoing packets. A disturbance on eth2 of
r hits the path to srv, not the way back.
Drill 1: Lab and iperf3 Server
# on netz
sudo ip netns add r
sudo ip netns add cli
sudo ip netns add srv
sudo ip -n r link set lo up
sudo ip -n cli link set lo up
sudo ip -n srv link set lo up
sudo ip -n r link add eth1 type veth peer name eth0 netns cli
sudo ip -n r link add eth2 type veth peer name eth0 netns srv
sudo ip -n r addr add 10.90.1.1/24 dev eth1
sudo ip -n r addr add 10.90.2.1/24 dev eth2
sudo ip -n cli addr add 10.90.1.10/24 dev eth0
sudo ip -n srv addr add 10.90.2.20/24 dev eth0
sudo ip -n r link set eth1 up
sudo ip -n r link set eth2 up
sudo ip -n cli link set eth0 up
sudo ip -n srv link set eth0 up
sudo ip -n cli route add default via 10.90.1.1
sudo ip -n srv route add default via 10.90.2.1
sudo ip netns exec r sysctl -qw net.ipv4.ip_forward=1
sudo ip netns exec cli ping -c1 -W1 10.90.2.20 | grep -o '1 received'
sudo ip netns exec srv iperf3 -s -DExpected: 1 received
-D starts the iperf3 server as a background daemon. It
listens on port 5201 and accepts one test after the other.
Save your progress? Sign up for free
Drill 2: Throughput with TCP
# on netz
sudo ip netns exec cli iperf3 -c 10.90.2.20 -t 5Expected:
Connecting to host 10.90.2.20, port 5201
[ 5] local 10.90.1.10 port 45798 connected to 10.90.2.20 port 5201
[ ID] Interval Transfer Bitrate Retr Cwnd
[ 5] 0.00-1.00 sec 1.35 GBytes 11.6 Gbits/sec 0 942 KBytes
[ 5] 1.00-2.00 sec 1.81 GBytes 15.6 Gbits/sec 0 1.34 MBytes
[ 5] 2.00-3.00 sec 1.70 GBytes 14.6 Gbits/sec 1 1.67 MBytes
[ 5] 3.00-4.00 sec 1.76 GBytes 15.1 Gbits/sec 0 1.75 MBytes
[ 5] 4.00-5.00 sec 1.94 GBytes 16.7 Gbits/sec 0 1.84 MBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bitrate Retr
[ 5] 0.00-5.00 sec 8.66 GBytes 14.9 Gbits/sec 1 sender
[ 5] 0.00-5.00 sec 8.66 GBytes 14.9 Gbits/sec receiver
iperf Done.
15 Gbit/s through a router, all in the memory of one VM: veth has no wire, only CPU. The columns:
| Column | Meaning |
|---|---|
Bitrate |
Throughput in this interval |
Retr |
Retransmits: segments TCP had to send again |
Cwnd |
Congestion window (Day 5): this much may be in flight unacknowledged, it grows as long as nothing is lost |
sender/receiver |
Total on both sides. If they differ a lot, something got lost on the way |
By default the client sends. -R reverses the direction
(the server sends), -P 4 opens four connections at
once:
# on netz
sudo ip netns exec cli iperf3 -c 10.90.2.20 -t 5 -R | tail -4
sudo ip netns exec cli iperf3 -c 10.90.2.20 -t 5 -P 4 | grep -E 'SUM.*(sender|receiver)'Expected:
[ 5] 0.00-5.00 sec 8.28 GBytes 14.2 Gbits/sec 0 sender
[ 5] 0.00-5.00 sec 8.28 GBytes 14.2 Gbits/sec receiver
iperf Done.
[SUM] 0.00-5.00 sec 11.8 GBytes 20.2 Gbits/sec 0 sender
[SUM] 0.00-5.00 sec 11.8 GBytes 20.2 Gbits/sec receiver
Four connections reach 20 instead of 15 Gbit/s because they spread
across both CPU cores. If -P 4 achieves clearly more than
one connection, the bottleneck is not the link but something per
connection: CPU, window, or delay (Drill 4).
Save your progress? Sign up for free
Drill 3: UDP Has No Brakes
UDP sends at the rate you specify (-b), whether it
arrives or not:
# on netz
sudo ip netns exec cli iperf3 -c 10.90.2.20 -u -b 100M -t 5 | tail -4
sudo ip netns exec cli iperf3 -c 10.90.2.20 -u -b 5G -t 5 | tail -4Expected:
[ 5] 0.00-5.00 sec 59.6 MBytes 100 Mbits/sec 0.000 ms 0/43156 (0%) sender
[ 5] 0.00-5.00 sec 59.6 MBytes 100 Mbits/sec 0.010 ms 0/43156 (0%) receiver
iperf Done.
[ 5] 0.00-5.00 sec 639 MBytes 1.07 Gbits/sec 0.000 ms 0/462455 (0%) sender
[ 5] 0.00-5.00 sec 517 MBytes 867 Mbits/sec 0.006 ms 87884/462455 (19%) receiver
iperf Done.
100 Mbit/s arrive completely. At an ordered 5 Gbit/s, the sender only manages 1.07 Gbit/s (one datagram per system call costs CPU), and the receiver cannot keep up: 19% get lost. TCP would have braked, UDP does not. That is why you measure loss and jitter with UDP (the variation in round-trip time, important for voice and video), and throughput with TCP.
Save your progress? Sign up for free
Drill 4: Delay
Now the router delays everything it sends to srv by 50
milliseconds:
# on netz
sudo ip netns exec cli ping -c3 -q 10.90.2.20 | tail -1
sudo ip netns exec r tc qdisc add dev eth2 root netem delay 50ms
sudo ip netns exec r tc qdisc show dev eth2
sudo ip netns exec cli ping -c3 -q 10.90.2.20 | tail -1
sudo ip netns exec cli iperf3 -c 10.90.2.20 -t 8 | grep -E 'sender|receiver| [0-7].00-'Expected:
rtt min/avg/max/mdev = 0.065/0.093/0.137/0.031 ms
qdisc netem 8002: root refcnt 3 limit 1000 delay 50ms
rtt min/avg/max/mdev = 50.168/50.253/50.323/0.064 ms
[ 5] 0.00-1.00 sec 45.8 MBytes 383 Mbits/sec 0 7.95 MBytes
[ 5] 1.00-2.00 sec 74.9 MBytes 628 Mbits/sec 0 7.95 MBytes
[ 5] 2.00-3.00 sec 70.6 MBytes 593 Mbits/sec 0 7.95 MBytes
[ 5] 3.00-4.00 sec 70.9 MBytes 595 Mbits/sec 0 7.95 MBytes
[ 5] 4.00-5.00 sec 74.2 MBytes 623 Mbits/sec 0 8.01 MBytes
[ 5] 5.00-6.00 sec 70.8 MBytes 593 Mbits/sec 90 8.01 MBytes
[ 5] 6.00-7.00 sec 70.6 MBytes 592 Mbits/sec 0 8.01 MBytes
[ 5] 7.00-8.00 sec 72.5 MBytes 607 Mbits/sec 0 8.01 MBytes
[ 5] 0.00-8.00 sec 553 MBytes 580 Mbits/sec 90 sender
[ 5] 0.00-8.05 sec 553 MBytes 576 Mbits/sec receiver
No loss, no narrower link, just 50 ms of round-trip time, and a single connection drops from 15 Gbit/s to 580 Mbit/s. This is the bandwidth-delay product: TCP may send at most one window full of data unacknowledged and must then wait for the acknowledgment, which takes one round trip.
Throughput ≤ window ÷ round-trip time
The window grows up to the kernel’s buffer limit
(net.ipv4.tcp_rmem and tcp_wmem, about 8 MB
here). In the lab there is a second limit: netem holds at most 1000
packets (limit 1000), and the 90 retransmits are packets
that found no more room there. On long distances (data center to data
center, backup across continents) this is why several parallel
connections are so much faster than one.
Real links fluctuate. netem delay 50ms 20ms scatters
every delay by ±20 ms:
# on netz
sudo ip netns exec r tc qdisc change dev eth2 root netem delay 50ms 20ms
sudo ip netns exec cli ping -c10 -q 10.90.2.20 | tail -1
sudo ip netns exec r tc qdisc del dev eth2 rootExpected:
rtt min/avg/max/mdev = 30.912/55.062/69.350/11.104 ms
mdev is the jitter. change modifies an
existing rule, del removes it.
Save your progress? Sign up for free
Drill 5: Loss
First the healthy path with mtr, then 10% loss toward
srv:
# on netz
sudo ip netns exec cli mtr -n -r -c 20 10.90.2.20
sudo ip netns exec r tc qdisc add dev eth2 root netem loss 10%
sudo ip netns exec cli mtr -n -r -c 50 10.90.2.20
sudo ip netns exec cli iperf3 -c 10.90.2.20 -t 5 | grep -E 'sender|receiver'
sudo ip netns exec r tc qdisc del dev eth2 rootExpected:
Start: 2026-11-24T00:28:56+0000
HOST: netz Loss% Snt Last Avg Best Wrst StDev
1.|-- 10.90.1.1 0.0% 20 0.2 0.2 0.1 0.5 0.1
2.|-- 10.90.2.20 0.0% 20 0.1 0.2 0.1 0.3 0.0
Start: 2026-11-24T00:29:20+0000
HOST: netz Loss% Snt Last Avg Best Wrst StDev
1.|-- 10.90.1.1 0.0% 50 0.2 0.2 0.1 0.3 0.0
2.|-- 10.90.2.20 14.0% 50 0.2 0.2 0.1 0.6 0.1
[ 5] 0.00-5.00 sec 4.50 MBytes 7.55 Mbits/sec 387 sender
[ 5] 0.00-5.00 sec 4.00 MBytes 6.71 Mbits/sec receiver
-r turns mtr into a report instead of a live display,
-c sets the number of probes. The loss only shows up at hop
2, because nothing gets lost until after r. 14 instead of
10% is chance with 50 probes.
And TCP: from 14.9 Gbit/s to 7.55 Mbit/s, one two-thousandth. With every loss TCP halves its congestion window, with every timeout it starts almost from scratch. Even 1% loss is a disaster for TCP. When you hear “the link is slow,” look for loss first, then for bandwidth.
Save your progress? Sign up for free
Drill 6: The Trap in mtr
Routers answer packets that expire at them with ICMP “Time Exceeded.”
They are not keen on it: the kernel limits the rate. Here r
gets a bit stricter, and mtr asks five times per second:
# on netz
sudo ip netns exec r sysctl net.ipv4.icmp_ratelimit net.ipv4.icmp_ratemask
sudo ip netns exec r sysctl -qw net.ipv4.icmp_ratelimit=2000
sudo ip netns exec cli mtr -n -r -c 30 -i 0.2 10.90.2.20
sudo ip netns exec r sysctl -qw net.ipv4.icmp_ratelimit=1000Expected:
net.ipv4.icmp_ratelimit = 1000
net.ipv4.icmp_ratemask = 6168
Start: 2026-11-24T00:30:31+0000
HOST: netz Loss% Snt Last Avg Best Wrst StDev
1.|-- 10.90.1.1 73.3% 30 0.1 0.2 0.1 0.6 0.1
2.|-- 10.90.2.20 0.0% 30 0.1 0.2 0.1 0.4 0.1
73% loss at r, 0% at the target. Everything passes
through r; it just does not answer every question addressed
to itself. This is the most common false alarm with mtr: loss
only counts if it persists all the way to the target. Loss at a
hop in the middle that disappears afterwards is response rate limiting
or a router that gives ICMP low priority.
icmp_ratelimit is the minimum interval in milliseconds,
icmp_ratemask (6168 = bits 3, 4, 11, 12) says which ICMP
types are affected: Destination Unreachable, Source Quench, Time
Exceeded, and Parameter Problem. Echo Reply is not among them, which is
why the target answers every ping.
Save your progress? Sign up for free
Drill 7: ethtool and Offloads
The interface of the VM and that of a namespace:
# on netz
ethtool -i eth0 | head -1
ethtool eth0 2>/dev/null | grep -E 'Speed|Link detected'
sudo ip netns exec cli ethtool -i eth0 | head -1
sudo ip netns exec cli ethtool eth0 | grep -E 'Speed|Link detected'
sudo ip netns exec cli ethtool -k eth0 | grep -E '^(tcp-segmentation-offload|generic-segmentation-offload|generic-receive-offload|tx-checksumming|rx-checksumming):'
sudo ip netns exec cli ethtool -S eth0 | head -4Expected:
driver: virtio_net
Speed: Unknown!
Link detected: yes
driver: veth
Speed: 10000Mb/s
Link detected: yes
rx-checksumming: on
tx-checksumming: on
tcp-segmentation-offload: on
generic-segmentation-offload: on
generic-receive-offload: off
NIC statistics:
peer_ifindex: 2
rx_queue_0_xdp_packets: 0
rx_queue_0_xdp_bytes: 0
virtio_net is the virtual NIC of KVM/Proxmox; it reports
no speed. veth claims 10 Gbit/s and achieves 15 (Drill 2): the value is
a label, not a limit. On real hardware ethtool shows the
negotiated speed here, and Speed: 100Mb/s on a server is a
classic finding (wrong cable, half-broken port).
Offloads move work from the kernel to the NIC. With
tcp-segmentation-offload the kernel hands over segments of
up to 64 KB, and the NIC splits them into packets. A comparison shows
how much this gains: a capture in the client while the server sends,
once with and once without offload on the server:
# on netz
sudo ip netns exec cli tcpdump -i eth0 -n -c 300 'tcp and src host 10.90.2.20' 2>/dev/null | grep -o 'length [0-9]*' | sort -t' ' -k2 -n | tail -1 &
sleep 1; sudo ip netns exec cli iperf3 -c 10.90.2.20 -t 2 -R >/dev/null; wait
sudo ip netns exec srv ethtool -K eth0 tso off gso off
sudo ip netns exec cli tcpdump -i eth0 -n -c 300 'tcp and src host 10.90.2.20' 2>/dev/null | grep -o 'length [0-9]*' | sort -t' ' -k2 -n | tail -1 &
sleep 1; sudo ip netns exec cli iperf3 -c 10.90.2.20 -t 2 -R | grep receiver; wait
sudo ip netns exec srv ethtool -K eth0 tso on gso onExpected:
length 65160
length 1448
[ 5] 0.00-2.00 sec 624 MBytes 2.62 Gbits/sec receiver
With offload, a 65,160-byte segment travels through veth without ever being split (the giant packets from Day 7). Without offload, the kernel splits into 1448-byte segments itself, and throughput drops from just over 14 to 2.6 Gbit/s. So offloads are not a detail but a factor of five. Turn them off only for troubleshooting (captures that should match the wire, or a driver bug) and back on afterwards.
Save your progress? Sign up for free
Drill 8: Bufferbloat
A 100 Mbit/s link, throttled with tbf (Token Bucket
Filter). latency 400ms allows the queue to buffer up to 400
ms of data, like many routers with generous memory:
# on netz
sudo ip netns exec r tc qdisc add dev eth2 root tbf rate 100mbit burst 32kb latency 400ms
sudo ip netns exec cli iperf3 -c 10.90.2.20 -t 12 > /tmp/last.txt &
sleep 3; sudo ip netns exec cli ping -c 6 -q 10.90.2.20 | tail -1; wait
grep -E 'sender|receiver' /tmp/last.txtExpected:
rtt min/avg/max/mdev = 152.993/210.734/227.598/27.193 ms
[ 5] 0.00-12.00 sec 140 MBytes 97.8 Mbits/sec 1 sender
[ 5] 0.00-12.00 sec 139 MBytes 95.4 Mbits/sec receiver
The download uses the link fully, and every ping waits 210 ms in the queue behind it. Without load it was 0.1 ms. This is bufferbloat: the link is not too slow, but every click, every phone call, and every SSH keystroke waits behind the big download. The remedy is a queue that separates flows and never lets long waiting times build up in the first place, fq_codel:
# on netz
sudo ip netns exec r tc qdisc del dev eth2 root
sudo ip netns exec r tc qdisc add dev eth2 root handle 1: tbf rate 100mbit burst 32kb latency 400ms
sudo ip netns exec r tc qdisc add dev eth2 parent 1:1 fq_codel
sudo ip netns exec r tc qdisc show dev eth2
sudo ip netns exec cli iperf3 -c 10.90.2.20 -t 12 > /tmp/last.txt &
sleep 3; sudo ip netns exec cli ping -c 6 -q 10.90.2.20 | tail -1; wait
grep -E 'sender|receiver' /tmp/last.txtExpected:
qdisc tbf 1: root refcnt 3 rate 100Mbit burst 32Kb lat 400ms
qdisc fq_codel 8005: parent 1:1 limit 10240p flows 1024 quantum 1514 target 5ms interval 100ms memory_limit 32Mb ecn drop_batch 64
rtt min/avg/max/mdev = 0.214/1.067/1.393/0.403 ms
[ 5] 0.00-12.00 sec 137 MBytes 95.7 Mbits/sec 289 sender
[ 5] 0.00-12.00 sec 136 MBytes 95.2 Mbits/sec receiver
Same throughput, and the ping waits 1 ms instead of 210. fq_codel
gives every flow its own queue (the ping overtakes the download) and
deliberately drops packets as soon as a flow waits longer than
target 5ms. The 289 retransmits are exactly that: TCP
notices early that it has to brake instead of filling the buffer. By the
way, fq_codel is the default queue of every real interface on Ubuntu
(sysctl net.core.default_qdisc). Bufferbloat occurs where a
device with a large buffer forms the bottleneck: router, modem,
firewall.
# on netz
sudo ip netns exec r tc qdisc del dev eth2 rootSave your progress? Sign up for free
Exercise: Speed drills
- Send UDP at 50 Mbit/s to
srvfor 3 seconds and read off the loss. Target time: 30 s - Which queue is currently attached to
eth2ofr? Target time: 15 s - Which driver does
eth0inclihave? Target time: 15 s
Solution
# on netz
sudo ip netns exec cli iperf3 -c 10.90.2.20 -u -b 50M -t 3 | grep receiver
sudo ip netns exec r tc qdisc show dev eth2
sudo ip netns exec cli ethtool -i eth0 | head -1Expected:
[ 5] 0.00-3.00 sec 17.9 MBytes 50.0 Mbits/sec 0.009 ms 0/12946 (0%) receiver
qdisc noqueue 0: root refcnt 2
driver: veth
noqueue is the normal state of veth: no queue of its
own.
Save your progress? Sign up for free
Challenge
The examiner builds a bad link without saying which kind:
# on netz
sudo ip netns exec r tc qdisc add dev eth1 root netem delay 30ms loss 2%
clearA user in cli reports: “Uploading works great,
downloading is unbearably slow, and ping looks normal.” Use measurements
to find out what is going on, in which direction, and where. Only then
look with tc.
Hint: Measure both directions separately. And in mtr, do not look only at the router.
Solution
# on netz
sudo ip netns exec cli ping -c 50 -i 0.2 -q 10.90.2.20 | tail -2
sudo ip netns exec cli mtr -n -r -c 50 -i 0.2 10.90.2.20
sudo ip netns exec cli iperf3 -c 10.90.2.20 -t 5 | grep -E 'sender|receiver'
sudo ip netns exec cli iperf3 -c 10.90.2.20 -t 5 -R | grep -E 'sender|receiver'Expected:
50 packets transmitted, 50 received, 0% packet loss, time 9833ms
rtt min/avg/max/mdev = 30.137/30.293/32.196/0.321 ms
Start: 2026-11-24T00:32:22+0000
HOST: netz Loss% Snt Last Avg Best Wrst StDev
1.|-- 10.90.1.1 70.0% 50 30.3 30.3 30.3 30.4 0.0
2.|-- 10.90.2.20 2.0% 50 30.3 30.4 30.2 31.3 0.2
[ 5] 0.00-5.01 sec 570 MBytes 955 Mbits/sec 0 sender
[ 5] 0.00-5.04 sec 570 MBytes 949 Mbits/sec receiver
[ 5] 0.00-5.03 sec 3.75 MBytes 6.25 Mbits/sec 52 sender
[ 5] 0.00-5.00 sec 3.00 MBytes 5.03 Mbits/sec receiver
How to read it:
- Ping: 30 ms instead of 0.1 ms, already at hop 1. So
the delay sits between
cliandr. 50 pings without loss: at 2% that is luck; a ping test with few packets often misses small loss. - mtr: 70% at
ris the trap from Drill 6 (-i 0.2). The 2% at the target are real. - iperf3: Upload 955 Mbit/s, download 6 Mbit/s with
52 retransmits. The loss only hits the direction toward
cli. When uploading, only acknowledgments travel in that direction, and TCP copes with lost ACKs because every later ACK also acknowledges the earlier ones. When downloading, the data itself gets lost.
Only now the proof:
# on netz
sudo ip netns exec r tc qdisc show dev eth1
sudo ip netns exec r tc qdisc show dev eth2
sudo ip netns exec r tc qdisc del dev eth1 rootExpected:
qdisc netem 8006: root refcnt 3 limit 1000 delay 30ms loss 2%
qdisc noqueue 0: root refcnt 2
netem on eth1 of r, that is,
on the path to cli. In real life this is a link with
disturbances in one direction, such as Wi-Fi with weak reception at the
client or a DSL line with errors in the downstream.
Save your progress? Sign up for free
Checkpoint
# on netz
for d in eth1 eth2; do sudo ip netns exec r tc qdisc show dev $d; doneExpected:
qdisc noqueue 0: root refcnt 2
qdisc noqueue 0: root refcnt 2
# on netz
sudo ip netns exec srv ethtool -k eth0 | grep -E '^tcp-segmentation-offload'
sudo ip netns exec r sysctl -n net.ipv4.icmp_ratelimitExpected:
tcp-segmentation-offload: on
1000
Clean-up
# on netz
for p in $(pgrep -x iperf3); do sudo kill $p; done
sudo ip netns del r
sudo ip netns del cli
sudo ip netns del srv
rm -f /tmp/last.txt
ip netns list | wc -l
pgrep -a iperf3 || echo "keine Labor-Prozesse"
sysctl net.ipv4.ip_forwardExpected:
0
keine Labor-Prozesse
net.ipv4.ip_forward = 0
All tc rules disappear along with the namespaces.
Practice note
- Loss first, then delay, then bandwidth. Even 1%
loss slows TCP down more than any throttling.
mtr -r -c 100to the target andiperf3in both directions (-R) answer most “the network is slow” tickets. - mtr loss in the middle that disappears at the end is not loss. Routers rate-limit ICMP replies. Only loss that persists all the way to the target is real loss.
- A single connection is limited by window ÷ round-trip
time. On long distances, larger buffers
(
tcp_rmem/tcp_wmem) or several connections help, not a wider link. - tc netem belongs in every test environment. An application that still works with 50 ms delay and 1% loss will also survive your users’ mobile network. Without netem you only test it on a perfect link that does not exist out there.
- Fix bufferbloat at the bottleneck, with fq_codel or cake, and with throttling just below the real bandwidth, so the queue builds up at your own router and not in the provider’s modem.