Skip to content
Visual explainer 3h 30m to learn 5 steps

DNS: hierarchy, resolution & records

Trace a DNS lookup from stub resolver to authoritative server and choose the right record types.

By Invicly Tech, , in Computer Networking. About 12 minutes to read.

Topic 25 of 51

In short

DNS translates names like www.example.com into IP addresses and other records. Your device asks a recursive resolver, which walks the hierarchy from the root servers to the top-level domain servers to the domain's authoritative servers, then caches the answer for its TTL. Nearly every connection starts with a DNS lookup, so DNS faults look like everything is down.

Think of it like this: A library catalogue: the resolver asks the main desk, then the right floor, then the right shelf.

Explained simply

Computers talk using numbers called IP addresses, but people remember names like www.example.com. DNS (the Domain Name System) is the internet's phone book. You give it a name, and it gives back the number, plus other facts such as which server handles email for that name.

No single computer knows every name. The job is split up like a tree. The root servers know who runs .com, .org and the other endings. The .com servers know who runs example.com. Only example.com's own servers (the authoritative servers) know the real answer for www.example.com.

Your laptop does not walk that tree itself. It asks one helper, the recursive resolver, usually run by your company, your internet provider, or a public service like 1.1.1.1 or 8.8.8.8. The resolver does the walking, then remembers (caches) the answer so the next person gets it instantly.

Every answer comes with a TTL (time to live), a number of seconds the answer may be remembered. A long TTL means fewer lookups and faster sites. A short TTL means changes spread quickly. Choosing the TTL is the main trade-off you control as a DNS owner.

Press Play on a diagram to walk through it one step at a time.

SequenceResolving www.example.com (cold cache)
Client
Recursive resolver
Root / TLD servers
Authoritative server
  1. 1A record for www.example.com?
    Client to Recursive resolver: A record for www.example.com?
  2. 2Ask root: referral to .com servers
    Recursive resolver to Root / TLD servers: Ask root: referral to .com servers
  3. 3Ask .com: referral to example.com name servers
    Recursive resolver to Root / TLD servers: Ask .com: referral to example.com name servers
  4. 4Ask authoritative for www.example.com
    Recursive resolver to Authoritative server: Ask authoritative for www.example.com
  5. 5Answer: A 93.184.215.14, TTL 3600
    Authoritative server to Recursive resolver: Answer: A 93.184.215.14, TTL 3600
  6. 6Answer, now cached
    Recursive resolver to Client: Answer, now cached
MapDNS hierarchy
. (root)
  • com
    • example.com
    • www.example.com
  • org
    • wikipedia.org
  • uk
    • co.uk
    • bbc.co.uk
LayersCaches a lookup passes through
  1. 1
    Application

    Browsers keep their own short DNS cache

  2. 2
    Operating system

    systemd-resolved or the Windows DNS client

  3. 3
    Home or office router

    Often a small forwarding cache

  4. 4
    Recursive resolver

    ISP, company or public, a large shared cache

  5. 5
    Authoritative servers

    The source of truth, never a cache

In depth

What is inside a DNS message

A DNS query and its reply use the same format: a 12-byte header, then the question, answer, authority and additional sections. The header holds an ID (to match replies to questions) and flags. RD (recursion desired) is set by clients asking a resolver to do the full job. RA means the server offers recursion. AA (authoritative answer) means the reply came from the zone's own server, not a cache. TC (truncated) means the answer did not fit in UDP and the client should retry over TCP.

The reply also carries a status code (RCODE). NOERROR with an empty answer means the name exists but has no record of that type. NXDOMAIN means the name does not exist at all. SERVFAIL means the resolver could not get a good answer, often because the authoritative servers are down or DNSSEC validation failed.

  • NOERROR: success (answer may still be empty)
  • NXDOMAIN: no such name
  • SERVFAIL: resolver failed upstream
  • REFUSED: server will not answer you

Delegation and glue records

A zone hands part of the tree to someone else with NS records. The .com zone contains NS records for example.com that say: ask ns1.example.net or ns2.example.net. This hand-off is a referral, and the resolver follows it.

