Skip to content
Linux networking · Chapter 10 of 20 Day 8: MTU, fragmentation and VXLAN

Day 8: MTU, fragmentation and VXLAN

Goal: Know and measure the MTU of every segment, watch Path MTU Discovery at work, create an MTU black hole and fix it with MSS clamping. And build a VXLAN overlay that, without a matching MTU, is fifteen times slower than necessary · Duration: approx. 90 min · Prerequisite: Days 4 and 7

Briefing

  • The MTU (maximum transmission unit) is the largest IP packet an interface sends in one piece, usually 1500 bytes on Ethernet. On the way through the network, the smallest MTU of all segments counts, the path MTU.
  • If a packet is too large, there are two options: the router splits it (fragmentation), or it throws it away and reports via ICMP “too big, only 1400 fits”. TCP uses the second option, and for that the packet carries the DF bit (Don’t Fragment). That is Path MTU Discovery.
  • Tunnels and overlays such as VXLAN pack packets into packets. Each wrapper costs space, 50 bytes for VXLAN. Forget that and you get fragments or lost packets.
 ┌─────┐ 10.80.1.0/24 ┌────┐ 10.80.12.0/24 ┌────┐ 10.80.2.0/24 ┌─────┐
 │ cli ├──────────────┤ r1 ├───────────────┤ r2 ├──────────────┤ srv │
 │ .10 │  MTU 1500    │ .1 │   MTU 1400    │ .2 │  MTU 1500    │ .20 │
 └─────┘              └────┘  (the link)   └────┘              └─────┘
      vx0 192.168.100.1  ═════ VXLAN 100 across all ═════  vx0 192.168.100.2

The narrow segment between r1 and r2 stands for a WAN link, a VPN or a provider using PPPoE (1492 there). The ends see nothing of it: their own MTU is 1500.

Drill 1: Two routers, one narrow segment

# on netz
sudo ip netns add cli
sudo ip netns add r1
sudo ip netns add r2
sudo ip netns add srv
sudo ip -n cli link set lo up
sudo ip -n r1 link set lo up
sudo ip -n r2 link set lo up
sudo ip -n srv link set lo up
sudo ip -n r1 link add eth1 type veth peer name eth0 netns cli
sudo ip -n r1 link add eth2 type veth peer name eth2 netns r2
sudo ip -n r2 link add eth1 type veth peer name eth0 netns srv
sudo ip -n cli addr add 10.80.1.10/24 dev eth0
sudo ip -n r1 addr add 10.80.1.1/24 dev eth1
sudo ip -n r1 addr add 10.80.12.1/24 dev eth2
sudo ip -n r2 addr add 10.80.12.2/24 dev eth2
sudo ip -n r2 addr add 10.80.2.1/24 dev eth1
sudo ip -n srv addr add 10.80.2.20/24 dev eth0
sudo ip -n r1 link set eth2 mtu 1400
sudo ip -n r2 link set eth2 mtu 1400
sudo ip -n cli link set eth0 up
sudo ip -n r1 link set eth1 up
sudo ip -n r1 link set eth2 up
sudo ip -n r2 link set eth2 up
sudo ip -n r2 link set eth1 up
sudo ip -n srv link set eth0 up
sudo ip -n cli route add default via 10.80.1.1
sudo ip -n srv route add default via 10.80.2.1
sudo ip -n r1 route add 10.80.2.0/24 via 10.80.12.2
sudo ip -n r2 route add 10.80.1.0/24 via 10.80.12.1
sudo ip netns exec r1 sysctl -qw net.ipv4.ip_forward=1
sudo ip netns exec r2 sysctl -qw net.ipv4.ip_forward=1
sudo ip netns exec cli ping -c1 -W1 10.80.2.20 | grep -o '1 received'

Expected: 1 received

The MTU of all interfaces at a glance:

# on netz
for n in cli r1 r2 srv; do echo "$n: $(sudo ip -n $n -o link show | grep -v ' lo:' | grep -o 'eth[0-9]@[a-z0-9]*.*mtu [0-9]*' | sed -E 's/@[^ ]*.* mtu/ mtu/' | paste -sd, )"; done

