How DNS works

What DNS solves

See DNS as the distributed system that lets a stable domain name point to services whose addresses can change.

You never type an IP address to open a website. You type a name, like flaviocopes.com. Something has to turn that name into an address a computer can connect to. That something is the Domain Name System, or DNS.

Think of DNS as a huge, distributed directory. You ask it a precise question and it gives you back a precise answer. “Which IPv4 addresses belong to this hostname?” “Which servers accept email for this domain?”

The record type is part of the question

This is the first thing to get right. You don’t ask DNS “tell me about flaviocopes.com”. You ask for one record type at a time.

Let’s ask three different questions about the same domain:

dig A flaviocopes.com
dig AAAA flaviocopes.com
dig MX flaviocopes.com

A asks for IPv4 addresses. AAAA asks for IPv6 addresses. MX asks where email for the domain should be delivered.

These are three separate lookups. A good answer to one says nothing about the other two. A domain can have a working website and no AAAA record at all, and that’s fine.

Who answers the question

Your laptop doesn’t go looking for the answer itself. It sends the question to a recursive resolver. That’s a server run by your ISP, your company, or a public provider like Cloudflare’s 1.1.1.1.

The resolver does the legwork. It finds the server that holds the official data (the authoritative server), gets the answer, and caches it for a while. The next person asking the same question gets the cached copy.

This split is why DNS scales. No single server knows every record, and the authoritative servers don’t get hit by every browser on the planet.

Why a name matters

A name separates what a service is from where it currently lives. When I move this site to a new server, I change one DNS record. I don’t tell every reader a new address.

What DNS does not do

DNS only gives you naming information. Getting an address back doesn’t open a TCP connection, negotiate TLS, or fetch a web page. All of that happens after DNS, and each step can fail while DNS is perfectly healthy.

Keep that in mind. Half of the “DNS problems” I’ve seen were something else.

Try this now: run the three dig commands above on a domain you use. Note which ones return records. Then ask yourself why an empty AAAA answer doesn’t mean the domain is broken.

Lesson completed