There is a chicken-and-egg problem when the name servers live inside the zone they serve, such as ns1.example.com for example.com. To find ns1.example.com you would need to ask example.com, which you cannot reach yet. The fix is glue: the parent zone also stores the A and AAAA addresses of those name servers and returns them in the additional section of the referral.

The SOA (start of authority) record at the top of every zone names the primary server, a serial number that secondaries watch for changes, and the negative-caching TTL used for NXDOMAIN answers.

FlowHow a resolver follows referrals
  1. 1
    Ask a root server

    Reply: NS records for com, with glue

  2. 2
    Ask a .com server

    Reply: NS records for example.com

  3. 3
    Ask example.com NS

    Reply has the AA flag: the real answer

  4. 4
    Cache by TTL

    Each record is kept for its own TTL

  5. 5
    Answer the client

    Later clients get the cached copy

Record types you will really use

Beyond A and AAAA, a handful of types cover almost every job. CNAME makes one name an alias of another; it cannot sit next to other records on the same name, so it is not allowed at the zone apex (example.com itself). Many DNS providers offer ALIAS or flattened records to get the same effect at the apex. MX lists mail servers with a preference number, where lower is tried first. TXT holds free text, used for SPF, DKIM, DMARC and domain ownership checks. NS names the zone's servers. PTR maps an address back to a name for reverse lookups, under in-addr.arpa for IPv4 and ip6.arpa for IPv6.

Newer types matter too. CAA says which certificate authorities may issue certificates for your domain. SRV gives host and port for a service. HTTPS (and SVCB) records can advertise HTTP/3 support and alternative endpoints in one lookup.

  • MX 10 mx1.example.com is tried before MX 20 mx2.example.com
  • CAA 0 issue "letsencrypt.org" limits who issues certificates
  • dig -x 192.0.2.10 does a PTR lookup

Caching, TTLs and planning a change

Every resolver along the way caches answers: the public resolver, your router, and the operating system (systemd-resolved on many Linux systems). Negative answers are cached too, for the time given in the zone's SOA record, so a typo that returned NXDOMAIN can linger even after you add the record.

To move a website to a new IP with little pain, lower the TTL a day or two before the move, for example from 3600 to 300 seconds. Wait at least the old TTL so every cache picks up the short value. Make the change, check it, and raise the TTL again once you are happy. Some resolvers apply a minimum TTL or ignore very low values, so plan for a few stragglers.

DNS normally runs on UDP port 53, and EDNS(0) lets replies be larger than the old 512-byte limit. Zone transfers (AXFR) and truncated answers use TCP port 53, so firewalls must allow both.

Private and secure DNS

Classic DNS is not encrypted, so anyone on the path can read or change answers. Two kinds of protection exist and they solve different problems.

DNSSEC signs records. The zone publishes DNSKEY records and RRSIG signatures, and the parent zone publishes a DS record that vouches for the child's key, building a chain of trust from the root. A validating resolver can then prove an answer was not forged. DNSSEC does not hide your queries.

Encrypted transports hide queries from the local network: DNS over TLS (DoT) uses TCP port 853, and DNS over HTTPS (DoH) uses port 443 like normal web traffic. They protect the link between you and the resolver, but the resolver still sees everything you look up, so choose one you trust.

CompareDNSSEC versus encrypted DNS
DNSSEC
  • Signs the records
  • Proves answers are genuine
  • Queries still visible
  • Set up by the zone owner
DoT and DoH
  • Encrypts the transport
  • Hides queries from the local network
  • Resolver still sees them
  • Set up on the client and resolver

Learn it in 5 short steps

About 40m each. Track them with a timer in your plan.

  1. 1
    Explain root, TLD and authoritative servers~40m
  2. 2
    Trace recursive and iterative resolution~40m
  3. 3
    Use A, AAAA, CNAME, MX, TXT, NS~40m
  4. 4
    Explain TTLs and caching~40m
  5. 5
    Query records with dig~40m

Key points

  • A maps to IPv4, AAAA to IPv6, CNAME to another name, MX to mail servers, NS to name servers, TXT to text.
  • TTL controls how long resolvers cache an answer; lower it before migrations.
  • Clients do recursive queries; resolvers do iterative ones.
  • DNS uses UDP port 53, falling back to TCP for large responses.

Key terms