Expected:

cli: eth0 mtu 1500
r1: eth1 mtu 1500,eth2 mtu 1400
r2: eth2 mtu 1400,eth1 mtu 1500
srv: eth0 mtu 1500

Both ends of a segment need the same MTU. If it is larger on one side, that side sends packets the other does not want to accept, and this only shows up with large packets.

Save your progress? Sign up for free

Drill 2: Finding the path MTU

ping -M do sets the DF bit, -s the payload size. Add 8 bytes of ICMP and 20 bytes of IP header: 1472 + 28 = 1500, exactly the MTU of cli.

# on netz
sudo ip netns exec cli ping -c1 -W1 -M do -s 1472 10.80.1.1 | grep received
sudo ip netns exec cli ping -c1 -W1 -M do -s 1473 10.80.1.1 2>&1 | grep -E 'received|error'

Expected:

1 packets transmitted, 1 received, 0% packet loss, time 0ms
ping: local error: message too long, mtu=1500
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

cli does not even send 1473: it knows its own MTU. Now to the server, behind the narrow segment, with a look at the routing table before and after:

# on netz
sudo ip netns exec cli ip route get 10.80.2.20
sudo ip netns exec cli ping -c2 -W1 -M do -s 1472 10.80.2.20 2>&1 | grep -vE '^PING|^$|rtt|statistics'
sudo ip netns exec cli ip route get 10.80.2.20

Expected:

10.80.2.20 via 10.80.1.1 dev eth0 src 10.80.1.10 uid 0
    cache
From 10.80.1.1 icmp_seq=1 Frag needed and DF set (mtu = 1400)
ping: local error: message too long, mtu=1400
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1017ms
10.80.2.20 via 10.80.1.1 dev eth0 src 10.80.1.10 uid 0
    cache expires 597sec mtu 1400

That is Path MTU Discovery in three lines:

  1. The first packet (1500 bytes, DF) gets as far as r1. It cannot send it over the 1400 segment, is not allowed to split it and reports back: Frag needed and DF set (mtu = 1400).
  2. cli remembers this for this destination, for ten minutes: cache expires 597sec mtu 1400.
  3. The second packet already fails locally, as with the gateway above.

The right size is 1400 − 28 = 1372:

# on netz
sudo ip netns exec cli ping -c1 -W1 -M do -s 1372 10.80.2.20 | grep -o '1 received'

Expected: 1 received

The ICMP message in the capture, after cli has forgotten its cache:

# on netz
sudo ip netns exec cli ip route flush cache
sudo ip netns exec r1 tcpdump -i eth1 -n -v -c 2 icmp 2>/dev/null &
sleep 1; sudo ip netns exec cli ping -c1 -W1 -M do -s 1472 10.80.2.20 >/dev/null 2>&1; wait

Expected:

00:23:01.614875 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 1500)
    10.80.1.10 > 10.80.2.20: ICMP echo request, id 13015, seq 1, length 1480
00:23:01.614921 IP (tos 0xc0, ttl 64, id 46273, offset 0, flags [none], proto ICMP (1), length 576)
    10.80.1.1 > 10.80.1.10: ICMP 10.80.2.20 unreachable - need to frag (mtu 1400), length 556
    IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 1500)
    10.80.1.10 > 10.80.2.20: ICMP echo request, id 13015, seq 1, length 1480

The ICMP message carries the beginning of the rejected packet, so the sender knows which connection is meant. Exactly this message must get through every firewall on the way back, otherwise Drill 4 breaks.

Save your progress? Sign up for free

Drill 3: Fragments

Without DF (-M dont) and with 2000 bytes of payload. Both ends first forget what they know about the path. In the capture on the narrow segment, only ID, offset and length matter:

