skipnothing/HTTP & Networking

DNS Resolution

dig example.com prints just one answer, but dig +trace example.com prints three screens of servers handing you off, each one saying ask them instead until the last one finally answers.

  • ▸Your machine never walks the chain itself; it knows up to three DNS addresses, and something else does the walking.
  • ▸Thirteen root-server names answer from nearly two thousand machines, because a name is not a box.
  • ▸Ask the same name twice and the second answer skips every server the first visited, until a countdown ends.
BUILDS ON
01

The stub asks one server

cat /etc/resolv.conf on your laptop prints a line or two, and one of them is nameserver, followed by an IP such as 1.1.1.1, or 127.0.0.53 for a local forwarder that passes the query on (glibc reads up to three such lines and tries them in order). Those are the only DNS addresses your machine holds. The small piece of the system that programs call to turn a name into an address, the stub resolver, does not know the root of the naming system, does not know who runs .com, does not know anything except those servers.

So when curl example.com needs an address, the stub sends its questions (curl asks for both A and AAAA, the IPv4 and IPv6 address records) to the first server on the list and blocks, waiting for the finished answer. Its query carries a bit named RD, Recursion Desired, which means you do the legwork and hand me back an IP.

The server it asks is a recursive resolver, and the whole rest of this topic is what that recursive does while your stub sits and waits.

WRITE THE STUB'S RESOLV.CONF

Keep going, sign up to unlock the rest

3 more parts in this topic, plus 23+ more topics in HTTP & Networking.

Sign up, it's freeSee the full HTTP & Networking