basforge

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

    RU
    OverviewLinuxNetworking

    Networking in practice: from a wire frame to a browser response

    Every browser request or curl call crosses four real TCP/IP layers: a frame on the local network, an IP packet across routers, a TCP or UDP port for the target process, and an application protocol like DNS, TLS, or HTTP. See how layers wrap one another, why engineers say L2, L3, L4, and L7, where traffic breaks, and which Linux tools expose each step.

    What happens when you open a website

    A single curl https://example.org feels instant, yet before any HTML arrives your machine completes five distinct network operations — and traffic can fail at any one of them for a different reason.

    terminal · curl https://example.org

    1. DNSUDP :53The resolver translates example.org into an IP address — for example 203.0.113.10 (or IPv6 2001:db8::10).
    2. Route & ARPip route · L2The kernel checks the routing table: the address is remote, so the packet heads to gateway 10.0.10.1. ARP resolves that gateway’s MAC address.
    3. TCP handshakeSYN · SYN-ACK · ACKThe client opens a connection from an ephemeral port (such as 54322) to server port 443 in three packets.
    4. TLS & SNIClientHello · TLS 1.3Both sides negotiate encryption; the client sends example.org in the SNI field so the server picks the right certificate.
    5. HTTPGET / HTTP/2Inside the encrypted channel, the request goes out and 200 OK returns with the page body.

    HTTP 200 OK response from web server

    When a site fails to load, “the network is down” tells you nothing. Knowing this chain narrows every outage down to one question: at which of the five steps did the packet stop.

    Four TCP/IP layers and why engineers say L2, L3, L4, L7

    Textbooks often draw the 7-layer OSI model, yet the internet and the Linux kernel run the 4-layer TCP/IP stack. OSI session (L5) and presentation (L6) do not exist as separate layers in TCP/IP — applications and TLS handle their jobs. Still, OSI numbers stuck in daily engineering talk: “L2 switch”, “L3 router”, “L4 load balancer”, “L7 proxy”. Four working layers are all you need to keep in mind:

    Layer Short name Protocols Address Device / location Linux tools
    Link L2 Ethernet, Wi-Fi, ARP, VLAN MAC (52:54:00:…) NIC, switch, br-* bridge ip link, ip neigh
    Internet L3 IPv4, IPv6, ICMP IP (203.0.113.10) Router, routing table, NAT ip addr, ip route, mtr
    Transport L4 TCP, UDP Port (443, 53) Kernel sockets, nftables firewall ss, nc
    Application L7 DNS, TLS, HTTP, SSH Domain, URL, SNI App, browser, Traefik dig, curl -v, openssl

    Data hits the wire like nested envelopes: each layer wraps the block above it with its own header. That is encapsulation — a switch reads only L2, a router inspects up to L3, a firewall filters L3 and L4, and the web server receives clean HTTP.

    Frame on the wire · 1514 bytes (MTU 1500 + 14-byte Ethernet)Pick a layer
    Ethernet header (L2)Rewritten at every router
    Dst MAC · 6 B02:42:ac:11:00:01MAC of the next-hop gateway, not the final server
    Src MAC · 6 B52:54:00:1a:2b:3cMAC of the sender’s network interface
    EtherType · 2 B0x0800Payload type: 0x0800 IPv4, 0x0806 ARP, 0x86DD IPv6
    IPv4 header (L3)End-to-end (changed only by NAT)
    Src IP · 4 B10.0.10.42Sender; a router doing SNAT replaces this with its external IP
    Dst IP · 4 B203.0.113.10Final destination used for routing lookups
    TTL · 1 B64, 63, …Decremented by 1 at each router; at 0 the router sends ICMP Time Exceeded
    Protocol · 1 B6 (TCP)1 — ICMP, 6 — TCP, 17 — UDP
    TCP header (L4)Seen by sender and receiver
    Src / Dst Port · 4 B54322 > 443Client ephemeral port and HTTPS port on the server
    Seq / Ack · 8 Bseq 1 · ack 1Byte counters TCP uses to detect lost segments
    Flags · byte tcp[13]0x12 · [S.]SYN + ACK — server reply during handshake
    Window · 2 Bwin 65160Bytes the receiver is ready to accept without pausing
    Flag byte tcp[13] bit breakdown · 00010010 = 16 + 2 = 0x12 (SYN+ACK)
    CWR0128
    ECE064
    URG032
    ACK116
    PSH08
    RST04
    SYN12
    FIN01
    Payload (L7 · HTTPS)Encrypted by TLS (except SNI in ClientHello)
    MSS · max segment1460 bytesMTU 1500 minus 20-byte IPv4 and 20-byte TCP headers
    Visible in tcpdumpTLSv1.3 ClientHelloHostname (SNI) is plaintext; HTTP headers and body are encrypted
    Frame Check Sequence (FCS / CRC32)Recalculated on every link

    The NIC verifies CRC32 in hardware and drops corrupted frames before the kernel sees them — which is why FCS rarely appears in tcpdump output.

    The core rule of packet travel: MAC addresses live only until the next router, while IP addresses travel from source to final destination (unless NAT rewrites them). When a router forwards a packet, it strips the old Ethernet header, decrements TTL by 1, and wraps the same IP packet in a new frame addressed to the next hop’s MAC.

    Five misconceptions that waste hours of debugging

    Shallow networking summaries leave behind bad habits. When debugging servers and containers, these five cost the most time:

    L3 vs. L4

    ping does not test websites or ports

    ping sends ICMP Echo (L3), which has no concept of ports. A server can answer ping while its web server is dead — or silently drop ICMP at the firewall while HTTPS on port 443 serves traffic fine.

    DROP vs. REJECT

    Timeouts and Connection refused have different causes

    When a client hangs for 20 seconds and times out, a firewall is silently dropping packets (DROP) or a route is missing. When it fails in milliseconds with Connection refused, the packet reached the server and the kernel returned RST: nothing listens on that port, or a rule used REJECT.

    L3 and conntrack

    NAT is not a firewall

    A home router ignores unsolicited inbound IPv4 packets because no matching conntrack entry exists — not as a security feature. Once IPv6 arrives without NAT, explicit firewall rules have to do that job (nftables).

    L4 mechanics

    TCP does not guarantee delivery

    Unplug the cable and no protocol can deliver a packet. TCP guarantees something else: using seq and ack numbers, it detects loss, retransmits, reorders chunks, and reports a broken connection to the application if replies stop coming.

    Linux kernel

    tcpdump sees inbound traffic before the firewall

    On inbound traffic, AF_PACKET capture sits ahead of netfilter hooks. That is why tcpdump on the server shows incoming SYN packets that never reach nginx or a container: ufw or nftables drops them right after capture.

    Where traffic breaks: five common failures

    Almost any server or home-network outage falls into one of the five scenarios below. Switch between them to see where packets stop, what tcpdump prints, and which command to run first:

    1. Client✓ SYN >
    2. Router / NAT✓ SNAT
    3. nftables✓ accept :443
    4. Server :443✓ < SYN-ACK
    00.000 IP 10.0.10.42.54322 > 203.0.113.10.443: Flags [S], seq 104928171, length 0
    00.018 IP 203.0.113.10.443 > 10.0.10.42.54322: Flags [S.], seq 391820411, ack 104928172, length 0
    00.018 IP 10.0.10.42.54322 > 203.0.113.10.443: Flags [.], ack 1, length 0
    What happened

    The three-way handshake finished in 18 ms — the connection entered ESTABLISHED, followed by TLS ClientHello.

    Check with

    ss -tn state established '( dport = :443 )'

    1. Client✓ SYN > (×3)
    2. Router / NAT✓ forwarded
    3. nftables / ufw✕ DROP (silent)
    00.000 IP 10.0.10.42.54322 > 203.0.113.10.443: Flags [S], seq 104928171, length 0
    01.012 IP 10.0.10.42.54322 > 203.0.113.10.443: Flags [S], seq 104928171, length 0
    03.044 IP 10.0.10.42.54322 > 203.0.113.10.443: Flags [S], seq 104928171, length 0
    Cause

    The firewall silently dropped packets (policy drop), so the client retries SYN at 1 s, 2 s, and 4 s. On the server itself, tcpdump still prints those SYN packets because capture happens before the firewall.

    Check with

    sudo nft list ruleset | grep -E 'dport 443|policy drop'

    1. Client✓ SYN >
    2. Router / NAT✓ forwarded
    3. nftables✓ allowed
    4. Server kernel✕ < RST (no listener)
    00.000 IP 10.0.10.42.54322 > 203.0.113.10.8080: Flags [S], seq 104928171, length 0
    00.017 IP 203.0.113.10.8080 > 10.0.10.42.54322: Flags [R.], seq 0, ack 104928172, length 0
    Cause

    The packet reached the server, yet nothing is listening on port 8080 (or the service listens only on 127.0.0.1), or a firewall rule uses reject. The client gets Connection refused immediately.

    Check with

    sudo ss -tulnp | grep 8080

    1. Client✓ TCP + small packets
    2. Tunnel (MTU 1420)✕ 1500 B packet + DF
    00.018 IP 203.0.113.10.443 > 10.0.10.42.54322: Flags [S.], options [mss 1460]
    00.021 IP 10.0.10.42.54322 > 203.0.113.10.443: Flags [P.], length 1448
    00.425 IP 10.0.10.42.54322 > 203.0.113.10.443: Flags [P.], length 1448
    Cause

    The short handshake gets through, while the first full 1500-byte packet does not fit inside VPN/PPPoE; the ICMP Fragmentation Needed reply is dropped, leaving the connection stuck retransmitting.

    Check with

    ping -M do -s 1472 203.0.113.10

    1. Client✓ A? example.org
    2. Resolver :53✕ SERVFAIL / empty
    00.000 IP 10.0.10.42.49102 > 10.0.10.1.53: 4821+ A? example.org. (29)
    00.042 IP 10.0.10.1.53 > 10.0.10.42.49102: 4821 ServFail 0/0/0 (29)
    Cause

    TCP never started: the resolver returned SERVFAIL (broken DNSSEC or unresponsive upstream) or NXDOMAIN (the domain does not exist).

    Check with

    dig +trace example.org and dig @1.1.1.1 example.org

    Tools for inspecting networking on Linux

    Older guides still reference ifconfig, netstat, route, and arp from net-tools. Modern Linux distributions replaced them with iproute2 (ip and ss), which talks directly to the kernel over Netlink and handles network namespaces (netns), IPv6, and Docker containers accurately.

    Layer What it shows When to use it
    ip (iproute2) L2, L3 Interfaces, addresses, ARP table (ip neigh), routes (ip route get) First check: is the link up, what is the IP, and where will a packet go
    ss (iproute2) L4 Open sockets, listening processes (-tulnp), TCP states Check what listens on a port and on which address (0.0.0.0 vs. 127.0.0.1)
    mtr / ping L3 Reachability, packet loss, and latency at every hop along the path Locate which router drops packets or adds latency
    dig L7 (DNS) A/AAAA/CNAME/TXT records, cache TTL, +trace delegation path Verify name resolution and compare your resolver against 1.1.1.1
    curl -v L4, L7 TCP connect, TLS handshake, certificate, SNI, and HTTP headers Debug web services, Traefik proxies, redirects, and certificates
    tcpdump L2–L7 Live packets on an interface and .pcap captures for Wireshark When logs stay silent: see every SYN, RST, retransmission, and DNS reply
    If… Run
    you are unsure where the kernel will route a packet to 203.0.113.10 ip route get 203.0.113.10
    a browser or curl gets Connection refused sudo ss -tulnp on the server
    a domain fails to load while the IP responds dig example.org and dig @1.1.1.1 example.org
    a site behind Traefik returns the wrong certificate or 502 curl -vkI https://example.org
    packets vanish and application logs are empty sudo tcpdump -nn -i any and save to .pcap

    How this section is organized and where to start

    The section is split into five parts from the bottom layer up — from wire frames to the Linux network stack. The full map of chapters and cheat sheets lives in the Networking section:

    • New to networking — follow the chapters in order starting with part one: each chapter opens with live command output or a failure trace, explains the mechanism, and reinforces it with a short check.
    • Already comfortable with the basics — jump straight to the chapter you need (such as NAT and conntrack, ICMP and MTU, IPv6, or Linux netns and veth), or go directly to the tcpdump topic for packet capture and analysis.

    Related topics on this site build on these fundamentals: kernel firewalls in nftables and The ufw firewall, container networking in Docker networks and Docker subnet clashes with home network, home routers in MikroTik and Wired on MikroTik, and reverse proxies with TLS in Traefik.

    If it doesn’t work

    ping 203.0.113.10 succeeds, while the website or SSH on the same server fails to open

    Cause
    ping sends ICMP Echo and knows nothing about TCP ports. The server is reachable over IP, while the target port is blocked by a firewall or the service is not running.
    Fix
    Test the specific port with nc -zv -w 3 203.0.113.10 443 or curl -vk https://example.org. On the server, check what listens on that port with sudo ss -tulnp.

    A connection hangs for 10–30 seconds and fails with Connection timed out, even though the port is open on the server

    Cause
    A firewall silently drops SYN packets (DROP), or the return route is missing. The client retries SYN with exponential backoff until it times out.
    Fix
    Inspect firewall rules (sudo nft list ruleset) and routing (ip route get 203.0.113.10). In tcpdump -nn, you will see repeated Flags [S] packets with no reply.

    Instant Connection refused right after running the command

    Cause
    The packet reached the server, and the kernel replied with RST: nothing is listening on that port and address (often the service is bound only to 127.0.0.1), or a firewall rule uses REJECT.
    Fix
    Run sudo ss -tulnp | grep :8080 on the server and confirm the bind address is 0.0.0.0 (or ::), not 127.0.0.1.

    tcpdump on the server shows incoming packets, while nginx, Traefik, or app logs stay empty

    Cause
    tcpdump captures incoming traffic via AF_PACKET before netfilter hooks run. The packet lands in the capture and is dropped a moment later by ufw or nftables.
    Fix
    Check the input and forward chains in sudo nft list ruleset along with drop counters. For Docker containers, inspect forward as well (nftables).

    SSH connects and accepts short commands, then freezes completely after ls -la or a file transfer

    Cause
    An MTU black hole: small packets (SYN, short keystrokes) fit through a VPN or PPPoE link with a smaller MTU, while full 1500-byte frames get dropped because ICMP Fragmentation Needed is blocked.
    Fix
    Find the largest non-fragmented payload with ping -M do -s 1472 203.0.113.10, lowering the size until replies arrive. Allow the required ICMP types or enable MSS clamping on the router.

    curl: (6) Could not resolve host or Temporary failure in name resolution, while ping 1.1.1.1 works

    Cause
    IP routing to the internet works, while DNS is broken: the resolver is unreachable, systemd-resolved is misconfigured, or the domain has no A/AAAA record.
    Fix
    Compare the system resolver against a public one: dig example.org vs. dig @1.1.1.1 example.org. On Ubuntu, check system DNS status with resolvectl status.