Skip to main content
networking

DNS

10 min read
Fully authored

How a name becomes an IP — and how DNS becomes a load balancer.

In 1983, the ARPANET had grown to a few hundred computers. Each computer knew its own IP address, and if you wanted to talk to another one, you looked up its name in a single file called HOSTS.TXT. The file lived at SRI International in California and was manually updated as new hosts joined. Every computer on the ARPANET downloaded a copy periodically. As the network grew past a few hundred hosts, this stopped scaling — imagine editing a shared text file every time someone added a new server.

Paul Mockapetris at USC/ISI proposed a solution: replace the single flat file with a hierarchical, distributed database where each organization managed its own portion. He published RFC 882 and RFC 883 in 1983, then refined the design in RFC 1034 and RFC 1035 in 1987. The result was the Domain Name System — DNS. Today DNS serves an estimated ~5 trillion queries per day globally. Every time you type a URL, click a link, open an app, send an email, or your phone syncs your calendar, DNS resolves at least one name to an IP.

DNS is officially a Layer 7 (Application) protocol, running mostly over UDP (Layer 4) on port 53. But its role is foundational: without DNS, you'd need to memorize 142.250.80.46 to reach Google. Every protocol above IP implicitly depends on DNS to be usable. It's also the internet's biggest attack surface — DDoS amplifiers, cache poisoning, hijacking, censorship. And it's a load balancer: change the DNS response and you route traffic differently.

The RFCs

  • RFC 1034 (1987, Mockapetris) — Domain Names: Concepts and Facilities.
  • RFC 1035 (1987, Mockapetris) — Domain Names: Implementation and Specification. The wire format still used today.
  • RFC 4033-4035 (2005) — DNSSEC. Signed DNS responses to prevent cache-poisoning.
  • RFC 7858 (2016) — DNS over TLS (DoT).
  • RFC 8484 (2018) — DNS over HTTPS (DoH).

The hierarchy — how names are organized

DNS is a tree. The root is the empty string (called "the dot"). Below the root are top-level domains (TLDs): .com, .org, .net, .io, .co.uk, and 1500+ others. Below each TLD are second-level domains: google.com, github.io, bbc.co.uk. Below those are subdomains: mail.google.com, api. github.com. The tree can be arbitrarily deep.

The DNS tree — from root to your subdomain
.root.comVerisign.orgPIR.ukNominetgoogleGooglegithubGitHubwikipediaWMFbbcBBCgovGov of UKwwwmailapirawnewsRoot (13 servers)TLD (~1500)Second-levelSubdomain
Each level is served by different servers. When you look upwww.google.com, your resolver walks: root → .com TLD → google.com authoritative → returns the A record for www.

Each level of the tree is served by a different authoritative name server. The 13 root name servers (named a.root-servers.net through m.root-servers.net) know where all the TLD servers are. Verisign runs the .com and .net TLD servers. GoDaddy is the biggest registrar for buying second-level domains. Once you own google.com, you can point it at whichever authoritative name servers you want (Cloudflare, AWS Route 53, or your own bind9 install).

Recursive resolution — the animated walkthrough

You type google.com into your browser. What happens? A recursive resolver (usually your ISP's or one you configured like 1.1.1.1) walks the hierarchy on your behalf.

Recursive DNS resolution — step 1 of 5
Cold cache — 4 round-trips. Once cached, 1 round-trip.
Q: A? www.google.comBrowserchrome, curl…Recursive1.1.1.1, ISPRoota.root-servers.com TLDVerisignAuthoritativens1.google.com
Step 1: Browser asks its configured resolver (usually your ISP's, or 1.1.1.1). Resolver checks its cache — miss.

The full recursion involves up to 4 round-trips (root → TLD → authoritative → response), but caching drops that to typically 1 round-trip in steady state. Every hop that answers stores its answer with a TTL (Time-To-Live) — how long other resolvers may cache the answer before asking again. Popular sites like google.com are cached almost everywhere with sub-millisecond access.

TTL — the caching knob that runs the internet

TTL is the single most important operational knob in DNS. Long TTL (e.g., 1 day) means resolvers cache aggressively — fewer queries hit your authoritative servers, less load, less cost — but if you change the record, the change won't propagate for up to a day. Short TTL (e.g., 60 seconds) means fast propagation but more queries and more load.

Interactive: TTL trade-off
30s (aggressive)3600s (1 hr)86400s (1 day)
Cache hit rate
96.7%
Queries hitting auth
33,333
per 1M total
Change propagation
5m
worst case
Balanced: 97% cache hit rate, 5-minute worst-case propagation. Industry-standard for most A/AAAA records.

Rule of thumb: long TTL for stable records (your MX servers rarely change) and short TTL for volatile records (health-checked A records that swap during a failover). Before a planned migration, drop the TTL a day early so resolvers refresh frequently by cutover time.

Record types — the alphabet soup

DNS carries many types of records, not just A records (hostname → IPv4). Each record type serves a specific purpose:

TypePurposeExampleTypical TTLWho uses it
AHostname → IPv4 addressgoogle.com → 142.250.80.4660s - 1dEveryone
AAAAHostname → IPv6 addressgoogle.com → 2607:f8b0:4004:c07::6460s - 1dIPv6-enabled sites
CNAMEAlias one name to another. Can't coexist with other records at the same name.www.example.com → example.comhours - 1dSaaS docs sites (myco.readthedocs.io)
MXMail exchanger. Points at the SMTP server accepting mail for a domain.example.com MX 10 mail.example.comhours - 1dAnyone with email
TXTFree-form text. Used for SPF, DKIM, DMARC, ownership verification.v=spf1 include:_spf.google.com ~allhours - 1dEmail deliverability, domain verification
NSDelegates a subdomain to different authoritative name servers.example.com NS ns1.google.com1d+Registrars, DNS providers
SRVService record: which host+port serves a specific protocol._xmpp._tcp.example.com → 10 60 5222 xmpp.example.comhoursXMPP, SIP, Kubernetes CoreDNS
SOAStart Of Authority. Zone metadata — refresh interval, serial number, primary NS.example.com SOA ns1.google.com hostmaster (2024112001 3600 …)1d+Every zone has exactly one
PTRReverse DNS — IP → hostname. Used for logging, spam filtering.142.250.80.46 → someweb-front.example.net1d+Mail servers, log analyzers
CAACertificate Authority Authorization — restricts which CAs may issue certs for this domain.example.com CAA 0 issue letsencrypt.orghoursDomain owners for security

DNS as a load balancer

Here's a design trick: because DNS resolvers cache and every resolver can get a different answer, DNS itself can act as the first tier of load balancing. Four common techniques:

Round-robin DNS
How: Return multiple A records; different clients see different orderings. Client picks the first.
✓ Pros: Simple. Free. Works everywhere.
✗ Cons: No health awareness — dead IPs stay in rotation. Client caching interferes.
Small-scale HA. Many static sites still use this.
Weighted DNS
How: Return records with weights. Return them proportionally so 70% of clients get server A, 30% get server B.
✓ Pros: Great for canary deploys — send 5% of traffic to the new version.
✗ Cons: Still no health awareness by default. Coarse-grained.
AWS Route 53 weighted routing, Cloudflare Load Balancer.
Latency-based routing
How: Resolver's IP → estimated geolocation → closest AWS region. Returns different IP based on where the client is.
✓ Pros: Users get low-latency routing automatically.
✗ Cons: Estimate is coarse (city-level at best). Corporate NATs pick unexpected regions.
AWS Route 53 latency-based, Google Cloud DNS, Cloudflare Argo Smart Routing.
GeoDNS
How: Return different answers based on the resolver's country/region. Compliance + localization.
✓ Pros: Respects data-residency law: EU users → EU servers.
✗ Cons: Country accuracy of resolver IP is imperfect.
Netflix — different Open Connect appliances per ISP. Uber for geo-fenced services.
Health-checked DNS failover
How: Continuously health-check registered targets. Return only healthy ones. When primary dies, remove from DNS.
✓ Pros: Real failover — dead servers stop getting traffic.
✗ Cons: Slow (TTL-bounded — clients may cache the dead IP for the TTL duration).
AWS Route 53 with health checks, DNSMadeEasy, Dyn (RIP), Constellix.
Anycast (technically L3, but felt via DNS)
How: The same IP is announced from many places. Router picks nearest. DNS returns one Anycast IP; the network figures out where.
✓ Pros: Instant failover (no TTL wait), automatic geo-routing, absorbs DDoS.
✗ Cons: Requires BGP presence in many DCs — infra-heavy.
Cloudflare 1.1.1.1, Google DNS 8.8.8.8, all root DNS servers.

DNS security — the underbelly

DNS was designed in 1983 with zero security assumptions. UDP is stateless — you send a query, an answer comes back, and you have no way to verify the answer wasn't forged. This has led to decades of attacks and slow migrations toward secure DNS.

  • Cache poisoning (Kaminsky 2008): attacker floods the resolver with fake responses matching a spoofed query ID, hoping one lands before the real answer. Fixed partially by source-port randomization and DNSSEC.
  • DNS amplification: attacker sends a small DNS query with a spoofed source IP (the victim). The huge response floods the victim. Classic DDoS vector.
  • DNS hijacking: attacker changes NS or A records at a registrar to point domains at their servers. Cryptocurrency exchanges are common targets.
  • ISP censorship: ISPs return NXDOMAIN or redirects for blocked sites. Users route around this via third-party resolvers (1.1.1.1, 8.8.8.8) or DoH.
  • DNSSEC (2005) — every zone signs its records with a private key; resolvers verify against a chain of trust rooted at the root zone.
  • DoT (2016) & DoH (2018) — DNS queries encrypted so ISPs can't see or modify them.

Applied in real systems — lots of examples

Cloudflare 1.1.1.1
Deep dive

Cloudflare 1.1.1.1 — the fastest public resolver

Announced April 1, 2018. Anycast IPs 1.1.1.1 and 1.0.0.1. Served from 300+ Cloudflare data centers. Supports DoT and DoH natively. Committed to zero query logging (audited by KPMG). Reached 25%+ of global public DNS traffic in 2 years.

Read the deep dive →
Google 8.8.8.8
Deep dive

Google Public DNS 8.8.8.8 — the memorable default

Launched 2009. Anycast IPs 8.8.8.8 and 8.8.4.4. The most recognizable public resolver — often typed from memory during network troubleshooting. Serves ~1 trillion queries per day. Google logs queries for security research but anonymizes.

Read the deep dive →
AWS Route 53
Deep dive

AWS Route 53 — the AWS control plane's control plane

Route 53 is AWS's authoritative DNS. Named after port 53. Powers every AWS customer's public domain. Built on an Anycast fleet of ~200+ PoPs. Supports latency-based, geolocation-based, weighted, and failover routing policies. Health checks integrate directly with the DNS response.

Read the deep dive →
Cloudflare Authoritative
Deep dive

Cloudflare Authoritative — the biggest managed DNS

Cloudflare hosts DNS for millions of domains for free. Their authoritative servers are on the same 300+ PoPs as 1.1.1.1. Publishes a DNS record in ~5 seconds globally (via their own control plane). Every free-tier Cloudflare site rides on this.

Read the deep dive →
Verisign .com
Deep dive

Verisign — operator of .com and .net

Verisign has run the .com and .net TLD servers since 2000 (via ICANN contract). Handles ~150,000 queries per second on average, ~350,000 at peak. Their infrastructure is literally the phone book for half of the commercial internet.

Read the deep dive →
GoDaddy
Deep dive

GoDaddy — the biggest registrar

GoDaddy manages ~85 million domains. When you buy a domain, you're usually buying it through a registrar like GoDaddy, Namecheap, or Cloudflare Registrar. They handle the WHOIS record and (optionally) authoritative name servers.

Read the deep dive →
Netflix
Deep dive

Netflix — DNS-based Open Connect routing

Netflix resolves occ-0-*.1.nflxso.net differently per ISP — the DNS response points the client at the nearest Open Connect Appliance embedded in that ISP's network. The whole CDN architecture depends on smart DNS resolution.

Read the deep dive →
Unbound, BIND
Deep dive

Unbound & BIND — the open-source DNS servers

BIND (Berkeley Internet Name Domain, 1984) is the historical DNS server that ran the early internet. Unbound (2007) is the modern validating/recursive resolver. Both power much of the non-cloud DNS infrastructure worldwide.

Read the deep dive →
dnsmasq
Deep dive

dnsmasq — the DNS in your home router

Nearly every home router in the world runs dnsmasq. It serves DNS + DHCP for the LAN, caches upstream queries, and handles the mDNS/Bonjour local-network name resolution. Written in ~10k lines of C by Simon Kelley.

Read the deep dive →
Firefox DoH
Deep dive

Firefox & Chrome — DNS over HTTPS by default

Firefox started using Cloudflare 1.1.1.1 via DoH by default in the US in 2020, bypassing ISP DNS. Chrome does the same when the user's configured DNS supports DoH. This shift moved DNS trust from the ISP to the browser vendor.

Read the deep dive →
Quad9 (9.9.9.9)
Deep dive

Quad9 — the malware-blocking public resolver

Non-profit resolver at 9.9.9.9. Blocks known malicious domains at the DNS level. Runs on IBM infrastructure. Popular in privacy-focused circles for its no-logging policy.

Read the deep dive →
Kubernetes CoreDNS
Deep dive

Kubernetes CoreDNS — service discovery via DNS

Every Kubernetes cluster runs CoreDNS inside. Pods resolve service names like my-service.my-namespace.svc.cluster.local via CoreDNS, which watches the Kubernetes API for services and endpoints. DNS as service discovery.

Read the deep dive →

Key takeaways

  • DNS is a hierarchical distributed database from 1983. Root → TLD → authoritative → subdomain. Layer 7, port 53, mostly UDP.
  • Recursive resolution walks the hierarchy on your behalf. Cold: up to 4 round-trips. Warm: 1 round-trip. Caching is what makes DNS fast in practice.
  • TTL is the caching-vs-agility knob. Long TTL = fewer queries, slower propagation. Short TTL = fast changes, more load.
  • Record types matter. A (IPv4), AAAA (IPv6), CNAME (alias), MX (mail), TXT (arbitrary), NS (nameserver), SRV (service), SOA (zone metadata).
  • DNS is a load balancer: round-robin, weighted, latency-based, GeoDNS, and health-check-driven failover all work at the DNS layer.
  • DNS security: DNSSEC signs responses, DoT/DoH encrypt them. Cache poisoning, amplification, and hijacking are the classic attacks.
  • Every serious system depends on DNS as a hidden dependency. When DNS fails, everything fails. Design for it: fallback resolvers, aggressive local caching, monitor query success rates.

References

  • Mockapetris (1983, 1987) — RFCs 882, 883, 1034, 1035. The DNS design.
  • Kaminsky (2008) — Black Hat presentation on the cache-poisoning attack that forced worldwide patching.
  • RFCs 4033-4035 (2005) — DNSSEC.
  • RFC 7858 (2016) — DNS over TLS.
  • RFC 8484 (2018) — DNS over HTTPS.
  • Cloudflare Learning Center — DNS docs at cloudflare.com/learning/dns/

Practice what you just read

Every foundation concept has a companion quiz to close the loop.