How DNS turns a name into an address

· 2 min read

#how-it-works#networking

DNS is the system that turns a name like example.com into an IP address. The one idea to keep: nobody knows every answer, but everyone knows who to ask next.

The short version

Names form a tree, with the root at the top. Your device asks a resolver. The resolver asks a server near the top, gets pointed down the tree, and repeats until a server that owns the name gives the address.

A resolver walking down the DNS tree The browser asks the resolver. The resolver asks a root server, then a top-level domain server, then an authoritative server, and returns the answer to the browser. Browser Resolver Root server .com server Authoritative server 1 2 3 4 5 answer
Numbers show the order. Solid arrows are questions; the dashed arrow is the final answer.

Step by step

  1. Your browser asks a resolver for the address of example.com.
  2. The resolver asks a root server. It replies with a referral to the servers for .com.
  3. The resolver asks a .com server, which refers it to the servers that hold example.com.
  4. The resolver asks one of those servers, which answers with an A record: a 32-bit IPv4 address.
  5. The resolver caches the answer for the record's TTL and returns it to the browser.

Why it matters

The TTL is why a DNS change can take time to show up: cached copies stay valid until they expire. In practice the resolver often skips steps 2 and 3, because it already knows the closest servers.

Sources