DNS

Understand how domain names resolve to IP addresses through recursive resolvers, root, TLD and authoritative servers, plus record types and caching.

Beginner · about 3 hours · difficulty 2/5

Learn first: Transport Layer: TCP and UDP

DNS is the internet's phone book: it turns example.com into an IP address. It is short to learn and appears in almost every "what happens when you type a URL" answer.

Resolution step by step

  • The browser checks its own cache, then the OS cache and the hosts file.
  • The query goes to a recursive resolver (your ISP's, or a public one like 8.8.8.8 or 1.1.1.1).
  • The resolver asks a root server, which points to the TLD server for .com, which points to the domain's authoritative name server, which returns the answer.
  • The resolver caches the answer for its TTL and returns it. Recursive (resolver does the work for you) vs iterative (each server refers you onward) queries are a common question.

Record types to know

  • A (IPv4) and AAAA (IPv6).
  • CNAME: an alias to another name (www pointing to the root domain or a CDN).
  • MX: mail servers. TXT: verification and email security (SPF, DKIM). NS: authoritative name servers.

Why it matters in engineering

  • TTL trade-off: long TTLs mean fewer lookups but slow changes during a migration.
  • DNS is used for simple load balancing and geo-routing (returning different IPs by region), which ties into system design.
  • DNS runs mostly on UDP port 53, falling back to TCP for large responses.
  • Security: DNS spoofing and cache poisoning, mitigated by DNSSEC; DNS over HTTPS for privacy.

Good enough to move on: you can explain the full resolution path with caching, pick the right record type for a scenario, and use nslookup or dig to inspect a domain.

Key concepts

  • Resolver, root, TLD, authoritative
  • Recursive vs iterative queries
  • A, AAAA, CNAME, MX, TXT, NS records
  • Caching and TTL
  • DNS-based load balancing
  • dig and nslookup
  • DNS security and DNSSEC

Mini project

Use dig +trace on three domains and document each step of the resolution chain, then write a small script that sends a raw DNS query over UDP and parses the A records from the response.

Check yourself

You changed your server's IP but some users still reach the old one for hours. What explains this and how would you plan the next migration?

Free resources