Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 3 of 6 · Worked example · 20 min · revision 3

From a name to a response: DNS, TCP and HTTP in one trace

Trace an end-to-end network request from recursive DNS resolution through the TCP three-way handshake and TLS session setup to HTTP virtual hosting.

Contentsand lesson path

What you will learn

  • Explain how DNS resolution, a TCP connection and an HTTP request combine when a client calls a service by name.

01. Step 1: Translating Hostnames to IPs via DNS

When a client application executes curl https://api.example.com/v1/users, the operating system cannot send IP packets directly to the string api.example.com. The human-friendly hostname must first be resolved into a 32-bit IPv4 address (A record) or 128-bit IPv6 address (AAAA record) through the Domain Name System (DNS).

The resolution chain operates through five hierarchical stages:

  1. Stub Resolver: The local libc resolver follows the order in /etc/nsswitch.conf (typically the static /etc/hosts file first, then DNS servers from /etc/resolv.conf). It does not cache answers by itself; a local cache exists only if a service such as systemd-resolved, nscd or dnsmasq runs.
  2. Recursive Resolver: If uncached, the query is forwarded to a recursive resolver (such as cloud provider internal DNS, Google 8.8.8.8, or Cloudflare 1.1.1.1). The recursive resolver does the work of walking the DNS tree, one iterative query per level, and caches what it learns.
  3. Root Nameservers (.): Do not know the answer, but refer the resolver to the Top-Level Domain (TLD) nameservers responsible for the .com zone.
  4. TLD Nameservers (.com): Do not know the answer either. They reply with a referral: the NS records that name the authoritative nameservers for example.com, usually with their IP addresses (glue records).
  5. Authoritative Nameservers: The designated DNS servers holding the master zone records for example.com (e.g. AWS Route 53 or Cloudflare DNS), which return the target IP address accompanied by a Time-To-Live (TTL) value in seconds.

DNS Record Types and CNAME Chaining: In addition to direct A and AAAA address mappings, domain administrators utilize Canonical Name (CNAME) alias records to map subdomains (e.g. www.example.com to example.com or to an AWS CloudFront distribution domain). However, RFC 1034 says that a name with a CNAME record should hold no other data, and the zone apex (the root domain example.com) always holds SOA and NS records, so the apex cannot be a CNAME. DNS providers work around this with provider-specific ALIAS or ANAME records ("CNAME flattening"): the provider resolves the target name itself and answers with plain A and AAAA records.

DNS Caching and Negative TTL: Resolvers cache DNS answers for the duration specified by the record's TTL. If a record has a TTL of 43,200 seconds (12 hours), recursive resolvers across the world will serve the cached old IP for up to 12 hours, ignoring upstream changes until the TTL countdown expires. Failed lookups (NXDOMAIN) are cached too, for a time taken from the zone's Start of Authority (SOA) record (RFC 2308), so a name you have just created can keep failing for a while on resolvers that asked before it existed.

Bash · Tracing DNS resolution and querying specific record types with dig
# Query A record for domain with authoritative response metadata
dig api.example.com A

# Trace hierarchical resolution path from root servers down to domain
dig +trace api.example.com

# Query specific resolver directly with compact output format
dig @1.1.1.1 api.example.com +short

02. Steps 2 & 3: The TCP Three-Way Handshake and TLS Negotiation

Armed with the resolved IP address, the client initiates a reliable transport channel by opening a TCP connection to destination port 443 via the TCP Three-Way Handshake (RFC 9293, which replaced RFC 793 in 2022):

  • SYN (Synchronize): The client transmits a TCP packet with the SYN control flag set and a random initial sequence number; call it x.
  • SYN-ACK (Synchronize-Acknowledge): The server allocates transmission control blocks in memory and replies with both SYN (with its own random sequence number, y) and ACK (acknowledging x + 1).
  • ACK (Acknowledge): The client acknowledges y + 1. The connection enters the ESTABLISHED state, and data payload transmission can begin.

If the protocol is HTTPS, the endpoints immediately execute the Transport Layer Security (TLS 1.3) cryptographic handshake over this established TCP connection:

  1. ClientHello: The client sends the TLS versions and cipher suites it supports, the exact host name it wants in the Server Name Indication (SNI) extension, and one or more key shares, its half of the key exchange. Current major browsers, and OpenSSL 3.5 and later by default, offer the hybrid group X25519MLKEM768, which combines classic elliptic-curve Diffie-Hellman (X25519) with the post-quantum algorithm ML-KEM-768 (standardised for TLS in RFC 10024, 2026), together with plain X25519 for servers that do not support the hybrid yet.
  2. ServerHello and Certificate: The server picks a cipher suite and one key-exchange group and returns its own key share. From the two shares, both sides derive handshake keys, so everything after the ServerHello is already encrypted: the server sends its X.509 certificate chain, a CertificateVerify signature that proves it holds the certificate's private key, and its Finished message.
  3. Finished: The client checks the certificate chain and the signature and sends its own Finished message. Both parties then use symmetric session keys (AES-GCM or ChaCha20-Poly1305) to encrypt all application data on the wire. In TLS 1.3, this entire handshake requires only a single round-trip time (1-RTT) before the client can send its HTTP request, compared to the two round trips required by legacy TLS 1.2.

