AlgoViz

Introduction to DNS

easy 25 min

DNS is the distributed database that turns names such as www.example.com into addresses computers can connect to.

See it run

The parts of DNS, how a name is read, which record to choose, and how to change an address without losing users.

Operations

One lookup

From a typed name to a connection. Each server knows only the next step.

Step 1 of 6

The question

BrowserResolverRoot serverscom serversexample.com DNSWeb server192.0.2.10

www.example.com?

The browser needs the address of www.example.com and asks its resolver.

Step 1: The question

def resolve(name):    if name in cache:        return cache[name]    tld = ask(ROOT, name)            # who runs com?    owner = ask(tld, name)           # who runs example.com?    answer = ask(owner, name)        # the record    cache[name] = answer, answer.ttl    return answer
Questions asked
1 to 4
You learn
The address
Answer in a cache
no walk at all

Say who does the walking: the resolver asks the three servers, not the browser.

In the real world

The same introduction to dns doing real jobs. Pick one and step through it.

Two addresses for one name, and what plain DNS does not notice.

Step 1 of 4

Two answers

Our systemClientsDNStwo A recordsServer AhalfServer Bhalf

Rough sharing

DNS returns both addresses in changing order. Users spread roughly evenly.

Step 1: Two answers

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Putting an IP address in the program

    critical

    The address changes one day and every copy of the program breaks.

    Wrong
    connect("192.0.2.10")
    Right
    connect("api.example.com")
  • Lowering the TTL at the moment of the change

    major

    Caches already hold the answer with the old TTL.

    Wrong
    set_ttl(60)set_address(new)
    Right
    set_ttl(60)wait(old_ttl)set_address(new)
  • Resolving once at start-up

    major

    The process keeps calling an address that has left, long after the TTL.

    Wrong
    ADDR = resolve(NAME)   # for ever
    Right
    def address():    return cache_for_ttl(NAME)
  • Treating round-robin DNS as a load balancer

    minor

    It spreads lookups and not requests, and it does not see a dead server.

    Wrong
    A records: s1, s2, s3
    Right
    A record: balancerbalancer checks s1, s2, s3

Interview tips

  • How to explain it

    • A tree of names, each branch run by its owner.
    • Root, TLD and authoritative servers point down the tree.
    • Answers are records with a time to live.
  • Memory trick

    • You, resolver, root, TLD, authoritative.
    • Names are read from right to left.
    • CNAME is a nickname.
  • Reach for it when

    • An address may change.
    • Users are far apart.
    • Customers bring their own domain.
  • Be careful when

    • You need a change in seconds.
    • Clients cache for ever.
    • Old records point at things you no longer own.