basforge

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

    RU

    Packets, layers, and encapsulation: frame, packet, segment, and MTU 1500

    Files do not travel over Ethernet or Wi-Fi as one continuous stream — the kernel slices data into chunks up to 1500 bytes (MTU) and wraps each layer’s headers around them: TCP, IP, and Ethernet. Break down a single tcpdump -e line, separate frames from packets and segments, calculate payload size (MSS 1460), and see why a router rewrites only the outer header.

    New hereEncapsulation and TCP/IP layers

    What you’ll get

    Check the maximum packet size on a Linux interface and capture one live frame with its link-layer header (-e):

    ip -o link show eth0
    # 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT qlen 1000\    link/ether 52:54:00:1a:2b:3c brd ff:ff:ff:ff:ff:ff
    
    sudo tcpdump -nn -e -i eth0 -c 1 'tcp and port 443'

    One line of tcpdump output exposes every layer in the frame — from the NIC’s MAC addresses down to TCP options:

    tcpdump -nn -e -i eth0 -c 1 · Pick a segment
    The two lengths on this line do not contradict each other: length 74 at the start is the whole wire frame, while length 0 at the end is the application payload inside TCP.

    Comparing those two numbers is the fastest way to grasp encapsulation: 74 bytes of protocol headers are already on the wire before the application sends a single byte of text.

    Why data is split into packets

    Sending a gigabyte file as one unbroken stream fails for three reasons:

    • Dozens of flows share one link. While a backup transfers, SSH keystrokes, DNS queries, and voice packets still slip through the same NIC and router without waiting for the backup to finish.
    • Corruption does not ruin the whole file. Wi-Fi interference or a full router queue damages one 1500-byte chunk. Only that chunk gets retransmitted, not the entire gigabyte.
    • Routers keep small buffers. Switch and router queues assume a fixed upper frame limit; without it, one sender would exhaust transit node memory.
    Calculate the packet size
    # Interface eth0: mtu 1500
    ping -M do -c 1 -s 1472 203.0.113.10   # succeeds
    ping -M do -c 1 -s 1473 203.0.113.10   # fails — why?
    Calculate the packet size
    Answer:
    ping: local error: message too long, mtu=1500

    MTU 1500 caps the entire IP packet, excluding the Ethernet header. An IPv4 header without options is 20 bytes, and an ICMP Echo header is 8 bytes. That leaves 1472 bytes for payload; -s 1473 produces a 1501-byte packet, and -M do prevents the kernel from fragmenting it.

    Frame, packet, segment: how the terms differ

    In casual speech everything gets called a “packet”, yet Linux docs, tcpdump, Wireshark, and RFCs give each layer’s data block (PDU) its own name:

    Layer Block name Typical header What’s inside Who reads the header
    L7 · Application Payload (data) Protocol-specific HTTP, TLS, DNS, SSH Client and server programs
    L4 · Transport Segment (TCP) / datagram (UDP) 20 bytes (TCP) / 8 bytes (UDP) Ports, seq/ack, flags Sender/receiver kernel, firewall
    L3 · Network Packet (IP packet) 20 bytes (IPv4) / 40 bytes (IPv6) Source/dest IP, TTL, protocol Every router along the route
    L2 · Link Frame (Ethernet frame) 14 bytes + 4-byte FCS MAC addresses, EtherType, optional VLAN (+4 B) NIC, switch, br-* bridge

    Here is the full byte budget of an Ethernet II frame carrying IPv4 and TCP:

    |<-------------- MTU 1500 bytes (IP packet size) -------------->|
    ┌──────────────┬───────────┬──────────┬──────────────────────────┬─────┐
    │ Ethernet 14B │ IPv4 20B  │ TCP 20B  │   Payload (MSS 1460 B)   │ FCS │
    │ MAC + Type   │ IP + TTL  │ ports    │   HTTP / TLS / SSH       │ 4 B │
    └──────────────┴───────────┴──────────┴──────────────────────────┴─────┘
    |<-------------------- 1518 bytes (full L2 frame) -------------------->|

    At physical layer L1, the NIC prepends an 8-byte Preamble + SFD and waits a 12-byte Interframe Gap before the next frame — 1538 bytes of wire time for 1460 bytes of application data (1460 / 1538 ≈ 94.9%). That produces the ~940 Mbps TCP ceiling on gigabit Ethernet; with TCP Timestamps enabled (+12 bytes in the TCP header, Linux’s default), payload shrinks to 1448 bytes.

    How layers change across a router

    When host 10.0.10.42 sends a request to 203.0.113.10, the kernel builds the frame top-down (encapsulation): data wraps in TCP, TCP in IPv4, IPv4 in Ethernet with the gateway’s MAC. An intermediate router performs partial decapsulation up to L3 and builds a fresh L2 header:

    What changes at a router (no NAT) · passing through an intermediate hopPick a layer
    Ethernet header is rewritten on every linkChanges at every router
    Router ingress52:54:… > 02:42:…Client MAC and router’s internal interface MAC
    Router egress02:42:… > aa:bb:…Router’s external interface MAC and ISP gateway MAC
    FCS checksumrecalculatedVerified by the inbound NIC, recomputed by the outbound NIC
    IP addresses stay unchanged; TTL drops by 1End-to-end (TTL −1)
    Src IP / Dst IP10.0.10.42 > 203.0.113.10A plain router without NAT leaves both untouched
    TTL64 > 63Loop guard: if it hits 0, the router drops the packet
    Header ChecksumrecalculatedUpdated along with TTL
    TCP header reaches the server unchangedUntouched by the router
    Ports54322 > 443Changed only by NAT/PAT or port forwarding
    Seq / Ack / FlagsunchangedA router without an L4 firewall does not even inspect this layer
    Only the endpoints see application dataEncrypted to the server

    Transit routers carry the payload as opaque bytes and cannot tell whether it is a web page, an SSH session, or a backup stream.

    That separation is why you can swap a LAN from copper to fiber or Wi-Fi without applications or TCP connections noticing: only the outer L2 envelope changes.

    What does a plain router without NAT change?
    Client (10.0.10.42) ──► Router (no NAT) ──► Server (203.0.113.10:443)
    What does a plain router without NAT change?
    Answer:
    L2: new Src/Dst MAC + FCS · L3: TTL = TTL - 1 + new IP checksum

    A switch (L2) forwards frames verbatim, not a router. A router without NAT leaves IP addresses and TCP untouched, yet always swaps MAC addresses for the next link and subtracts 1 from TTL.

    Where MTU 1500 comes from and where it shrinks

    1500 comes from the Ethernet II (IEEE 802.3) standard as the maximum frame payload. In practice it often shrinks because extra encapsulation layers stack on top of Ethernet — all carving space out of those same 1500 bytes:

    Link or tunnel Added overhead Resulting MTU TCP MSS (IPv4)
    Standard Ethernet (IPv4) 14 B Ethernet + 4 B FCS (outside MTU) 1500 1460
    Standard Ethernet (IPv6) 40-byte IPv6 header instead of 20 1500 1440
    VLAN 802.1Q (inside switch) +4-byte tag on the L2 header 1500 1460
    ISP PPPoE +8-byte PPPoE/PPP header inside the frame 1492 1452
    WireGuard over IPv4 +20 IPv4 + 8 UDP + 32 WireGuard (+ margin) 1420 1380
    Loopback lo No wire; transferred in kernel memory 65536 65495
    Jumbo frames (datacenter / SAN) Extended Ethernet frame 9000 8960

    Modern NICs and switches add the 4-byte 802.1Q VLAN tag on top of 1518 bytes (making a 1522-byte frame), so VLANs keep MTU 1500 intact. PPPoE and VPN tunnels sit inside the outer IP packet, directly reducing usable MTU. How hosts discover a smaller path MTU (Path MTU Discovery) is covered in the ICMP and MTU chapter.

    If it doesn’t work

    ping -M do -s 1473 203.0.113.10 fails immediately with ping: local error: message too long, mtu=1500

    Cause
    Out of a 1500-byte MTU, the IPv4 header takes 20 bytes and the ICMP header takes 8 bytes. That leaves 1472 bytes for payload; -M do forbids fragmenting the packet.
    Fix
    Use -s 1472 to test a full unfragmented Ethernet frame. If replies only succeed with a smaller size (such as 1464 or 1392), a PPPoE link or VPN tunnel sits on the path.

    tcpdump output omits MAC addresses and ethertype, starting directly with IP 10.0.10.42…

    Cause
    tcpdump hides the L2 header by default to keep output compact. Running with -i any also returns a Linux SLL pseudo-header instead of real Ethernet.
    Fix
    Add -e and specify an interface: sudo tcpdump -nn -e -i eth0 -c 1.

    Small requests and ping work over VPN or PPPoE, while web pages and file transfers stall

    Cause
    Tunnel encapsulation adds its own headers (8 bytes for PPPoE, 60 bytes for WireGuard over IPv4). When interface MTU stays at 1500 and ICMP Fragmentation Needed is blocked, large packets drop silently.
    Fix
    Measure the real path MTU with ping -M do -s …, set the matching MTU on the tunnel interface, or enable MSS clamping on the router.

    File copies over gigabit Ethernet top out around 940 Mbps instead of 1000

    Cause
    Part of the 1000 Mbps link rate goes to per-frame overhead: preamble, interframe gap, FCS checksum, and Ethernet, IPv4, and TCP headers.
    Fix
    That is the normal physical ceiling for Ethernet at MTU 1500 (1460 / 1538 ≈ 94.9%). Exceeding it requires jumbo frames (MTU 9000) inside a LAN where every switch supports them.