# on netz
sudo ip netns exec cli ip route flush cache
sudo ip netns exec srv ip route flush cache
sudo ip netns exec r2 tcpdump -i eth2 -n -v -c 6 icmp 2>/dev/null | grep -o 'id [0-9]*, offset [0-9]*, flags \[[^]]*\], proto ICMP (1), length [0-9]*' &
sleep 1; sudo ip netns exec cli ping -c1 -W1 -M dont -s 2000 10.80.2.20 | grep 'bytes from'; wait

Expected:

2008 bytes from 10.80.2.20: icmp_seq=1 ttl=62 time=0.211 ms
id 53487, offset 0, flags [+], proto ICMP (1), length 1396
id 53487, offset 1376, flags [+], proto ICMP (1), length 124
id 53487, offset 1480, flags [none], proto ICMP (1), length 548
id 18886, offset 0, flags [+], proto ICMP (1), length 1396
id 18886, offset 1376, flags [+], proto ICMP (1), length 124
id 18886, offset 1480, flags [none], proto ICMP (1), length 548

One ping, three fragments per direction, and they are fragments of fragments: cli splits the 2028 bytes into 1500 + 548 (offset 0 and 1480). r1 splits the first piece again into 1396 + 124 for the 1400 segment. All carry the same id, flags [+] means “more follow”, the last one has [none]. Reassembly happens only at the receiver.

Fragmentation costs Why
CPU in the router every packet is copied and split
Reliability if one fragment is lost, the whole packet is lost
Firewalls only the first fragment has ports, the others can hardly be filtered

That is why TCP always sets DF and relies on Path MTU Discovery.

Save your progress? Sign up for free

Drill 4: The black hole

A web server with a large file:

# on netz
mkdir -p ~/mtu/web
head -c 3000000 /dev/urandom > ~/mtu/web/gross.bin
sudo ip netns exec srv sudo -u ubuntu python3 -m http.server 8080 --directory /home/ubuntu/mtu/web >/dev/null 2>&1 &
sleep 1
sudo ip netns exec srv ip route flush cache
sudo ip netns exec cli curl -s -o /dev/null -m 10 -w '%{http_code} %{size_download} Byte in %{time_total} s\n' http://10.80.2.20:8080/gross.bin
sudo ip netns exec srv ip route get 10.80.1.10

Expected:

200 3000000 Byte in 0.030973 s
10.80.1.10 via 10.80.2.1 dev eth0 src 10.80.2.20 uid 0
    cache expires 599sec mtu 1400

The server sent 1500-byte segments, r2 reported “only 1400 fits”, the server adapted, all within the first milliseconds. Now a colleague comes along with some “hardening”: r2 should no longer send ICMP error messages.

# on netz
sudo ip netns exec r2 nft add table ip wand
sudo ip netns exec r2 nft add chain ip wand raus '{ type filter hook output priority 0; }'
sudo ip netns exec r2 nft add rule ip wand raus icmp type destination-unreachable counter drop
sudo ip netns exec srv ip route flush cache
sudo ip netns exec cli curl -s -o /dev/null -m 10 -w '%{http_code} %{size_download} Byte in %{time_total} s\n' http://10.80.2.20:8080/gross.bin; echo "rc=$?"
sudo ip netns exec r2 nft list chain ip wand raus | grep counter
sudo ip netns exec cli curl -s -m 5 http://10.80.2.20:8080/ | head -c 40; echo

Expected:

200 0 Byte in 10.002906 s
rc=28
        icmp type destination-unreachable counter packets 8 bytes 4608 drop
<!DOCTYPE HTML>
<html lang="en">
<head>

The typical picture of an MTU black hole: connection setup works, small responses work (the directory listing, even the 200 status code of the large file), but as soon as full segments flow, everything stalls. The server sends 1500 bytes with DF, r2 throws them away and is no longer allowed to say so. The server repeats the same oversized segments until curl gives up after 10 seconds. The eight dropped messages in the counter are the cries for help that never arrived.

Tried it: The ping from Drill 2 would not have shown this: ping without -M do and with the default size (84 bytes) always gets through. “Ping works, but the page does not load” is the classic phone call when the MTU is to blame.

