How DNS works
medium 25 minResolution turns a name into an address by checking caches first and then following referrals from the root to the owner's servers.
See it run
Step through a cold lookup, the two kinds of question, caches with yes and no answers, and the chain of trust.
Operations
The cold walk
www.example.com with every cache empty, from your keyboard to the owner's server and back.
Step 1 of 11
User request
www.example.com?
You type www.example.com.
Step 1: User request
def lookup(name): for cache in (browser, system): if cache.fresh(name): return cache[name] return resolver.resolve(name) # one recursive questiondef resolve(name): # inside the resolver server = closest_known(name) # root, if nothing is known while True: reply = ask(server, name) # iterative if reply.is_answer: cache.store(name, reply) return reply server = reply.referral- Messages
- 4 round trips
- Proves
- Nothing by itself
- Warm resolver
- 1 round trip
The resolver sends every message after the first one.
In the real world
The same how dns works doing real jobs. Pick one and step through it.
The same record change reaches three caches at three times.
Step 1 of 4
11:59
TTL 3600 s
A asked at 11:05, B has just asked, and C has never asked. The TTL is one hour.
Step 1: 11:59
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Saying the browser asks the root servers
majorThe browser asks through the system to one resolver. The resolver walks.
Wrongbrowser -> root -> com -> ownerRightbrowser -> resolverresolver -> root, com, ownerBelieving DNSSEC hides questions
criticalIt signs public records. Anyone on the way can still read the question.
Wrongprivacy = DNSSECRightgenuine = DNSSECprivate = DoH or DoTRetrying a name that does not exist
minorNXDOMAIN is an answer. Retrying adds load and delay.
Wrongretry on any errorRightretry on timeout, SERVFAILstop on NXDOMAINTesting a name before creating it
minorThe no is cached and hides the new record.
Wronglookup("new")create("new")Rightcreate("new")lookup("new")
Interview tips
How to explain it
- One recursive question from you.
- Iterative questions from the resolver.
- Caches stop the walk as early as they can.
Memory trick: BORRTA
- Browser, OS, Resolver.
- Root, TLD, Authoritative.
- Be Our Reliable Route To Answers.
Debug like this
- Ask your resolver.
- Ask the owner's server.
- Different: caching. Same: not DNS.
Security in two lines
- DNSSEC proves the record.
- DoH and DoT hide the question.
- TLS still proves the server.