How DNS works, end to end

DNS turns a name like example.com into the address of your server by asking a chain of servers: your resolver asks a root server, then the top-level domain servers, then the authoritative servers for the domain, and caches the answer for the record's TTL. Once you understand that chain, almost every DNS problem can be traced with one command, dig +trace.

Networking and security guide, updated 2026-12-03

What happens when someone types your domain?

A browser asks the operating system for the address of www.example.com. The system passes the question to a recursive resolver, run by the visitor's ISP, a public service or the visitor themself. If the resolver has a cached answer, it replies at once. If not, it walks the tree:

  1. It asks a root server, which answers: ask the servers for .com.
  2. It asks a TLD server for .com, which answers: the authoritative servers for example.com are these NS records.
  3. It asks one of those authoritative servers, which returns the actual record, for example an A record with 203.0.113.10.

The resolver caches each step and sends the answer back. The browser then connects to the address. All of this usually takes a few milliseconds when cached and tens of milliseconds when not.

Registrar or DNS host: who does what?

Two roles are often confused because one company may do both:

  • The registrar is where you bought the domain. It tells the TLD registry which name servers are authoritative for your domain. That is the NS delegation.
  • The DNS host runs those name servers and stores your records: A, AAAA, MX and the rest.

Changing records happens at the DNS host. Changing which company hosts DNS happens at the registrar, by updating the name servers. Mixing these up is the most common reason that a record "does not work": it was added at a provider that is not authoritative for the domain. Check which servers are in charge with dig NS example.com +short.

You can also host DNS yourself on a server, but two independent name servers in different networks are the minimum for reliability, so most people use their DNS provider. The steps for pointing a domain here are in pointing a domain to your server.

Which record types do you actually need?

TypePurposeExample value
AName to IPv4 address203.0.113.10
AAAAName to IPv6 address2001:db8:1234:5678::1
CNAMEAlias to another nameexample.com.
MXMail servers for the domain, with priority10 mail.example.com.
TXTFree text: SPF, DKIM, DMARC, verificationv=spf1 mx -all
CAAWhich certificate authorities may issue0 issue "letsencrypt.org"
NSAuthoritative name serversns1.example.net.
PTRAddress back to name (reverse DNS)mail.example.com.

A CNAME cannot sit at the zone apex (example.com itself) next to other records, and it cannot share a name with an MX or TXT record. Use A and AAAA at the apex. An MX record must point to a name with A or AAAA records, never directly to an IP or to a CNAME. PTR records live in the reverse zone, which is set by support; see reverse DNS.

How do SPF, DKIM, DMARC and CAA records work?

These are ordinary TXT or CAA records with a special meaning:

  • SPF (TXT on the domain) lists which servers may send mail for it: v=spf1 ip4:203.0.113.10 ip6:2001:db8:1234:5678::/64 -all.
  • DKIM (TXT at selector._domainkey.example.com) publishes the public key that verifies signatures your mail server adds.
  • DMARC (TXT at _dmarc.example.com) tells receivers what to do when SPF and DKIM fail, and where to send reports: v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com.
  • CAA limits which certificate authorities may issue for the domain. If you use Let's Encrypt, 0 issue "letsencrypt.org" allows it and blocks others.

Check each with dig TXT _dmarc.example.com +short or dig CAA example.com +short.

What does TTL control?

Every record carries a TTL in seconds. A resolver that fetched the record may serve it from cache until the TTL runs out, then must ask again. Typical values are 300 (five minutes) for records you may change soon and 3600 or 86400 for stable ones.

The TTL that matters for a change is the old one, because it decides how long caches keep the old answer. Plan moves like this:

  1. A day ahead, lower the TTL of the record to 300.
  2. Wait at least one full old TTL so every cache picks up the short value.
  3. Change the record. Caches update within five minutes.
  4. When everything is stable, raise the TTL again.

Negative answers are cached too: if someone looked up a name before it existed, the "does not exist" reply is kept for the time set in the SOA record of the zone, often up to an hour.

Is DNS propagation real?

Not in the sense people often imagine. Nothing is pushed around the internet. When you change a record, the authoritative servers serve the new value immediately (after the DNS host has published it, which takes seconds to a few minutes). What lags behind is caching: resolvers that saw the old record keep it until its TTL expires.

Two exceptions take longer. A change of name servers at the registrar depends on the NS TTL at the TLD, which is often 48 hours or more. And a few resolvers ignore low TTLs and keep records longer than they should. Neither is fixed by waiting for "propagation" to finish everywhere; it is fixed by checking the authoritative servers directly, which tells you the truth right away.

How do you debug DNS with dig?

dig is the main tool. Install it with apt install bind9-dnsutils on Ubuntu and Debian or dnf install bind-utils on Rocky, Alma and Fedora.

# what your resolver returns
dig example.com A +short

# ask the authoritative server directly, skipping caches
dig example.com A @ns1.example.net +short

# follow the whole chain from the root
dig example.com A +trace

# show TTL left in the cache
dig example.com A +noall +answer

+trace prints each step: root servers, TLD servers, the NS delegation and the final answer. If the delegation points to name servers you did not expect, fix it at the registrar. If the authoritative answer is correct but your resolver shows the old one, it is cache and the TTL tells you how long it will last. A SERVFAIL status often means a DNSSEC problem; try dig +cd to check without validation and compare.

How do you run your own resolver with Unbound?

A local caching resolver makes lookups on your server fast and independent of outside resolvers, and it validates DNSSEC. Unbound is a small, well-tested choice. On Ubuntu 24.04 or Debian 13:

apt install unbound
cat > /etc/unbound/unbound.conf.d/local.conf <<EOF
server:
    interface: 127.0.0.1
    interface: ::1
    access-control: 127.0.0.0/8 allow
    access-control: ::1/128 allow
    prefetch: yes
EOF
unbound-checkconf
systemctl restart unbound
dig @127.0.0.1 example.com +short

On Ubuntu, systemd-resolved already holds port 53 on 127.0.0.53, not 127.0.0.1, so both can run. Point resolved at Unbound by setting DNS=127.0.0.1 and DNSStubListener=yes in /etc/systemd/resolved.conf, then systemctl restart systemd-resolved. On Rocky and Alma use dnf install unbound; the config lives in /etc/unbound/unbound.conf.

Keep the resolver bound to localhost. An open resolver on a public address gets abused for amplification attacks within days.

Questions about this guide

How long does a DNS change take?

A record change is visible as soon as the old TTL runs out in each cache. A name server change at the registrar can take up to two days because of the TLD TTL.

Can I use a CNAME for my root domain?

Not in standard DNS. Use A and AAAA records at the apex. Some DNS providers offer flattening features, which return addresses but are not real CNAMEs.

Where do I set reverse DNS?

Not at your DNS provider. Reverse DNS for your server address is set by support; see reverse DNS.

Why does my site work on my phone but not on my laptop?

Different resolvers cache different answers. Flush the local cache (resolvectl flush-caches on Linux) or check the authoritative server with dig @ns1....

Should I run an authoritative DNS server on my VPS?

You can, with software such as BIND, Knot or PowerDNS, but you need at least two servers in separate networks. For most domains, your DNS provider is simpler.

Does Unbound need a lot of memory?

No. A default install uses a few tens of MB and runs fine on the smallest plan, P1.