Series23 partsВиталий Лещенко

Networking for beginners

Networking for beginners

A series for those who write software, run servers or simply want to understand what happens between pressing Enter in the address bar and the page appearing.

The series has one principle: for every protocol, not only why it is needed but how it works. Which bytes go over the wire, who answers them, what happens when something breaks. That is why almost every part has packet headers, commands and tcpdump output. To repeat the examples, any Linux machine (WSL will do) with tcpdump and Wireshark on your workstation is enough.

The order is bottom-up through the stack and then outwards: first the basics (the models, Ethernet, Wi-Fi and PPPoE), then IPv4 with ARP and ICMP, the UDP and TCP transports, the DHCP and DNS services, a separate block on IPv6 with Neighbor Discovery, SLAAC and DHCPv6, then VLAN, VXLAN, IPsec with IKEv2, VPNs and proxies, routing with OSPF and BGP, and finally TLS with certificates.

  1. Part 1

    What are the OSI and TCP/IP models?

    OSI and TCP/IP layers in action

    OSI and TCP/IP are two models that describe the network stack as a set of layers: each layer solves one task, uses the layer below and prepends its own header to the data. OSI is a seven-layer scheme that serves as a common language, the one behind "L2", "L3" and "L7"; TCP/IP is a four-layer model of how networks are actually built. On the wire this gives a nesting doll of Ethernet → IP → TCP/UDP → data, and a "what's inside" field in every header — EtherType, Protocol, port — tells the receiver whom to hand the contents to.

  2. Part 2

    How does Ethernet work?

    Ethernet frame encapsulation

    Ethernet delivers data to a neighbour on the cable in frames: a 14-byte header — destination MAC, source MAC and the EtherType "what's inside" field — then 46–1500 bytes of data and a 4-byte CRC; a frame that fails it is silently dropped. A switch remembers which port it saw each source MAC behind, forwards a frame only to the destination's port and floods unknown and broadcast addresses to every port, never changing a byte of the frame. The 64-byte minimum is a legacy of the shared cable and CSMA/CD, which full duplex does without.

  3. Part 3

    How does Wi-Fi work?

    Wi-Fi laptop, access point and server

    Wi-Fi pretends to be Ethernet, but inside it is a shared half-duplex radio channel: one device transmits at a time, and a collision cannot be heard, so instead of CSMA/CD it uses CSMA/CA — listen to the air, back off a random time, send the frame, retransmit if no ACK arrives. An access point is a bridge between 802.11 frames and ordinary Ethernet. Joining takes scanning, authentication, association and the WPA2/WPA3 four-way handshake: the password never crosses the air, and traffic is encrypted with a PTK unique to each session.

  4. Part 4

    What is PPPoE and why is it used?

    PPPoE encapsulation

    PPPoE runs a PPP session — a two-party protocol with no addresses — over the ISP's shared Ethernet. The client finds an access concentrator with a broadcast PADI, gets a PADO, sends a PADR and receives a Session ID in the PADS; then frames with EtherType 0x8864 carry plain PPP: LCP agrees on the link, PAP or CHAP checks the username and password, IPCP hands out the address. The ISP gets authentication, accounting and session control through RADIUS; the subscriber gets an MTU of 1492, since the PPPoE and PPP headers take 8 bytes out of 1500.

  5. Part 5

    How do IPv4 addresses, masks and subnets work?

    IPv4 addresses and subnets

    An IPv4 address is a 32-bit number written as four dotted bytes, and the mask splits it into network and host parts: 192.168.1.10/24 and mask 255.255.255.0 are the same thing. The network address is address AND mask, broadcast is address OR the inverted mask, and a subnet has 2^(32 − prefix) − 2 hosts. Moving the boundary right splits a network into subnets, moving it left merges aligned blocks. Most importantly, a host applies its mask to the destination address to decide whether it is a neighbour or the packet goes to the default gateway.

  6. Part 6

    How do the IPv4 header, routing and NAT work?

    IPv4 routing and NAT

    The IPv4 header is 20 bytes: source and destination addresses, TTL, the Protocol field, the length, the fragmentation fields and a checksum of the header only. At every hop a router decrements TTL, picks the routing table row with the longest matching prefix and wraps the packet in a new frame for the next hop — statelessly, each packet an independent decision. NAT rewrites the source address and port to public ones, keeps a translation table and uses it to restore the address in replies, so inbound connections need port forwarding.

  7. Part 7

    How does ARP work?

    ARP on a shared LAN

    ARP translates a neighbour's IP address into the MAC address that an Ethernet frame needs. The host sends a broadcast request asking who has this IP address, the owner answers with a unicast frame giving its MAC, and the result is cached in the neighbour table (ip neigh), where an entry passes through REACHABLE → STALE → recheck → FAILED. ARP works only within a segment: for other networks the host asks for the gateway's MAC. The protocol has no checks, so anyone in the segment can claim to be the gateway — that is ARP spoofing.

  8. Part 8

    What is ICMP and how do ping and traceroute work?

    ICMP ping and traceroute

    ICMP is the protocol the network uses to tell a sender that delivery failed: a router or host drops the packet and sends back a message with a type and code (Destination Unreachable, Time Exceeded, Fragmentation Needed) that carries the original packet's header. ping sends an Echo Request and waits for an Echo Reply, measuring the round-trip time. traceroute sends probes with TTL starting at 1 and rising: every router where TTL reaches zero answers with Time Exceeded from its own address, and the path is assembled hop by hop.

  9. Part 9

    How does UDP work?

    UDP datagrams

    UDP delivers data not to a machine but to a process on it: an eight-byte header — source port, destination port, length and checksum — is prepended to the data, and the datagram is handed to IP. There is no connection: no handshake, no acknowledgements, no retransmissions, no ordering, a lost datagram is simply lost, but message boundaries are preserved and one socket receives all peers. That is why UDP is chosen where latency matters more than completeness or the application knows better what to do about a loss: DNS, DHCP, voice, QUIC.

  10. Part 10

    How does TCP work?

    TCP reliable stream

    TCP turns unreliable IP into a reliable byte stream in both directions: it numbers every byte, the receiver acknowledges with the number of the next byte it expects, and whatever is not acknowledged the sender retransmits — on the RTO timer or after three duplicate ACKs. A connection opens with the SYN, SYN+ACK, ACK handshake and closes with a FIN in each direction. Speed is limited by two windows: the receive window protects the receiver, the congestion window protects the network; it grows until a loss occurs and is then halved.

  11. Part 11

    How does DHCPv4 work?

    DHCPv4 DORA

    DHCP gives a machine with no address an address, mask, gateway and DNS in four messages over UDP 67/68 — DORA: the client broadcasts a DISCOVER from 0.0.0.0, the server offers an address in an OFFER, the client asks for it in a REQUEST, the server confirms with an ACK, and the parameters travel in options. The address is leased, and halfway through the lease the client renews it with a unicast request to its server. Across a router the request is forwarded by a relay agent, and the server picks the pool by its address in giaddr.

  12. Part 12

    How does DNS work?

    DNS name resolution

    DNS turns a name into an address through a distributed name tree cut into zones, each served by its own authoritative servers. The stub resolver in the OS sends the query to a recursive server, which walks the tree from the root servers through the com. servers to the example.com. servers, gets an authoritative answer and caches every step for the record's TTL. The message travels in UDP on port 53, and if the answer does not fit in the datagram it is repeated over TCP; the whole path can be walked by hand with dig +trace.

  13. Part 13

    How do IPv6 addresses and the header work?

    IPv6 addressing

    An IPv6 address is 128 bits written as eight colon-separated groups of hex digits: leading zeros are dropped and the longest run of zero groups becomes ::. The upper 64 bits are the network prefix (every local network is a /64), the lower 64 the interface identifier a host can generate itself; a link-local fe80:: exists before any configuration. The header is always 40 bytes with no checksum and no fragmentation fields: everything optional goes into a chain of extension headers linked by Next Header, and TTL became Hop Limit.

  14. Part 14

    What are ICMPv6 and Neighbor Discovery?

    ICMPv6 and Neighbor Discovery

    ICMPv6 is the protocol at Next Header 58 that in IPv6 does the job of ICMP, ARP and part of DHCP: errors such as Packet Too Big, ping, and the Neighbor Discovery messages. A neighbor is found with a Neighbor Solicitation to its solicited-node multicast group, answered by a Neighbor Advertisement; the router announces itself with Router Advertisements to ff02::1, and DAD checks that an address is free. All NDP messages carry Hop Limit 255, and ICMPv6 must never be filtered wholesale: without it a host finds neither neighbor nor router.

  15. Part 15

    How does SLAAC work?

    SLAAC self-configuration

    SLAAC builds an address without a server: the host takes the /64 prefix from a Router Advertisement with the A flag, makes up a 64-bit interface identifier itself, checks the address with DAD and starts working; no one keeps track of which address was given to whom. The identifier comes from the MAC via EUI-64, from a stable hash per RFC 7217, or at random for temporary addresses, which change once a day. An address has two lifetimes — preferred and valid — and every new RA refreshes them; the default gateway always comes from that same RA.

  16. Part 16

    How does DHCPv6 work?

    DHCPv6 addresses and prefixes

    DHCPv6 is a separate protocol over UDP 546/547: the client sends a Solicit from its link-local address to ff02::1:2, gets an Advertise, sends a Request and gets a Reply with an address inside an IA_NA; with Rapid Commit it takes two messages. The client is named by a DUID, not a MAC, starts only on the M or O flag in a Router Advertisement, and never gets a gateway — that comes from the RA. Its main role is prefix delegation: the subscriber's router asks for an IA_PD, gets a /56 from the provider and hands out a /64 to its networks.

  17. Part 17

    What is a VLAN and how does it work?

    Two VLANs on one switch

    A VLAN splits one switch and one cable into several independent networks, each of them a separate broadcast domain with its own IP subnet. The switch marks a frame with a four-byte 802.1Q tag carrying a 12-bit VLAN number (4094 in all) and floods broadcasts only to ports of the same VLAN. An access port belongs to one VLAN and hands the host untagged frames, a trunk carries many VLANs with tags, and traffic between VLANs goes only through a router or an L3 switch.

  18. Part 18

    What is VXLAN and why is it needed?

    VXLAN Ethernet tunnel

    VXLAN wraps an Ethernet frame in UDP (port 4789) with an 8-byte header and a 24-bit VNI: an L2 segment stretches across any IP network, with 16 million networks instead of VLAN's 4094. A VTEP sits on the border between overlay and underlay and learns which remote VTEP a MAC lives behind from traffic (flood-and-learn) or from a control plane — EVPN over BGP, or static entries from an orchestrator, as in Kubernetes. That gives clouds a network per customer and lets data centers move virtual machines between racks without changing addresses.

  19. Part 19

    How do IPsec and IKEv2 work?

    IPsec and IKEv2 tunnel

    IPsec encrypts and signs whole IP packets at the network layer, so any protocol is protected and applications know nothing about it: ESP adds an SPI, a sequence number and an integrity check, and in tunnel mode hides the original packet inside a new IP header. Each direction's keys live in a Security Association, and IKEv2 negotiates them: in IKE_SA_INIT the parties pick algorithms and do a Diffie-Hellman exchange, in IKE_AUTH they authenticate with a PSK, a certificate or EAP and create the first Child SA; behind NAT it all moves to UDP 4500.

  20. Part 20

    How do VPNs and proxies work?

    VPN tunnel and proxy

    A VPN is a tunnel at the network layer: after connecting, the system gets an interface like tun0 or wg0 and routes into it, so every application and any protocol over IP goes through it, and encryption is built in. A proxy is an intermediary at the transport or application layer: the application connects to it via HTTP CONNECT or SOCKS5 and asks it to reach the destination, so it works only where configured. A "VPN" in a browser extension is a proxy, and neither one is anonymity: all that changes is who sees your traffic.

  21. Part 21

    How does OSPF work?

    OSPF link-state routing

    OSPF is a link-state routing protocol for one network: each router describes only its own links in LSAs and floods them to everyone, so every router assembles the same map (the LSDB) and computes the shortest paths from itself with Dijkstra's algorithm. It finds neighbors with Hello packets to 224.0.0.5 directly in IP (protocol 89), a path's cost is the sum of the outgoing interface costs, and when a link fails a new LSA reaches everyone within seconds and paths are recomputed. Large networks are split into areas with a mandatory area 0.

  22. Part 22

    How does BGP work?

    BGP between autonomous systems

    BGP is the routing protocol between autonomous systems that the entire internet rests on: neighbors are configured by hand, the session runs over TCP on port 179, and instead of a map routers pass each other prefixes with attributes, the main one being AS_PATH, the list of ASes to the origin. The best path is chosen not by distance but by policy: LOCAL_PREF first, then AS_PATH length, MED and the remaining rules down the chain. eBGP between ASes adds its own number to the path and sets the next hop to itself; iBGP within an AS changes nothing.

  23. Part 23

    How do TLS and certificates work?

    TLS 1.3 and certificates

    TLS protects a single TCP connection: in one handshake round trip client and server exchange one-time Diffie-Hellman keys, obtain a shared secret, and everything after that is encrypted, certificate included. A certificate is a public key, the owner's names in the SAN and a CA's signature; the client builds the chain up to a root in its trust store and verifies the CertificateVerify signature, which only the owner of the private key can produce. That key only signs, so stealing it does not expose recorded traffic — that is forward secrecy.