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
On this page
- Step 1: Translating Hostnames to IPs via DNS
- Steps 2 & 3: The TCP Three-Way Handshake and TLS Negotiation
- Step 4: HTTP Request Formatting and Virtual Hosting
- Check your understanding
- Apply it
- Review prompt
Lessons of Networking Basics
- Layers as a debugging map, and what L4 and L7 mean Concept · 15 min
- Addresses, CIDR blocks and the default gateway: DHCP, ARP and the next hop Worked example · 25 min
- From a name to a response: DNS, TCP and HTTP in one trace Worked example · 20 min
- Ports, NAT, firewalls, proxies and TLS along the path Concept · 20 min
- Troubleshooting lab: which hop is broken? Lab · 25 min
- Check: subnetting and failure triage Knowledge check · 8 questions
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:
- Stub Resolver: The local libc resolver follows the order in
/etc/nsswitch.conf(typically the static/etc/hostsfile first, then DNS servers from/etc/resolv.conf). It does not cache answers by itself; a local cache exists only if a service such assystemd-resolved,nscdordnsmasqruns. - Recursive Resolver: If uncached, the query is forwarded to a recursive resolver (such as cloud provider internal DNS, Google
8.8.8.8, or Cloudflare1.1.1.1). The recursive resolver does the work of walking the DNS tree, one iterative query per level, and caches what it learns. - Root Nameservers (
.): Do not know the answer, but refer the resolver to the Top-Level Domain (TLD) nameservers responsible for the.comzone. - TLD Nameservers (
.com): Do not know the answer either. They reply with a referral: the NS records that name the authoritative nameservers forexample.com, usually with their IP addresses (glue records). - 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.
# 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 +short02. 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
SYNcontrol 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) andACK(acknowledging x + 1). - ACK (Acknowledge): The client acknowledges y + 1. The connection enters the
ESTABLISHEDstate, 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:
- 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. - 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.
- 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.
GET /v1/users HTTP/1.1
Host: api.example.com
User-Agent: curl/8.5.0
Accept: application/json
Connection: keep-alive# 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/health04. Check your understanding
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.comto 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
Hostheader: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_KEEPALIVEsocket 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 sysctlnet.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 -antorss -tanduring high traffic spikes to verify that connections transition smoothly toESTABLISHEDand do not pile up inSYN_RECV(a possible SYN flood, or an application that accepts connections too slowly) orTIME_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
- RFC 1034: Domain names - concepts and facilities (CNAME rule, section 3.6.2)
- RFC 1035: Domain names - implementation and specification
- RFC 9293: Transmission Control Protocol (TCP)
- RFC 9110: HTTP Semantics
- RFC 2308: Negative Caching of DNS Queries (DNS NCACHE)
- RFC 10024: Post-Quantum Traditional (PQ/T) Hybrid Key Agreement Mechanisms for TLS 1.3
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.