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—
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
| Type | Holds | Example |
|---|---|---|
| A | An IPv4 address | www.example.com. 300 IN A 203.0.113.10 |
| AAAA | An IPv6 address | www.example.com. 300 IN AAAA 2001:db8::10 |
| CNAME | An alias to another name. A name with a CNAME cannot hold other records, so it cannot sit at the zone apex | shop.example.com. CNAME lb-123.example.net. |
| MX | Mail servers for the domain, with a preference number | example.com. MX 10 mail.example.com. |
| TXT | Free text, used for SPF, domain ownership checks and more | example.com. TXT "v=spf1 -all" |
| NS | The authoritative name servers for a zone | example.com. NS ns1.example.net. |
| SOA | Zone metadata, including the negative-caching TTL | example.com. SOA ns1... hostmaster... |
Response codes
| Code | Meaning | Look at |
|---|---|---|
| NOERROR with answers | Success | — |
| NOERROR, no answers (NODATA) | The name exists but has no record of this type (for example AAAA only) | The record type you asked for |
| NXDOMAIN | The name does not exist in the zone | Spelling, the zone file, recent creation (negative cache) |
| SERVFAIL | The resolver could not get a valid answer | Authoritative servers up, delegation (NS) correct, DNSSEC valid |
| REFUSED | The server will not answer you (policy) | Whether you are allowed to use that resolver |
| Timeout (no reply) | Nothing came back | Firewall 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
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