DNS explained properly

What actually happens between typing a domain name and the page appearing — resolution, record types, time to live, and why “it hasn’t propagated yet” is a poor explanation.

6 min readBy Valentin Flückiger

DNS is the system most often blamed for an outage, and least often understood by those blaming it. "It's always DNS" became an operations joke precisely because it is true often enough to be irritating.

Here is what actually happens, and why some common explanations are wrong.

The problem DNS solves

Machines reach each other by IP address. Humans remember names. DNS is the directory translating the latter into the former.

But it is a directory of a peculiar kind: it does not exist anywhere in full. There is no central file containing every domain name in the world. The system is distributed, hierarchical, and each part knows only about the next one.

One resolution, step by step

You type example.com. Here is what happens, assuming no cache holds the answer.

1. The resolver. Your machine asks a recursive resolver — your provider's, or a public service. It does the work; your machine only asks the question.

2. The root. The resolver asks the root servers: "who handles .com?" The root does not know example.com. It only knows who runs each top-level domain.

3. The TLD. The .com servers answer: "for example.com, ask these name servers." They do not know the final address either.

4. The authoritative server. Those servers know the answer, because you put it there. They reply: example.com → 203.0.113.10.

5. The cache. The resolver keeps the answer for a duration stated in the record, and serves it directly to subsequent queries.

The whole trip takes a few dozen milliseconds. And it happens once: after that, everyone reads the cache.

The records worth knowing

A maps a name to an IPv4 address. AAAA does the same for IPv6. These are the two fundamental records.

CNAME says "this name is an alias for that other name". Useful for pointing www at the main name. Careful: a CNAME cannot coexist with other records on the same name, which in principle forbids putting one on the apex domain.

MX states which servers receive the domain's mail, with a priority: the lowest number is tried first.

TXT holds free text. It has become DNS's catch-all: domain ownership validation, and above all the three records that protect your mail.

NS designates the authoritative servers for the zone. It is the record that delegates.

CAA declares which certificate authorities may issue a certificate for your domain. Underused, useful.

The three records that protect mail

If you send mail from your domain, these are not optional — without them your messages land in spam, or do not arrive.

SPF lists the servers allowed to send mail on your behalf. One SPF record per domain: having two invalidates both.

DKIM cryptographically signs each message. The recipient verifies the signature using the public key published in your DNS.

DMARC tells recipients what to do when SPF and DKIM fail, and where to send reports. Start in none mode to observe, then tighten.

Time to live, and the propagation myth

Every record carries a time to live: how long a resolver may keep the answer cached.

That is where "you have to wait for it to propagate" comes from. It describes what happens badly.

DNS does not propagate. Nothing is pushed out to the world's resolvers. Your authoritative servers have the new value immediately. What takes time is existing caches expiring — each on its own schedule, depending on when it asked.

The practical consequence matters: the time to live that counts is the one in place before your change, not the one you just set. If the old record had a 24-hour TTL, some resolvers will hold the old address for 24 hours, whatever you do afterwards.

The correct migration procedure

  1. A few days ahead, lower the TTL to 300 seconds. Wait for the old TTL to expire everywhere.
  2. On the day, change the record. Caches expire within five minutes.
  3. Keep the old server running for at least 24 hours. Badly behaved resolvers ignore short TTLs, and browsers have caches of their own.
  4. A few days later, raise the TTL back to a normal value.

Skipping step 1 is the most common mistake, and it is what turns a migration into half a day of downtime for a fraction of visitors.

Diagnosing

The most useful reflex: query the authoritative server directly, to separate a configuration problem from a caching one.

# What an ordinary resolver sees
dig example.com A +short

# What the source of authority says, with no cache in between
dig @ns1.example.com example.com A

# The full delegation path, step by step
dig example.com +trace

# Who handles mail
dig example.com MX +short

If the authoritative server answers correctly but your machine sees something else, it is a cache. If the authoritative server answers wrongly, it is your configuration — and waiting will not help.

A diagnostic trap

On some networks, outbound port 53 is filtered. dig then returns silence for every query, including ones that should work. If nothing answers, first check that you can reach a resolver at all, before concluding the domain is broken. I lost time to exactly this.

DNSSEC, in two paragraphs

Classic DNS is not authenticated: an answer that arrives is taken at face value. That enables cache poisoning, where an attacker slips in a forged answer that a resolver then remembers.

DNSSEC cryptographically signs records. A validating resolver verifies the signature and rejects anything that does not match. The chain of trust starts at the root, descends to your zone, and each level signs the next.

Two things to know before enabling it:

It is a chain, and it can break. If your signatures expire, or the delegation at the registry no longer matches your keys, your domain becomes entirely unresolvable for every validating resolver. Not slow: invisible. That is a harsher outage than not having DNSSEC at all.

It does not prevent reading. DNSSEC authenticates, it does not encrypt. Queries remain visible on the network. DNS-over-TLS and DNS-over-HTTPS address confidentiality, and those are separate problems.

If your registrar offers DNSSEC with automatic key management, that is a good compromise. Managing it by hand demands real discipline about renewals.

One domain, several environments

A habit that prevents accidents: keep the names firmly separate.

example.com             production
staging.example.com     staging, with indexing disallowed
dev.example.com         development, often restricted by address

Two precautions that matter:

Disallow indexing of test environments. A robots.txt refusing everything, and an X-Robots-Tag: noindex header. An indexed staging site creates duplicate content and, sometimes, publishes things that were not meant to be public.

Never point a test environment at the production database. It sounds obvious, and yet it is one of the most frequent causes of accidental data loss.

Classic mistakes

Forgetting the AAAA record. An IPv6-only visitor will not reach you, and you will never know — they see an error, you see normal statistics.

Putting a CNAME on the apex domain. Technically forbidden. Some providers offer a proprietary workaround; use it knowing that is what it is.

Having two SPF records. The specification allows one. Two invalidate the check, and your mail goes to spam.

Name servers at the same provider as your hosting. If the provider goes down, the domain becomes unresolvable at the same moment the site does. Separating them is cheap diversification.

Forgetting to renew the domain. Trivial, devastating, and entirely avoidable with auto-renewal and a contact address you actually read.

What to take away

DNS is distributed, hierarchical and cached at every level. Nothing is pushed: everything expires. Time to live is prepared before a change, not during one. And when something looks inconsistent, query the authoritative server directly — it is the only way to tell what is misconfigured from what is merely still cached.

Tags

  • Hosting
  • Networking
  • Security