Labs / Protocols / Names & errors

Lab 2 of 3 ยท Names & errors

DNS: how a name finds its address, and why changes take time

Follow a name down the DNS hierarchy, then watch two resolvers disagree after a move.

Start this lab 6 steps

The idea

Priya moved her tea shop's website to a new server this morning, and her customers still see the old one. Her web host says to wait 48 hours, and Priya wants to know what exactly she is waiting for.

One address to ask
One address to ask
A name is a path down a tree
A name is a path down a tree
One question in, many questions out
One question in, many questions out
Two resolvers, one moment, two answers
Two resolvers, one moment, two answers
Three different kinds of no
Three different kinds of no
The file answers before DNS
The file answers before DNS

Steps

  1. Ask for a name

    Computers reach each other by IP address, and people remember names. So every time a customer opens Priya's site, something has to turn www.orchard.lab into an address.

    In the early 1980s that something was one text file, HOSTS.TXT, kept by one office in California. Every machine on the network downloaded a copy, and as the network grew, the file couldn't keep up. In November 1983 Paul Mockapetris published the replacement: the Domain Name System (DNS), a directory shared out across many servers, where no server holds the whole list.

    A laptop doesn't search that directory itself. It hands every question to one server, called its Recursive resolver. The file /etc/resolv.conf names that server.

    Read that file, then ask for the shop with dig, a tool that sends one DNS question and prints the whole reply. The lab also runs a capture on the laptop, which lists the DNS packets it sends and receives.

    laptop:~# cat /etc/resolv.conf
    laptop:~# dig www.orchard.lab
  2. Follow the name from the root

    The resolver doesn't hold the shop's address, so where does it find it? No server knows every name. Names form a tree instead, and you read a name from right to left.

    www.orchard.lab. really ends in a dot, and that dot is the root of the tree. Under the root sits lab, in the place where .com sits on the real internet. Under lab sits orchard.lab, which belongs to Priya, and www is a name inside it.

    Each level hands the part below it to someone else's server, and that is called delegation. A part of the tree that one server answers for is a zone, and that server is an authoritative server for it. It answers for its own zone and nothing more, so a search starts at the top and moves down.

    Do the resolver's job by hand now. Every resolver is built with the addresses of the root servers, because something has to be known before the first question. In this lab that is 10.0.2.10.

    laptop:~# dig +norecurse @10.0.2.10 www.orchard.lab
    laptop:~# dig +norecurse @10.0.2.20 www.orchard.lab
    laptop:~# dig +norecurse @10.0.2.30 www.orchard.lab
  3. Watch the resolver search, then remember

    The walk you did by hand took three questions. A full walk for every click would be slow, and the root servers would drown in questions. So a resolver keeps each answer for a while.

    That store is its cache, and the record's owner decides how long a copy may stay, with a number called the time to live (TTL).

    Be careful with that word. The TTL in ping counts routers in an IP packet, and this one counts seconds on a DNS record. They share only a name, and the 30 you saw in the last steps is the second kind.

    Now watch the resolver do the walk itself. The lab clears its memory first, so it starts from nothing, and for each question a capture on the resolver lists every DNS packet.

    You will ask three times: www, then www again 5 seconds later, then shop.orchard.lab, a name the resolver hasn't seen.

    laptop:~# dig +noall +answer www.orchard.lab
    laptop:~# dig +noall +answer www.orchard.lab
    laptop:~# dig +noall +answer shop.orchard.lab
  4. Move the shop and watch two resolvers disagree

    Now do what Priya did. Her record lives on one server, orchardServer, so a move means changing one line there. The lab will point www away from the old web server, 10.0.2.31, and at the new one, 10.0.2.32.

    People call what happens next propagation, as if the new address spreads out across the world. That word makes you picture a push, and DNS has no push. A name server doesn't know which resolvers hold a copy of its records, and it never contacts them.

    Two resolvers will show what happens instead. The provider's resolver asks for the shop a few seconds before the move.

    The public resolver at 10.0.2.53 stands in for free ones such as Google's 8.8.8.8 or Cloudflare's 1.1.1.1, and it has no copy. You ask both after the move, and @ picks which one.

    laptop:~# dig +noall +answer www.orchard.lab
    laptop:~# dig +noall +answer @10.0.2.53 www.orchard.lab
    laptop:~# dig +noall +answer www.orchard.lab
  5. Read the three ways DNS says no

    Most DNS trouble doesn't come as a wrong address. It comes as a program printing Could not resolve host, which hides the reason. dig shows the reason in status.

    Three different failures look alike in a browser: the name doesn't exist, the name exists with no record of the type you asked for, or the resolver couldn't finish the search. They point at different people, so you need to tell them apart. dig calls the first one NXDOMAIN and the last one SERVFAIL.

    Each of these has a real example here. nope.orchard.lab was never created. www.orchard.lab has an IPv4 address and no IPv6 address, and AAAA is the record type that holds an IPv6 address.

    The third needs a broken neighbor, so the lab adds one to the lab zone: bakery.lab, handed to 10.0.2.30. That is Priya's server, and it holds no such zone.

    laptop:~# dig nope.orchard.lab
    laptop:~# dig www.orchard.lab AAAA
    laptop:~# dig www.bakery.lab
  6. See what programs really ask

    Every test so far used dig, and dig talks to a DNS server and nothing else. Browsers, curl and ping work differently. They call the system's own name lookup, and that has more than one place to look.

    One of those places is a plain file, the hosts file: /etc/hosts on Linux and macOS, and C:\Windows\System32\drivers\etc\hosts on Windows. It is the same idea as the old HOSTS.TXT: an address and a name on a line, with no TTL. A line in it stays until someone deletes it.

    Developers add lines there to test a site before a move, and then forget them. Suppose someone did that on this laptop months ago. The lab adds the line 10.0.2.31 www.orchard.lab, and the zone still points at the new server.

    getent hosts does the same lookup that programs do, and prints what they would get. dig +short prints only the answer.

    laptop:~# getent hosts www.orchard.lab
    laptop:~# dig +short www.orchard.lab
    laptop:~# curl -sS -m 5 http://www.orchard.lab/

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab