Chapter 06 — DNS (The Internet's Phonebook)

Chapter 06 — DNS (The Internet's Phonebook)

Hey everyone! Welcome to Season 3 — Naming & The Web! 🙏

You type google.com, but computers route by IP addresses like 142.250.72.14. Something translates the friendly name into the number. That something is DNS — the Domain Name System — and it's one of the most elegant distributed systems ever built. It's also a guaranteed interview topic.

What we will cover:

  • What DNS is (the phonebook analogy)
  • The DNS hierarchy (root → TLD → authoritative)
  • How a lookup actually works, step by step
  • Caching & TTL (why it's fast)
  • Common record types (A, AAAA, CNAME, MX)
  • Interview Questions

1. What Is DNS?

┌─────────────────────────────────────────────────────────────┐
│   DNS = the system that translates human-friendly domain     │
│   names (google.com) into IP addresses (142.250.72.14).      │
│                                                             │
│   It's the internet's PHONEBOOK: you know the name, DNS      │
│   finds the number. 📖                                       │
└─────────────────────────────────────────────────────────────┘

Without DNS you'd have to memorize numeric IPs for every site — and those IPs change! DNS lets names stay stable while the underlying addresses can move freely.


2. The DNS Hierarchy

DNS isn't one giant server — it's a distributed tree, read right-to-left in a domain name.

   Reading  www.google.com  from RIGHT to LEFT:

   ┌─────────────────────────────────────────────────────────┐
   │  ROOT (.)              → the top; knows where TLDs live  │
   │     │                                                   │
   │  TLD (.com)            → knows where .com domains live   │
   │     │                                                   │
   │  AUTHORITATIVE (google.com) → knows google's actual IPs │
   │     │                                                   │
   │  HOST (www)           → the specific machine            │
   └─────────────────────────────────────────────────────────┘

   Nobody stores the WHOLE internet's names. Each level only knows
   "who to ask next." A beautiful, scalable delegation.

3. How a Lookup Works (Step by Step)

LET'S TRACE:  resolving www.google.com
──────────────────────────────────────
  1. Your device asks its RESOLVER (usually your ISP's DNS server,
     or 8.8.8.8, 1.1.1.1)
  2. Resolver asks a ROOT server: "where's .com?"
        → root: "ask the .com TLD server at X"
  3. Resolver asks the .COM TLD server: "where's google.com?"
        → TLD: "ask google's authoritative server at Y"
  4. Resolver asks GOOGLE'S authoritative server: "IP of www?"
        → "142.250.72.14"  ✅
  5. Resolver returns the IP to your device (and CACHES it)
  6. Your device connects to 142.250.72.14

   Feels instant because most of this is CACHED (next section).
   Your device ─▶ Resolver ─▶ Root ("ask .com")
                     │      ─▶ .com TLD ("ask google")
                     │      ─▶ google authoritative ("here's the IP")
                     ◀── IP ──┘

4. Caching & TTL — Why It's Fast

   Doing that full walk EVERY time would be slow. So results are
   CACHED at many levels:
     • your browser cache
     • your OS cache
     • your resolver's cache

   Each DNS record has a TTL (Time To Live) = how long to cache it
   before re-checking. e.g. TTL 3600 = "trust this for 1 hour."

   → 2nd visit to google.com? The IP is already cached → instant,
     no full lookup needed. (Same caching idea as everywhere else.)

   TRADE-OFF: long TTL = faster + less DNS traffic, but changes
   take longer to propagate. Short TTL = quick changes, more lookups.

5. Common Record Types

RecordMaps...Example
AName → IPv4 addressgoogle.com → 142.250.72.14
AAAAName → IPv6 addressgoogle.com → 2607:f8b0::...
CNAMEName → another name (alias)www.site.com → site.com
MXDomain → mail serverwhere to deliver @gmail.com email
NSDomain → its authoritative name serverswho's in charge of this domain
TXTArbitrary text (verification, SPF)domain ownership proof

Interview Questions — Quick Fire!

Q: What is DNS?

"DNS, the Domain Name System, translates human-friendly domain names like google.com into the IP addresses that computers use to route traffic. It's essentially the internet's phonebook. It lets names stay stable and memorable while the underlying IP addresses can change, and it's a distributed, hierarchical system so no single server holds all names."

Q: How does a DNS lookup work?

"Your device asks a resolver, usually run by your ISP or a public provider. If the answer isn't cached, the resolver queries the root server, which points it to the appropriate top-level-domain server like .com, which points it to the domain's authoritative server, which returns the actual IP. The resolver caches the result and returns it to your device. It's a hierarchy where each level just says who to ask next."

Q: What is the DNS hierarchy?

"DNS is organized as a tree read right to left in a domain name: the root at the top, then top-level domains like .com or .org, then the authoritative servers for individual domains, and finally specific hosts. Each level only knows how to delegate to the next, which makes the system massively scalable — no server needs to know the entire namespace."

Q: Why is DNS caching important, and what is TTL?

"Caching avoids doing the full hierarchical lookup every time, making resolution fast and reducing load on DNS servers. Results are cached in the browser, the OS, and the resolver. Each record has a TTL, or Time To Live, specifying how long it may be cached before being refreshed. A longer TTL means faster responses but slower propagation of changes; a shorter TTL means changes take effect quickly but generates more lookups."

Q: What's the difference between an A record and a CNAME record?

"An A record maps a domain name directly to an IPv4 address, while a CNAME record maps a name to another name, acting as an alias. For example, www.example.com might be a CNAME pointing to example.com, which then has an A record resolving to the actual IP. AAAA records are the IPv6 equivalent of A records."


Key Points to Remember

ConceptKey Takeaway
DNSTranslates domain names → IP addresses. The internet's phonebook.
HierarchyRoot → TLD (.com) → authoritative → host. Each level delegates to the next.
LookupResolver walks the hierarchy (unless cached), returns the IP, caches it.
Caching & TTLCached at browser/OS/resolver; TTL controls freshness vs speed.
RecordsA (IPv4) · AAAA (IPv6) · CNAME (alias) · MX (mail) · NS · TXT.

What's Next?

We have the IP now. Time to actually ask for a web page. Chapter 07 covers HTTP — the language of the web: methods, status codes, and headers.

Keep learning, keep connecting! See you in the next one!