Sub topic 1
How DNS Resolution Works
Prerequisites
Assume you are comfortable with a Linux shell, IP addresses, UDP and TCP ports, and basic systemd service management. You should also know that a DNS name, such as www.example.com, maps to information such as an IP address.
DNS is a distributed naming system. It stores information in zones, which are administrative parts of the DNS namespace. No single server normally stores every name. Instead, servers cooperate to find an answer.
The resolution path
A client first sends a query to a recursive resolver. The client is often a stub resolver provided by the operating system. A recursive resolver finds the answer for the client, follows referrals, and caches the result.
For www.example.com, the resolver commonly works through these steps:
- It checks its cache. If a valid cached record exists, it returns that record immediately.
- It asks a root server for information about
.com. - The root server returns a referral to the
.comtop-level domain servers. - The resolver asks a
.comserver forexample.com. - The
.comserver returns a referral to the authoritative servers forexample.com. - The resolver asks one of those authoritative servers for
www.example.com. - The authoritative server returns the record, such as an A record containing an IPv4 address.
- The resolver caches the response for the record's time to live, or TTL, and sends it to the client.
The resolver's queries after the first one are iterative: each server gives the resolver the best information it has, and the resolver decides what to ask next. The client's query to the recursive resolver is recursive because the client expects the resolver to complete the lookup.
Server roles
The same software can sometimes perform multiple roles, but separating roles reduces risk and simplifies troubleshooting.
| Role | Main responsibility | Typical response |
|---|---|---|
| Recursive resolver | Finds answers for allowed clients | Cached or newly resolved records |
| Authoritative server | Publishes records for its zones | Answers from its zone data |
| Forwarder | Sends queries to another resolver | Response received from an upstream server |
An authoritative server does not need to contact the root servers for names inside its own zones. It answers from its zone files. A recursive resolver should be restricted to trusted networks. An unrestricted recursive resolver can be abused for reflection attacks and consumes resources for unknown clients.
Caching and TTL
Each resource record includes a TTL in seconds. The resolver can reuse a cached answer until the TTL expires. A short TTL allows changes to spread faster but increases query traffic. A long TTL reduces traffic but keeps old data available longer after a change.
Exercise
Exercise
Which server should a client normally query, and which server owns the final answer for a domain?
Show answer
The client normally queries a recursive resolver. The authoritative server for the domain's zone owns the final answer.