AlgoViz

How DNS works

medium 25 min

Resolution 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

YouBrowser cacheSystem cacheResolverRoot serverscom serversns1.example.com

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

Our DNSchanged 12:00Cache Aold, till 12:05Cache Bold, till 12:59Cache Cempty

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

    major

    The browser asks through the system to one resolver. The resolver walks.

    Wrong
    browser -> root -> com -> owner
    Right
    browser -> resolverresolver -> root, com, owner
  • Believing DNSSEC hides questions

    critical

    It signs public records. Anyone on the way can still read the question.

    Wrong
    privacy = DNSSEC
    Right
    genuine = DNSSECprivate = DoH or DoT
  • Retrying a name that does not exist

    minor

    NXDOMAIN is an answer. Retrying adds load and delay.

    Wrong
    retry on any error
    Right
    retry on timeout, SERVFAILstop on NXDOMAIN
  • Testing a name before creating it

    minor

    The no is cached and hides the new record.

    Wrong
    lookup("new")create("new")
    Right
    create("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.