Networking Basics: DNS, TCP, TLS, HTTP
How a browser resolves a hostname, opens a TCP connection, negotiates TLS 1.3, and exchanges HTTP requests and responses.
TL;DR
Loading an https:// URL is a layered handoff: DNS resolves the hostname to an IP, TCP establishes a reliable byte stream with a 3-way handshake, TLS 1.3 authenticates the server and encrypts the channel in 1-RTT, and HTTP exchanges requests and responses inside that tunnel.
Intent
Trace every network layer between typing a URL in a browser and receiving an HTTP 200 OK response, so you can pinpoint whether a failure is DNS, TCP, TLS, or HTTP.
Problem
When a web request fails or feels slow, "the network is down" is rarely actionable. Without knowing which layer runs first—name resolution, transport connection, encryption handshake, or application framing—it is hard to tell a NXDOMAIN lookup failure apart from a blocked TCP port, an expired TLS certificate, or a 502 HTTP gateway error.
Solution
Each protocol solves one narrow job and hands off to the next:
- DNS (Domain Name System): The client asks a recursive resolver for the
A(IPv4) orAAAA(IPv6) record of the hostname. Cached results are reused until their TTL expires. - TCP (RFC 9293): The client opens a socket to the resolved IP on port
443using the 3-way handshake (SYN→SYN-ACK→ACK), establishing sequence numbers for ordered, retransmitted byte delivery. - TLS 1.3 (RFC 8446): Inside the TCP stream,
ClientHelloandServerHellonegotiate a cipher suite and Diffie-Hellman key share in 1-RTT, verify the server's X.509 certificate chain, and derive symmetric session keys. - HTTP (RFC 9110): Once the TLS record layer is open, the browser sends an HTTP request (
GET / HTTP/1.1or HTTP/2HEADERSframe) and the server returns status code, headers, and body back down the same TLS and TCP stack.
Real-world analogy
▶ Flow: watch it work
HTTPS Request Lifecycle: DNS → TCP → TLS 1.3 → HTTP
Press Start or tap any step dot to trace the path.
▸All steps (8)
Code
You can observe each stage directly with curl -v (verbose output prints DNS resolution, TCP connect, TLS handshake, and HTTP headers):
# Inspect DNS, TCP connect, TLS 1.3 negotiation, and HTTP response headers (not run)
curl -vI --tlsv1.3 https://example.comWhen to use / when to avoid
- You are debugging latency or connection failures and need to isolate DNS, TCP, TLS, or HTTP.
- You want to understand why connection reuse (HTTP keep-alive, HTTP/2 multiplexing) saves multiple round trips.
- You are configuring load balancers, reverse proxies, or Kubernetes Ingress TLS termination.
- You only need to check application-level JSON payloads; browser DevTools Network tab or curl -s is enough.
- You are working inside a local Unix domain socket where DNS and TCP do not apply.
How to implement
Check DNS resolution first
Verify the hostname resolves to the expected IP (dig +short example.com or nslookup example.com).
Verify TCP reachability
Confirm the target IP and port (443) accept connections without firewall drops.
Inspect TLS certificate and version
Check that the server presents a valid certificate chain and negotiates TLS 1.2 or TLS 1.3.
Read the HTTP status and headers
Inspect the HTTP status code, Cache-Control, and Content-Type returned by the origin.
Pros / Cons
- Clean separation of concerns: DNS, TCP, TLS, and HTTP evolve independently.
- TLS 1.3 cuts handshake latency to 1-RTT (and 0-RTT for resumed sessions with replay caveats).
- Standardized RFCs mean any compliant browser, CLI, or proxy interoperates.
- Cold connections pay sequential round trips (DNS + TCP + TLS) before the first HTTP byte.
- Head-of-line blocking in TCP delays all multiplexed HTTP/2 streams if one packet drops (why HTTP/3 uses QUIC over UDP).
Relations
Check yourself
Check Yourself
1. Which stage runs first when a browser has an empty cache and visits https://example.com?
2. How does TLS 1.3 improve handshake latency compared to TLS 1.2?
Sources
Related Notes
Git Internals: Objects, Branches, and Rebase vs Merge
Understand Git's content-addressable object store (blobs, trees, commits), lightweight refs, and how rebase replays commits onto a new base.
Linux Processes, Signals, and Exit Codes
How PID 1, SIGTERM, graceful shutdown, SIGKILL, exit codes 137 and 143, exec in entrypoints, and tini/--init keep container shutdowns clean.