Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Networking Cheatsheet

🌐 OSI Model

LayerNameUnitProtocolsDevices
7ApplicationDataHTTP, FTP, DNS, SMTP
6PresentationDataSSL/TLS, JPEG, ASCII
5SessionDataNetBIOS, RPC
4TransportSegmentTCP, UDP
3NetworkPacketIP, ICMP, ARPRouter
2Data LinkFrameEthernet, Wi-FiSwitch
1PhysicalBitsCables, RadioHub

🔄 TCP vs UDP

TCPUDP
ConnectionConnection-orientedConnectionless
ReliabilityGuaranteedBest-effort
OrderingOrderedNo ordering
SpeedSlowerFaster
UseHTTP, FTP, emailDNS, gaming, streaming

🤝 TCP Handshake

Three-Way:
  Client → SYN → Server
  Client ← SYN-ACK ← Server
  Client → ACK → Server

Four-Way Termination:
  Client → FIN → Server
  Client ← ACK ← Server
  Client ← FIN ← Server
  Client → ACK → Server

🌍 DNS

Resolution: Client → Recursive Resolver → Root → TLD → Authoritative

Record Types:
A: Domain → IPv4
AAAA: Domain → IPv6
CNAME: Alias → Domain
MX: Domain → Mail server
NS: Domain → Name server
TXT: Text (SPF, verification)
PTR: IP → Domain (reverse)

🔐 HTTPS / TLS

TLS 1.3 Handshake (1-RTT):
  Client → ClientHello (cipher suites, key share)
  Server → ServerHello (chosen cipher, certificate, key share)
  Client verifies certificate → Encrypted session begins

TLS 1.3 vs 1.2:
  1-RTT vs 2-RTT, 0-RTT resumption, removed weak ciphers

📡 HTTP Versions

HTTP/1.1HTTP/2HTTP/3
ProtocolTCPTCPQUIC (UDP)
MultiplexingNoYesYes
Header CompressionNoHPACKQPACK
Server PushNoYesYes
TLSOptionalOftenBuilt-in

🔄 REST API

Methods: GET (read), POST (create), PUT (update full),
         PATCH (update partial), DELETE (delete)

Status Codes:
  2xx: Success (200 OK, 201 Created, 204 No Content)
  3xx: Redirect (301 Moved, 302 Found, 304 Not Modified)
  4xx: Client Error (400 Bad Request, 401 Unauthorized,
       403 Forbidden, 404 Not Found)
  5xx: Server Error (500 Internal, 502 Bad Gateway, 503 Unavailable)

⚖️ Load Balancing

L4 (Transport): Routes by IP+port, fast
L7 (Application): Routes by HTTP headers/URL, flexible

Algorithms:
  Round Robin: Rotate through servers
  Least Connections: Server with fewest connections
  IP Hash: Same client → same server (sticky)
  Weighted: More powerful servers get more traffic

🌐 WebSocket

Full-duplex, persistent connection over TCP
Upgrade from HTTP via handshake
Use: Real-time chat, gaming, live updates, notifications

vs HTTP:
  HTTP: Request → Response → Close
  WebSocket: Bidirectional, persistent

🍪 Cookies vs Sessions vs Tokens

Cookie: Client-side, sent with requests, size limit
Session: Server-side, identified by session ID
Token (JWT): Self-contained, stateless, includes claims

📋 URL Components

https://www.example.com:443/path/to/page?key=value#section
  |       |           |   |           |         |
protocol subdomain   port path       query    fragment

⚡ Quick Facts

  • NAT: Maps private → public IP (PAT uses ports)
  • ARP: Maps IP → MAC address
  • DHCP: Auto-assigns IP addresses
  • ICMP: ping (echo), traceroute (TTL exceeded)
  • CDN: Edge servers cache content closer to users
  • VPN: Encrypted tunnel over public internet
  • CORS: Browser security for cross-origin requests
  • gRPC: HTTP/2 + Protocol Buffers, fast internal APIs
  • GraphQL: Client-specified queries, single endpoint
  • SSL Pinning: Hardcode expected certificate (prevents MITM)

🔗 Cross-References