Computers talk to each other with IP addresses, people prefer names. The Domain Name System (DNS) is the distributed directory that connects them.
The cast
- Stub resolver: the small client in your operating system that asks for an answer.
- Recursive resolver: a server, often run by your network or a public provider, that does the searching on your behalf and caches results.
- Authoritative server: the server that holds the real records for a domain.
Resolving a name
When your browser needs www.example.com and nothing is cached:
- The recursive resolver asks a root server, which does not know the answer but points to the servers for the
.comzone. - A .com server points to the authoritative servers for
example.com. - The authoritative server returns the address for
www.example.com. - The resolver caches the answer and returns it to you.
The whole chain usually takes a few milliseconds to a couple of hundred, and later lookups are served from cache.
Common record types
- A / AAAA: name to an IPv4 / IPv6 address.
- CNAME: an alias to another name.
- MX: mail servers for the domain.
- TXT: free text, used for email authentication and domain verification.
- NS: the authoritative name servers.
Caching and TTL
Each record has a time to live in seconds, which tells caches how long they may keep it. A long TTL reduces load and speeds up lookups. A short TTL lets changes spread quickly, which is why people lower it before a planned migration and raise it again afterwards. After a change, some users may still see the old value until their cached copy expires.
Debugging
dig example.com A +short # what address does it resolve to?
dig example.com NS +short # who is authoritative?
dig @1.1.1.1 example.com A # ask a specific resolver
dig +trace example.com # follow the delegation from the rootCompare answers from your resolver and from the authoritative server to tell whether the problem is the record or a stale cache.
Takeaway
DNS is a hierarchy of delegations with caching at every level. When something is wrong, check the record, its TTL and which resolver you asked.
Comments