Course outline · 0% complete

0/25 lessons0%

Course overview →

DNS: how names become addresses

lesson 2-3 · ~12 min · 5/25

The internet's phone book

Humans remember names, networks deliver to numbers. DNS (Domain Name System) is the worldwide system that translates example.com into 93.184.215.14. No single computer holds the whole phone book. Instead the lookup walks a hierarchy, right to left through the name:

  1. Your machine asks a resolver (usually run by your ISP, or a public one like 8.8.8.8): "what is the address of example.com?"
  2. The resolver asks a root server: "who handles .com?" There are 13 named root server clusters that every resolver knows by heart.
  3. The resolver asks the .com TLD server (top-level domain): "who handles example.com?"
  4. The resolver asks that authoritative server, which owns the real answer: "example.com is 93.184.215.14."
  5. The resolver hands the answer back and caches it, so the next lookup skips all of this until the answer expires.

Each DNS answer carries a TTL (time to live), the number of seconds a resolver may cache it before asking again.

DNS matters to working engineers because it fails in famous ways: a wrong or stale record after a deploy means "the site is down" for some users and fine for others, depending on whose resolver cached what. That is why the half-joking rule "it's always DNS" exists, and why checking DNS is step 1 of the debugging checklist in unit 9.

You(browser)Resolvercaches answers1. Root server"ask .com"2. .com TLD"ask example's server"3. Authoritative"93.184.215.14"
A full DNS lookup: the resolver (gold dot's home base) queries root, TLD, then authoritative servers, and finally returns the IP to you. Cached answers skip the three right-hand trips.

Practice the two classic DNS lookup tools. This is a guided session: run each command and read the output.

Step 1/4: dig is the standard DNS lookup tool. Ask it for example.com and look at the ANSWER SECTION: the record type A means an IPv4 address, and 3600 is the TTL in seconds.

$ 

Code exercise · python

Your turn. Build the heart of a resolver: a cache in front of the authoritative answers. For each name in the query list, print a HIT line if the name is already in the cache dict, otherwise copy the answer from authoritative into cache and print a MISS line. This is exactly the caching behavior from step 5 of the lookup walk (real resolvers add a TTL timer to each entry; we skip that here).

Quiz

A DNS answer for api.example.com has TTL 300. What does that mean?

Problem

In the DNS hierarchy, one kind of server owns the final, official answer for a domain, the record that everything else is just a cached copy of. What is this kind of server called? (One word.)