basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    ICMP and MTU: beyond ping, Path MTU Discovery, and MTU black holes

    ICMP is IP’s control and error-reporting protocol, well beyond ping: routers use it to report unreachable networks, expired TTL, and oversized packets (Fragmentation Needed). Covers key ICMP types, Path MTU Discovery, why blocking ICMP freezes SSH and TLS, and how nftables MSS clamping fixes it.

    Also in this chapterTip · MTU blackhole

    What you’ll get

    Send a full unfragmented packet (-M do -s 1472) from a host with MTU 1500 through router 10.0.10.1, which leads into a link with MTU 1400, and watch the Linux kernel discover the true path MTU:

    ping -M do -c 2 -W 1 -s 1472 10.0.20.10
    # PING 10.0.20.10 (10.0.20.10) 1472(1500) bytes of data.
    # From 10.0.10.1 icmp_seq=1 Frag needed and DF set (mtu = 1400)
    # ping: local error: message too long, mtu=1400
    
    ip route get 10.0.20.10
    # 10.0.20.10 via 10.0.10.1 dev eth0 src 10.0.10.10 uid 0
    #     cache expires 597sec mtu 1400
    
    tracepath -n 10.0.20.10
    #  1?: [LOCALHOST]                      pmtu 1500
    #  1:  10.0.10.1                                             0.041ms
    #  2:  10.0.10.1                                             0.010ms pmtu 1400
    #  2:  10.0.20.10                                            0.017ms reached
    #      Resume: pmtu 1400 hops 2 back 2

    The first packet reached the router and triggered an ICMP reply; the second packet was stopped locally by the kernel because it had already cached mtu 1400 for 10 minutes. Here is the router’s reply in tcpdump -nn:

    tcpdump -nn -i eth0 icmp · Pick a segment
    Without this packet, the client never learns about the smaller MTU past the router and keeps throwing 1500-byte packets into a void.

    ICMP message types: what runs over IP

    ICMP is an L3 control protocol (Protocol = 1 in the IPv4 header) with no port numbers. The ping utility uses only one pair of messages, while error messages keep the rest of the network working:

    Type / Code Name When sent Practical meaning
    8 / 0 Echo Request ping command L3 reachability probe
    0 / 0 Echo Reply Reply to ping Host is up and the return path to the client works
    3 / 0, 3 / 1 Net / Host Unreachable No route or no ARP reply Network has no route to the destination, or the neighbor is offline (MAC, switch, ARP, and VLAN)
    3 / 3 Port Unreachable Closed UDP port No process is listening on that UDP port (UDP counterpart to TCP RST)
    3 / 4 Fragmentation Needed Packet exceeds MTU with DF set Carries Next-Hop MTU — the basis of Path MTU Discovery
    3 / 13 Administratively Prohibited Firewall REJECT rule Packet was explicitly rejected by a firewall along the path
    11 / 0 Time Exceeded TTL hit 0 Routing-loop protection and the engine behind traceroute and mtr (Routing and LPM)

    Blocking all ICMP on a firewall is a common mistake. If a server should not respond to ping, block only inbound Type 8 (echo-request) and keep Type 3 and Type 11 open. In nftables, ICMP errors tied to existing connections pass automatically via ct state related accept (nftables).

    Path MTU Discovery and the MTU black hole

    On the modern internet, IPv4 packets almost always go out with the DF (Don’t Fragment) flag set: in-path fragmentation loads intermediate routers, breaks stateless filters, and loses an entire packet when a single fragment drops. In IPv6, intermediate fragmentation is forbidden by the standard.

    To let both endpoints learn the smallest MTU along the path — such as PPPoE 1492, WireGuard 1420, or IPSec 1400 (Packets and encapsulation) — hosts run Path MTU Discovery (PMTUD, RFC 1191):

    1. The client sends a 1500-byte packet with DF set.
    2. The router before the narrower link cannot forward it, drops it, and replies with ICMP Type 3 Code 4 carrying Next-Hop MTU (1400).
    3. The client kernel caches mtu 1400 in the route cache for 10 minutes and shrinks subsequent segments to fit.

    An MTU black hole happens when a firewall on the path silently drops ICMP Fragmentation Needed. The failure pattern is unmistakable: small packets (TCP SYN/SYN-ACK, login prompt, default 56-byte ping) stay under 1400 bytes and sail through, whereas the first full 1500-byte packet (TLS certificate, long ls -la output, HTTP body) vanishes at the router. The sender gets neither an error nor an ACK and keeps retransmitting until the session times out.

    1. Client (MTU 1500)✓ 1500 B + DF
    2. Router (MTU 1400)✓ < ICMP need to frag
    3. Client cache✓ stored mtu 1400
    4. Server✓ packets ≤ 1400 arrive
    18:55:48.084714 IP 10.0.10.10 > 10.0.20.10: ICMP echo request, id 4646, seq 1, length 1480
    18:55:48.084729 IP 10.0.10.1 > 10.0.10.10: ICMP 10.0.20.10 unreachable - need to frag (mtu 1400), length 556
    What happened

    The router reported the narrow link’s exact MTU; the client kernel cached mtu 1400 for 10 minutes and lowered packet size.

    Check with

    ip route get 10.0.20.10 and tracepath -n 10.0.20.10

    1. Client (MTU 1500)✓ SYN and small packets
    2. Router (MTU 1400)✕ 1500 B + DF dropped
    3. Firewall (ICMP)✕ dropped Type 3 Code 4
    # Short ping passes, full 1500 B packet vanishes silently:
    ping -M do -c 2 -W 1 -s 1472 10.0.20.10
    2 packets transmitted, 0 received, 100% packet loss
    Cause

    The Fragmentation Needed reply never reached the client: the kernel still assumes MTU 1500 and retries full-size packets endlessly.

    Check with

    ping -M do -c 1 -s 1372 10.0.20.10 (step -s down until it replies)

    1. Client✓ SYN [mss 1460]
    2. Router (nftables)✓ clamped mss to 1360
    3. Narrow link 1400✓ segments ≤ 1400 B
    4. Server✓ all 4096 B received
    18:55:52.963196 IP 10.0.10.10.49398 > 10.0.20.10.9001: Flags [S], options [mss 1360,sackOK,…], length 0
    18:55:52.963211 IP 10.0.20.10.9001 > 10.0.10.10.49398: Flags [S.], options [mss 1360,sackOK,…], length 0
    What happened

    The router lowered TCP MSS in SYN to 1360 (1400 − 40), so both peers send segments that fit the link even with ICMP blocked.

    Check with

    sudo nft list ruleset | grep maxseg

    Diagnostics and fixes: ping -M do, MSS clamping, and tcp_mtu_probing

    Find the real path MTU. In ping, -s sets only the ICMP payload size, so add 20 bytes for IPv4 and 8 bytes for the ICMP header (+28 bytes total):

    # Test standard Ethernet (1472 + 28 = 1500):
    ping -M do -c 1 -s 1472 10.0.20.10
    
    # If it silently drops, step down to common boundaries (1464 -> PPPoE 1492, 1392 -> WireGuard 1420, 1372 -> 1400):
    ping -M do -c 1 -s 1372 10.0.20.10
    # 1380 bytes from 10.0.20.10: icmp_seq=1 ttl=63 time=0.051 ms

    The tracepath -n <IP> command (preinstalled on Ubuntu) automates this probe and prints the hop where pmtu drops.

    How to fix it on your router and server:

    1. Keep required ICMP open. On every firewall you control, allow ct state related and destination-unreachable (frag-needed).

    2. Enable TCP MSS clamping on the router or VPN gateway. As SYN passes through, the kernel lowers TCP MSS to egress MTU − 40 (IPv4; − 60 for IPv6). In nftables, that is a single line in the forward chain:

      table ip filt {
        chain forward {
          type filter hook forward priority 0; policy accept;
          tcp flags syn tcp option maxseg size set rt mtu
        }
      }

      For a 1400-MTU link, this rewrites mss 1460 to mss 1360 before data transfer starts, so TCP works even if someone else’s firewall drops all ICMP.

    3. Turn on PLPMTUD on the Linux server itself. Ubuntu 24.04 ships with net.ipv4.tcp_mtu_probing = 0. When the black hole sits on an upstream network you cannot touch, setting it to 1 (RFC 4821) makes the server’s TCP stack probe smaller segment sizes automatically whenever a black hole is suspected.

    What is the largest `-s` value that passes through WireGuard (MTU 1420) without fragmentation?
    # Interface wg0: mtu 1420
    ping -M do -c 1 -s ??? 10.0.20.10
    What is the largest `-s` value that passes through WireGuard (MTU 1420) without fragmentation?
    Answer:
    ping -M do -c 1 -s 1392 -> packet is exactly 1420 bytes (1392 + 20 + 8)

    MTU 1420 caps the entire IP packet. A ping packet contains an IPv4 header (20 bytes) and an ICMP Echo header (8 bytes), with no TCP involved. That leaves exactly 1392 bytes for -s.

    Why does an MTU black hole let SSH log in, then freeze right after `ls -la /usr/bin`?
    ssh web1            # connects right away
    whoami              # prints: example-user
    ls -la /usr/bin     # session freezes completely
    Why does an MTU black hole let SSH log in, then freeze right after `ls -la /usr/bin`?
    Answer:
    Short packets (< 1400 B) pass · full 1500 B segment stalls in retransmits

    Connecting fine and hanging on the first big response is the classic signature of an MTU black hole. Small handshake packets and keystrokes fit through the link, whereas the first full 1500-byte frame gets silently dropped.

    If it doesn’t work

    SSH or HTTPS over VPN or PPPoE connects and accepts short commands, then freezes completely on ls -la or page load

    Cause
    MTU black hole: short packets (SYN, keystrokes) fit inside the tunnel MTU and go through, while the first full 1500-byte segment with the DF flag exceeds the link; the return ICMP Fragmentation Needed (type 3, code 4) is blocked by a firewall.
    Fix
    Measure the real path MTU with ping -M do -c 1 -s 1472 <IP> (lowering the size until you get a reply) or tracepath -n <IP>. Allow ct state related along with the required ICMP types and turn on MSS clamping on the router (tcp flags syn tcp option maxseg size set rt mtu).

    ping -M do -s 1472 10.0.20.10 returns Frag needed and DF set (mtu = 1400) the first time, then immediately prints local error: message too long, mtu=1400 on the second run

    Cause
    Normal Path MTU Discovery behavior: after the router’s first ICMP error, the Linux kernel cached mtu 1400 for that destination for 10 minutes and now rejects oversized packets before they even leave the interface.
    Fix
    Check the cache with ip route get 10.0.20.10 (cache expires … mtu 1400). After changing a tunnel’s MTU, clear the cache with sudo ip route flush cache.

    Blocked all ICMP on the firewall for stealth — and broke VPNs, large API responses, or mtr diagnostics

    Cause
    Dropping all ICMP cuts out Fragmentation Needed (type 3, code 4) and Time Exceeded (type 11) alongside ping (type 8). In IPv6, blocking all ICMPv6 takes the network offline altogether.
    Fix
    In nftables, keep ct state established,related accept (ICMP errors for active flows match related) and explicitly allow destination-unreachable, time-exceeded, and parameter-problem (nftables).

    ping -M do -c 1 -s 1472 to an external server loses 100% of packets, while -s 1464 succeeds with no loss

    Cause
    The ISP link uses PPPoE: its 8-byte header comes out of the 1500-byte Ethernet frame, leaving a real MTU of 1492 (1464 + 20 IPv4 + 8 ICMP = 1492).
    Fix
    That ceiling is normal for PPPoE: confirm the router’s WAN interface has MTU 1492 and MSS clamping enabled (1452 for IPv4) so 1500-MTU LAN devices do not stall.

    ping or tcpdump reports Port Unreachable or Communication Prohibited even though the traffic is not TCP

    Cause
    Different ICMP type 3 codes report the exact reason for refusal: code 3 (Port Unreachable) means a closed UDP port; code 13 (Communication Administratively Prohibited) means a firewall REJECT rule stopped the packet.
    Fix
    Inspect the error code in tcpdump -nn icmp: code 13 points to a firewall along the path, while code 1 (Host Unreachable) points to no ARP reply on the destination segment.

    Also in this chapter