Tap a card to flip it. 0/5 known

Examples

bash
dig www.example.com A +short
dig example.com MX +short
dig @1.1.1.1 example.com AAAA
dig +trace www.example.com      # follow root, TLD, authoritative
dig -x 8.8.8.8 +short           # reverse lookup (PTR)

Finding out why a new subdomain does not resolve

You added api.example.com an hour ago, but some users get errors. Step 1: ask the authoritative server directly. If it answers, your zone is fine. Step 2: ask the public resolvers. If they return NXDOMAIN, they cached the negative answer from before you created the record. Step 3: check the SOA record; its last number is the negative-caching time. Waiting that long (or flushing the resolver cache if you run it) fixes it.

bash
dig NS example.com +short
# ns1.dnshost.net.
dig @ns1.dnshost.net api.example.com A +norecurse
# flags: qr aa  -> authoritative answer exists
dig @8.8.8.8 api.example.com A | grep status
# status: NXDOMAIN  -> cached negative answer
dig example.com SOA +short
# ns1.dnshost.net. admin.example.com. 2026111001 7200 3600 1209600 3600

Moving a site with almost no downtime

The site at www.example.com moves from 203.0.113.10 to 198.51.100.20. Two days before: change the TTL on the A record from 86400 to 300. Wait one full day so old caches expire. Move day: start the new server, change the A record, and keep the old server running and redirecting for a day. Check from several resolvers that the new IP and the short TTL appear. After a week, raise the TTL back to 3600 or more.

bash
dig www.example.com A +noall +answer
# www.example.com. 86400 IN A 203.0.113.10   (before)
# ...lower TTL, wait, change record...
for r in 1.1.1.1 8.8.8.8 9.9.9.9; do
  dig @$r www.example.com A +noall +answer
done
# www.example.com. 300 IN A 198.51.100.20

Quick reference

  • dig name type +short gives just the answer; +noall +answer shows the record with its TTL
  • dig @server name +norecurse asks one server only; an aa flag means it is authoritative
  • NXDOMAIN: name does not exist; NOERROR with no answer: name exists, but not that record type
  • DNS uses UDP 53 and TCP 53; DoT uses TCP 853; DoH uses 443
  • No CNAME at the zone apex; use your provider's ALIAS or flattening feature
  • Lower the TTL at least one old TTL before a migration, raise it again afterwards
  • Negative answers are cached for the time set in the zone's SOA record
  • resolvectl status (systemd) or cat /etc/resolv.conf shows which resolver you use

Common mistakes

  • Putting a CNAME at the zone apex alongside other records.
  • Changing records with a long TTL and expecting instant effect.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1A resolver returns SERVFAIL for a name that worked yesterday. What is a likely cause?

Question 2

2Why do glue records exist?

Question 3

3Which record tells certificate authorities whether they may issue a certificate for your domain?

Question 4

4What does DNS over HTTPS protect against?

Question 5

5MX 10 a.example.com and MX 20 b.example.com both exist. Which is tried first?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Find the name servers, mail servers and the IPv6 address (if any) for a domain you use every day.

  2. Exercise 2medium

    Prove whether an answer came from a cache or from the authoritative server, and watch the TTL count down.

  3. Exercise 3hard

    Walk the delegation of www.example.com by hand without +trace: ask a root server, then the TLD server it refers you to, then the authoritative server.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Why do DNS changes take so long to show up?
They do not travel anywhere; old answers simply stay in caches until their TTL runs out. Lowering the TTL before a change makes it appear faster.
Is 8.8.8.8 or 1.1.1.1 better than my ISP's resolver?
Public resolvers are often fast and support DNSSEC validation and encrypted DNS. The best choice depends on speed from your location and whose privacy policy you trust.
What is the difference between a recursive and an authoritative server?
An authoritative server holds the official records for its zones and answers only for them. A recursive resolver holds no zones of its own; it finds answers for clients and caches them.
How do I flush my DNS cache?
On Linux with systemd-resolved run resolvectl flush-caches, on Windows run ipconfig /flushdns, and on macOS run sudo dscacheutil -flushcache followed by sudo killall -HUP mDNSResponder.

Go deeper

ShareXLinkedInWhatsApp