The right fix is to allow ICMP “destination unreachable” again. If the firewall is not in your hands (it belongs to the provider or another team), MSS clamping helps: during connection setup, the router rewrites the maximum segment size (MSS) in the SYN to a value that fits through the narrow segment. Then neither end sends oversized segments:

# on netz
sudo ip netns exec r2 nft add chain ip wand weiter '{ type filter hook forward priority 0; }'
sudo ip netns exec r2 nft add rule ip wand weiter tcp flags syn tcp option maxseg size set rt mtu
sudo ip netns exec srv ip route flush cache
sudo ip netns exec cli curl -s -o /dev/null -m 10 -w '%{http_code} %{size_download} Byte in %{time_total} s\n' http://10.80.2.20:8080/gross.bin
sudo ip netns exec srv tcpdump -i eth0 -n -c 2 'tcp[tcpflags] & tcp-syn != 0' 2>/dev/null &
sleep 1; sudo ip netns exec cli curl -s -o /dev/null http://10.80.2.20:8080/; wait

Expected (truncated):

200 3000000 Byte in 0.019842 s
00:23:59.407709 IP 10.80.1.10.38782 > 10.80.2.20.8080: Flags [S], seq 306391493, win 64240, options [mss 1360,sackOK,TS val 2797665120 ecr 0
00:23:59.407751 IP 10.80.2.20.8080 > 10.80.1.10.38782: Flags [S.], seq 3740991851, ack 306391494, win 65160, options [mss 1460,sackOK,TS val

The client sent mss 1460, the server receives mss 1360: 1400 − 40 bytes for the IP and TCP headers. rt mtu takes the smallest MTU of the routes to the destination and back to the sender, here the 1400 segment. The server never sends more than 1360 bytes per segment, and the black hole is bypassed even though the ICMP messages are still being dropped.

MSS clamping only helps TCP. UDP (DNS with large responses, QUIC, VXLAN in Drill 5) stays in the black hole. Correcting the firewall rule therefore remains the real fix:

# on netz
sudo ip netns exec r2 nft delete table ip wand

Save your progress? Sign up for free

Drill 5: VXLAN

VXLAN lays a virtual Ethernet over a routed network: every Ethernet frame is packed into a UDP packet to port 4789 and sent to the other end. Two hosts in different networks then see each other as if they were attached to the same switch. Kubernetes networks such as Flannel and Cilium do this millions of times.

# on netz
sudo ip -n cli link add vx0 type vxlan id 100 local 10.80.1.10 remote 10.80.2.20 dstport 4789 dev eth0
sudo ip -n srv link add vx0 type vxlan id 100 local 10.80.2.20 remote 10.80.1.10 dstport 4789 dev eth0
sudo ip -n cli addr add 192.168.100.1/24 dev vx0
sudo ip -n srv addr add 192.168.100.2/24 dev vx0
sudo ip -n cli link set vx0 up
sudo ip -n srv link set vx0 up
sudo ip -n cli -d link show vx0 | head -3
sudo ip netns exec cli ping -c1 -W1 192.168.100.2 | grep -o '1 received'

Expected (truncated):

info: Using default fan map value (33)
3: vx0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether f2:8f:19:47:f7:f5 brd ff:ff:ff:ff:ff:ff promiscuity 0  allmulti 0 minmtu 68 maxmtu 65535
    vxlan id 100 remote 10.80.2.20 local 10.80.1.10 dev eth0 srcport 0 0 dstport 4789 ttl auto ageing 300 udpcsum noudp6zerocsumtx noudp6zerocsumrx addrgenmode
1 received

Tried it: The line info: Using default fan map value (33) comes from an Ubuntu extension in iproute2 (for “Fan Networking”) and appears for every VXLAN device. It is harmless.

The kernel itself set vx0 to MTU 1450: 1500 from eth0 minus 50 bytes of wrapper (14 bytes inner Ethernet, 8 VXLAN, 8 UDP, 20 IP). In the router you see both layers:

# on netz
sleep 2
sudo ip netns exec r1 tcpdump -i eth2 -n -c 2 udp port 4789 2>/dev/null &
sleep 1; sudo ip netns exec cli ping -c1 -W1 -q 192.168.100.2 >/dev/null; wait

Expected:

00:24:32.272122 IP 10.80.1.10.60521 > 10.80.2.20.4789: VXLAN, flags [I] (0x08), vni 100
IP 192.168.100.1 > 192.168.100.2: ICMP echo request, id 13452, seq 1, length 64
00:24:32.272301 IP 10.80.2.20.60521 > 10.80.1.10.4789: VXLAN, flags [I] (0x08), vni 100
IP 192.168.100.2 > 192.168.100.1: ICMP echo reply, id 13452, seq 1, length 64

Outside, UDP between the real addresses, inside, the ping between the overlay addresses, and vni 100 is the number of the virtual network. The routers see only UDP, the overlay is invisible to them.

Save your progress? Sign up for free

Drill 6: VXLAN and the MTU

1450 is correct if the whole path handles 1500. Here the 1400 segment lies in between. A ping with the full overlay MTU and DF:

# on netz
sudo ip netns exec cli ping -c1 -W1 -M do -s 1422 192.168.100.2 2>&1 | grep -E 'received|error'
sudo ip netns exec r1 tcpdump -i eth2 -n -v -c 2 udp port 4789 or 'ip[6:2] & 0x1fff != 0' 2>/dev/null | grep -o 'id [0-9]*, offset [0-9]*, flags \[[^]]*\], proto UDP (17), length [0-9]*' &
sleep 1; sudo ip netns exec cli ping -c1 -W1 -q -M do -s 1422 192.168.100.2 >/dev/null; wait

Expected:

1 packets transmitted, 1 received, 0% packet loss, time 0ms
id 19546, offset 0, flags [none], proto UDP (17), length 106
id 19668, offset 0, flags [+], proto UDP (17), length 1396

The ping arrives, despite DF. The DF bit only applies to the inner packet. The outer UDP wrapper carries no DF, so r1 splits it for the 1400 segment (flags [+], 1396 bytes). The first line is a small overlay packet that happened to pass through. So it works, but what does it cost? iperf3 measures the throughput through the overlay, nstat counts in the router how many packets it had to split:

# on netz
sudo ip netns exec srv iperf3 -s -D -1
sleep 1
sudo ip netns exec r1 nstat -n
sudo ip netns exec cli iperf3 -c 192.168.100.2 -t 5 | grep -E 'sender|receiver'
sudo ip netns exec r1 nstat -z IpFragOKs IpFragCreates

Expected:

[  5]   0.00-5.00   sec   489 MBytes   820 Mbits/sec  391             sender
[  5]   0.00-5.00   sec   489 MBytes   821 Mbits/sec                  receiver
#kernel
IpFragOKs                       366941             0.0
IpFragCreates                   731635             0.0

r1 split 366,941 packets in five seconds, into 731,635 fragments, plus 391 retransmits. Now the overlay MTU matched to the segment: 1400 − 50 = 1350.

# on netz
sudo ip -n cli link set vx0 mtu 1350
sudo ip -n srv link set vx0 mtu 1350
sudo ip netns exec srv iperf3 -s -D -1
sleep 1
sudo ip netns exec r1 nstat -n
sudo ip netns exec cli iperf3 -c 192.168.100.2 -t 5 | grep -E 'sender|receiver'
sudo ip netns exec r1 nstat -z IpFragOKs IpFragCreates

Expected:

[  5]   0.00-5.00   sec  6.52 GBytes  11.2 Gbits/sec    0             sender
[  5]   0.00-5.00   sec  6.52 GBytes  11.2 Gbits/sec                  receiver
#kernel
IpFragOKs                       0                  0.0
IpFragCreates                   0                  0.0

From 821 Mbit/s to 11.2 Gbit/s, no fragments, no retransmits. A hundred bytes less MTU, 13 times the throughput. The absolute numbers only apply to veth in a VM (where fragmenting mainly costs CPU), but you will see the ratio this way or similarly on real hardware too.

Save your progress? Sign up for free

Exercise: Speed drills

  1. What MTU does eth2 in r1 have? Target time: 15 s
  2. Send the largest ping with DF that gets through from cli to srv. Target time: 30 s
  3. Which VNI and which destination port does vx0 in cli use? Target time: 30 s

Solution

# on netz
sudo ip -n r1 link show eth2 | grep -o 'mtu [0-9]*'
sudo ip netns exec cli ping -c1 -W1 -M do -s 1372 10.80.2.20 | grep -o '1 received'
sudo ip -n cli -d link show vx0 | grep -o 'vxlan id [0-9]*\|dstport [0-9]*'

Expected:

mtu 1400
1 received
info: Using default fan map value (33)
vxlan id 100
dstport 4789

Save your progress? Sign up for free

Challenge

A colleague asks: “What is the MTU of the path from cli to srv, and at which router does it get narrow?” You are to find out with a single command, without pings of growing size and without looking into the routers.

Hint: There is a tool that combines traceroute and Path MTU Discovery, and it does not need sudo.

Solution

# on netz
sudo ip netns exec cli ip route flush cache
sudo ip netns exec cli tracepath -n 10.80.2.20

Expected:

 1?: [LOCALHOST]                      pmtu 1500
 1:  10.80.1.1                                             0.207ms
 1:  10.80.1.1                                             0.062ms
 2:  10.80.1.1                                             0.034ms pmtu 1400
 2:  10.80.12.2                                            0.149ms
 3:  10.80.2.20                                            0.127ms reached
     Resume: pmtu 1400 hops 3 back 3

tracepath sends UDP packets with DF and increasing TTL. At hop 2, 10.80.1.1 (i.e., r1) reports pmtu 1400: the narrow segment lies behind it. The result is in the last line. In the namespace it only runs with sudo because of ip netns exec, on a normal host it works without. The ip route flush cache beforehand is necessary, otherwise cli already knows the 1400 from Drill 2 and reports it right at hop 1.

Save your progress? Sign up for free

Checkpoint

# on netz
sudo ip netns exec cli ip route get 10.80.2.20 | grep -o 'mtu [0-9]*'

Expected: mtu 1400

# on netz
sudo ip -n srv link show vx0 | grep -o 'mtu [0-9]*'

Expected: mtu 1350

# on netz
sudo ip netns exec r2 nft list ruleset | wc -l

Expected: 0

Clean-up

# on netz
pkill -u ubuntu -f '[h]ttp.server'
sudo ip netns del cli
sudo ip netns del r1
sudo ip netns del r2
sudo ip netns del srv
rm -rf ~/mtu
ip netns list | wc -l
pgrep -af '[h]ttp.server|[i]perf3' || echo "keine Labor-Prozesse"
sysctl net.ipv4.ip_forward

Expected:

0
keine Labor-Prozesse
net.ipv4.ip_forward = 0

The VXLAN devices disappear with their namespaces.

Practice note

  • “Ping works, but large downloads hang” means MTU. Check with ping -M do -s <MTU − 28> and tracepath. Most common causes: firewalls that block ICMP entirely, VPNs and PPPoE connections.
  • Never block ICMP “destination unreachable” (type 3, “packet too big” in IPv6). Without it, there is no Path MTU Discovery. In IPv6, routers do not fragment at all, so the message is mandatory there.
  • MSS clamping is the stopgap for TCP, standard on every VPN and PPPoE router (tcp option maxseg size set rt mtu). It does not rescue UDP.
  • Overlays need their own MTU. VXLAN costs 50 bytes, Geneve 50 and more, WireGuard 60 to 80. The overlay MTU depends on the smallest segment underneath, not on its own interface. Kubernetes networks usually set this automatically, as long as the node MTU is correct.

Contents

More