Skip to content

Computing foundations · Part 1 of 10

How DNS works: from a name to an address

DNS translates names such as example.com into IP addresses through a hierarchy of servers and caches. Records, TTLs and how to debug it.

· 2 min read

networkingdns

Computers talk to each other with IP addresses, people prefer names. The Domain Name System (DNS) is the distributed directory that connects them.

The cast

  • Stub resolver: the small client in your operating system that asks for an answer.
  • Recursive resolver: a server, often run by your network or a public provider, that does the searching on your behalf and caches results.
  • Authoritative server: the server that holds the real records for a domain.

Resolving a name

When your browser needs www.example.com and nothing is cached:

  1. The recursive resolver asks a root server, which does not know the answer but points to the servers for the .com zone.
  2. A .com server points to the authoritative servers for example.com.
  3. The authoritative server returns the address for www.example.com.
  4. The resolver caches the answer and returns it to you.

The whole chain usually takes a few milliseconds to a couple of hundred, and later lookups are served from cache.

Common record types

  • A / AAAA: name to an IPv4 / IPv6 address.
  • CNAME: an alias to another name.
  • MX: mail servers for the domain.
  • TXT: free text, used for email authentication and domain verification.
  • NS: the authoritative name servers.

Caching and TTL

Each record has a time to live in seconds, which tells caches how long they may keep it. A long TTL reduces load and speeds up lookups. A short TTL lets changes spread quickly, which is why people lower it before a planned migration and raise it again afterwards. After a change, some users may still see the old value until their cached copy expires.

Debugging

shell
dig example.com A +short          # what address does it resolve to?
dig example.com NS +short         # who is authoritative?
dig @1.1.1.1 example.com A        # ask a specific resolver
dig +trace example.com            # follow the delegation from the root

Compare answers from your resolver and from the authoritative server to tell whether the problem is the record or a stale cache.

Takeaway

DNS is a hierarchy of delegations with caching at every level. When something is wrong, check the record, its TTL and which resolver you asked.

A knowledge article, drafted with AI assistance and checked with automated tests. It is general background, not a description of my own experience or of any client's work.

Comments

Leave a comment

No account or email needed. Comments appear after review. A one-way hash of your IP address is kept for 30 days to fight spam, then erased.