Skip to main content
Foundations: web, servers, containersLesson 3 of 13

How DNS Finds an Address

When You Type an Address showed DNS as one box that turns a name into an IP. Here we open that box: who asks whom, why answers are cached, and why a DNS change takes time to show up. Name lookups inside a cluster continue in Finding Services by Name.

Questionwww.example.com A
Answer—
TTL—
Response code—
Your computerDNS hierarchy on the internetBrowserNeeds an IPStub resolverOS · /etc/hostsRecursive resolverISP · 8.8.8.8 · cacheRoot serverZone "."TLD serverZone .comAuthoritativeZone example.comwww.example.com?
RequestResponse / reportAppears in a later step

What you will learn

  • Where the OS looks first: /etc/hosts and /etc/resolv.conf
  • Recursive resolver vs root, TLD and authoritative servers
  • Why every answer is cached for its TTL
  • Why a record change takes time to reach everyone
  • NXDOMAIN, SERVFAIL and a timeout point to different problems

Records you will see​

TypeHoldsExample
AAn IPv4 addresswww.example.com. 300 IN A 203.0.113.10
AAAAAn IPv6 addresswww.example.com. 300 IN AAAA 2001:db8::10
CNAMEAn alias to another name. A name with a CNAME cannot hold other records, so it cannot sit at the zone apexshop.example.com. CNAME lb-123.example.net.
MXMail servers for the domain, with a preference numberexample.com. MX 10 mail.example.com.
TXTFree text, used for SPF, domain ownership checks and moreexample.com. TXT "v=spf1 -all"
NSThe authoritative name servers for a zoneexample.com. NS ns1.example.net.
SOAZone metadata, including the negative-caching TTLexample.com. SOA ns1... hostmaster...

Response codes​

CodeMeaningLook at
NOERROR with answersSuccess—
NOERROR, no answers (NODATA)The name exists but has no record of this type (for example AAAA only)The record type you asked for
NXDOMAINThe name does not exist in the zoneSpelling, the zone file, recent creation (negative cache)
SERVFAILThe resolver could not get a valid answerAuthoritative servers up, delegation (NS) correct, DNSSEC valid
REFUSEDThe server will not answer you (policy)Whether you are allowed to use that resolver
Timeout (no reply)Nothing came backFirewall on UDP/TCP 53, the nameserver in resolv.conf

Try it yourself​

cat /etc/resolv.conf # Which resolver the stub asks, plus search/options
getent hosts www.example.com # Resolve the way apps do (includes /etc/hosts)
dig www.example.com # status:, flags, ANSWER section and TTL
dig +trace www.example.com # Walk root → TLD → authoritative yourself
dig @8.8.8.8 www.example.com +short # Ask a specific resolver
dig @1.1.1.1 www.example.com +short # Compare caches between resolvers
dig example.com NS +short # Who is authoritative
dig example.com SOA # Last field is the negative-caching MINIMUM
dig wwww.example.com | grep status # NXDOMAIN
nslookup www.example.com # Available almost everywhere, including Windows

Run dig www.example.com twice against the same resolver and watch the TTL go down. That is the cache.

Check yourself

  1. You changed an A record from .10 to .20 an hour ago, yet some users still reach the old server. Why?
  2. A lookup returns SERVFAIL. What does that tell you?
  3. A user typed a name before you created its record, got NXDOMAIN, and still gets NXDOMAIN after you create it. What explains this?

Further reading: RFC 1034: Domain Concepts · RFC 2308: Negative Caching · Root servers (IANA) · resolv.conf(5) · DNS (MDN glossary) · When You Type an Address · Finding Services by Name