Lesson 3 of 7

DNS — The Internet's Phone Book

DNS translates names like example.com into IP addresses like 93.184.216.34. It's the first step of every page load, and you'll learn how a lookup works and how to inspect one.

Text
The lookup chain for api.shop.example.com:

 1. Browser cache — seen this name recently?
 2. OS cache — anyone on this machine seen it?
 3. Resolver (your ISP's, or 1.1.1.1 / 8.8.8.8) — cached?
 4. Root servers:      "for .com, ask these servers"
 5. .com TLD servers:  "for example.com, ask these"
 6. example.com's nameservers: "api.shop = 93.184.216.34"

Answer flows back, cached at every step (per its TTL).
Cold lookup: ~50-200ms. Cached: ~0ms. This is why DNS
caching exists and why 'propagation' takes time.
Bash
dig example.com             # full lookup, all details
dig example.com +short      # just the answer
# 93.184.216.34

# Record types — DNS stores more than addresses:
dig example.com A           # name -> IPv4
dig example.com AAAA        # name -> IPv6
dig example.com MX          # who receives this domain's email
dig example.com TXT         # freeform (domain verification, SPF)
dig www.example.com CNAME   # alias -> another name
dig example.com NS          # which servers answer for this domain

# Watch the full chain yourself:
dig example.com +trace

The TTL (time-to-live) on each record says how long may keep it. Long TTLs (hours) mean fast lookups but slow changes; that's why DNS changes 'propagate' gradually — caches worldwide expire on their own schedules. Ops teams drop TTL to 60 seconds before a migration, move, then raise it again.

Common question

Is DNS one big directory of names?

The Domain Name System maps names to records through a hierarchy. A resolver asks the root which servers know .com, asks those which servers are in charge of example.com, and asks those for the record it wants. Each answer comes with a time-to-live, and caches at every level make repeat lookups nearly free.

This has practical consequences. A change takes as long as the old time-to-live to fully take effect, so lower it before a migration. You can move a site by changing a record instead of telling everyone a new address. And when something is unreachable, the first thing to check is whether the name resolves at all.

Source: RFC 1034 describes the domain name space as "a tree structure", with authority for each part handed down (delegated) level by level.

Common mix-ups

Each of these sounds reasonable. Think about why it is wrong, then open the explanation.

  • There must be one master of domains, or lookups wouldn't agree.

  • A name is looked up fresh on every .

  • DNS turns names into addresses and nothing else.

Finished reading?Mark it done to track your progress.

Tip: use the ← and → keys to move between lessons.