DNS
How a name becomes an IP address — stub, recursive and authoritative resolvers, the root/TLD hierarchy, record types, TTLs and caching, DNS over UDP/TCP/HTTPS, DNS-based load balancing and failover, GeoDNS, anycast, and DNS security.
Why DNS exists
Humans remember example.com; networks route 93.184.215.14. The Domain Name System is a globally distributed, hierarchical, heavily cached database that maps names to addresses (and much more). It's also one of the most important pieces of traffic control infrastructure you have.
The hierarchy
Resolution step by step
dig www.example.com +trace # watch the delegation chain
dig example.com MX +short
dig @1.1.1.1 example.com AAAA
Record types
| Type | Maps | Example |
|---|---|---|
| A / AAAA | name → IPv4 / IPv6 | api.example.com. 300 IN A 203.0.113.10 |
| CNAME | alias → canonical name | www → example.com.cdn.net. |
| ALIAS / ANAME | apex alias (provider feature) | example.com → lb-123.elb.amazonaws.com |
| MX | mail exchangers | 10 mx1.example.com. |
| TXT | text: SPF, DKIM, DMARC, verification | "v=spf1 include:_spf.google.com ~all" |
| NS | delegation | example.com. NS ns1.dnsprovider.net. |
| SOA | zone authority, serial, negative TTL | |
| SRV | service location with port | _xmpp._tcp 10 5 5222 chat.example.com. |
| PTR | reverse DNS | 10.113.0.203.in-addr.arpa → api.example.com |
| CAA | allowed certificate authorities | 0 issue "letsencrypt.org" |
| HTTPS / SVCB | connection hints (ALPN h3, ECH) | 1 . alpn="h3,h2" |
Caching and TTLs
Caches exist in the browser, the OS, the recursive resolver, and sometimes in application runtimes (JVM networkaddress.cache.ttl). Negative answers (NXDOMAIN) are cached too, per the SOA's minimum TTL.
DNS as a traffic-management tool
| Technique | Use |
|---|---|
| Round robin (multiple A records) | crude load spreading |
| Weighted routing | canaries, gradual migration between stacks/providers |
| Latency-based / GeoDNS | send users to the nearest region; data residency |
| Health-checked failover | active-passive between regions |
| Anycast | one IP, many locations — DNS servers, CDNs, global LBs |
| Split-horizon DNS | different answers for internal vs external clients |
| Service discovery | Consul DNS, Kubernetes CoreDNS (svc.namespace.svc.cluster.local) |
DNS security and failure modes
| Threat / failure | Mitigation |
|---|---|
| Cache poisoning (forged responses) | random source ports + query IDs, DNSSEC (signed records) |
| On-path snooping | DNS over HTTPS/TLS/QUIC |
| DDoS on authoritative servers | anycast, large providers, multiple providers (secondary DNS) |
| Domain hijacking / expiry | registrar lock, MFA, auto-renew |
| Dangling CNAMEs (subdomain takeover) | remove records when deprovisioning cloud resources |
| DNS outage = total outage | long-enough TTLs, multi-provider DNS, don't make every internal call depend on fresh lookups |
Interview questions
Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.