03. Step 4: HTTP Request Formatting and Virtual Hosting

Once the encrypted TLS tunnel is operational, the client constructs and transmits the plain HTTP application request payload containing method, URI path, headers, and optional body.

Why the Host Header is Essential: Multiple websites (e.g. api.example.com and shop.example.com) often resolve to the exact same server IP address. When the web server (Nginx, Caddy, or Apache) accepts the connection, it examines the HTTP Host header to route the request to the correct server_name virtual host configuration block. If a client connects by raw IP address, HTTP/1.1 still sends a Host header, but it carries that IP (curl http://172.31.8.40/ sends Host: 172.31.8.40). That value matches no server_name, so the server falls back to its default catch-all virtual host.

HTTP · Standard GET request with Host header and content negotiation
GET /v1/users HTTP/1.1
Host: api.example.com
User-Agent: curl/8.5.0
Accept: application/json
Connection: keep-alive
Bash · Capturing full DNS, TCP, TLS, and HTTP trace with curl -v
# Execute complete verbose trace showing all four stages sequentially
curl -v https://httpbin.org/get

# Override Host header to test virtual hosting against specific IP
curl -H "Host: custom.internal" http://127.0.0.1:8080/health

04. Check your understanding

Practice check · 3 questions

DNS hierarchy, TCP handshake sequence, and Host header check

Three questions on DNS caching, the handshake and keepalive.

Q1. You create `beta.example.com` at 14:05. A teammate's resolver looked the name up at 14:00 and got NXDOMAIN. At 14:30 their lookups still fail, although both authoritative servers already return the new A record. The zone's SOA record sets a negative-caching time of 3,600 seconds. Why?
Q2. A capture shows a client SYN and the server's SYN-ACK. What completes the three-way handshake?
Q3. Idle database connections through a NAT gateway break after about six minutes; the gateway forgets idle flows after 350 seconds. `net.ipv4.tcp_keepalive_time` is 7200. What fixes it?
Practice only: not graded, not saved, not evidence.

05. Apply it

Incorporate these operational tracing techniques into production maintenance:

  • Pre-Migration TTL Reduction: When planning a service migration to a new IP, reduce the DNS record TTL to 300 seconds (5 minutes) at least 48 hours prior to the migration. Resolvers that respect the TTL then pick up the new IP within about five minutes of the change; some clients and resolvers cache longer than the TTL, so keep the old server running for a while.
  • Inspect SNI Handshake Issues: When configuring custom domains on Cloudflare or AWS CloudFront, run curl -Iv --resolve custom.example.com:443:1.2.3.4 https://custom.example.com to test SNI certificate delivery before updating public DNS.
  • Validate Virtual Hosting Locally: Test new Nginx virtual host configurations locally without modifying DNS by passing the target domain via the Host header: curl -H "Host: staging.example.com" http://localhost:8080/.
  • Tune TCP Keepalive on Internal Connections: For long-lived gRPC and database connections traversing load balancers, enable TCP keepalive in the client (the SO_KEEPALIVE socket option, or the driver's keepalive setting) and make the first probe fire before the NAT gateway's or load balancer's idle timeout, so the middlebox keeps its state and dead connections are noticed. The sysctl net.ipv4.tcp_keepalive_time (default 7200 seconds) only sets the host-wide default for sockets that enable keepalive; for example, Azure Load Balancer's default idle timeout is 4 minutes, so even 300 seconds would be too long there.
  • Monitor TCP Connection States: Inspect netstat -ant or ss -tan during high traffic spikes to verify that connections transition smoothly to ESTABLISHED and do not pile up in SYN_RECV (a possible SYN flood, or an application that accepts connections too slowly) or TIME_WAIT.

06. Review prompt

Trace the step-by-step lifecycle of an HTTPS request from initial user keystroke to server response. Explain the role of recursive DNS resolvers, the purpose of sequence numbers in the TCP three-way handshake, the necessity of SNI in TLS negotiation, and how reverse proxies utilize the HTTP Host header.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check