Sub topic 1
How DNS works: resolvers, authoritative servers and TTL
Prerequisites
This chapter assumes you know the following:
- What an IP address and a port are.
- How to run commands in a terminal.
- That an AWS account exists and that you have seen the AWS Management Console.
You do not need any Route 53 experience. You do need dig, a DNS lookup tool. It is included in the bind-utils package on Amazon Linux and Fedora, in dnsutils on Debian and Ubuntu, and in macOS by default. On Windows, use WSL or nslookup.
The problem DNS solves
Computers connect to IP addresses such as 192.0.2.10. People use names such as www.example.com. The Domain Name System (DNS) is a distributed, hierarchical database that maps names to data, most often to IP addresses.
No single server holds the whole database. Responsibility is split into pieces called zones, and each zone is served by servers that are authoritative for it. That split is what lets the system scale to the whole internet. It also explains most DNS behavior you will meet later: delegation, caching and propagation delays.
The roles in a lookup
Four kinds of participants take part in a typical lookup.
| Role | What it does | Example |
|---|---|---|
| Stub resolver | A small client library in your operating system or application. It asks one configured resolver and waits for the final answer. | The resolver code in your laptop's OS |
| Recursive resolver | Does the work of finding the answer by querying other servers. It caches results. | Your ISP's resolver, a public resolver, or the Amazon-provided resolver inside a VPC |
| Authoritative name server | Holds the records for a zone and gives answers from its own data. It does not search elsewhere. | Route 53 name servers such as `ns-123.awsdns-45.com` |
| Root and TLD servers | Authoritative servers near the top of the hierarchy. They do not know your records. They know who to ask next. | The root zone, then `.com` |
"Recursive" describes the service the resolver provides to its client: "get me the final answer." "Authoritative" describes a server that is the source of truth for a zone. A server that is authoritative for a zone normally does not recurse for other names. Route 53 as a public DNS service is authoritative only.
Following one query
Suppose your laptop's cache is empty and you open www.example.com. The resolver has no cached data either.
The steps are:
- The stub resolver sends the question to the configured recursive resolver and waits.
- The recursive resolver asks a root server. Root servers are reachable through addresses built into the resolver software (the root hints). The root answers with a referral: the names and addresses of the
.comservers. - The resolver asks a
.comserver. That server answers with another referral: the name servers listed forexample.com. - The resolver asks one of those servers. Because it is authoritative, it replies with the record and a time to live.
- The resolver caches the record, returns it to the client, and serves later identical questions from cache until the TTL runs out.
A referral is not an answer. The server is saying "I don't know, but these servers are responsible for the next part of the name." Where the referral points is set by NS records, and in the registry's .com zone those NS records are exactly the name servers you give your registrar. That link is the delegation, covered in a later chapter.
Glue records
If the name servers for example.com are themselves inside example.com (for example ns1.example.com), the resolver would need example.com to find example.com. The parent zone breaks the loop by returning glue: the IP addresses of those name servers, included in the referral. Route 53 name servers live under awsdns domains outside your zone, so you do not need glue.
Seeing it with dig
dig +trace makes dig walk the hierarchy itself, starting at the root, instead of using your resolver's cache. It prints each referral.
dig +trace www.example.com AYou will see root servers (.), then the com. name servers, then the example.com. name servers, and finally the A record. Each block of output is one hop from the diagram above.
A normal query shows what your resolver says:
dig www.example.com AThe answer section looks like this (the exact values depend on the domain):
;; ANSWER SECTION:
www.example.com. 287 IN A 192.0.2.10Read the columns from left to right: the name, the remaining TTL in seconds, the class (IN is Internet), the record type, and the data. The 287 is not the TTL configured in the zone. It is how many seconds are left in this resolver's cache.
What a record looks like
DNS data is stored as resource records. Every record has the same fields:
- Name: the owner name, such as
www.example.com.The trailing dot marks a fully qualified name, anchored at the root. - Type: what kind of data it holds.
Ais an IPv4 address andAAAAis an IPv6 address.NSnames a name server, andCNAMEnames another name. - TTL: how long, in seconds, a cache may reuse the record.
- Data: the value for that type.
All records with the same name and type form a record set (an RRset). If app.example.com has two A records, resolvers receive both together, and they typically rotate the order. Later chapters cover the types in detail.
TTL and caching
Time to live (TTL) is set by the zone owner on each record set. It is an instruction to every cache between the client and you: "You may reuse this answer for this many seconds without asking me again."
Caching happens at several layers:
- The recursive resolver, shared by many clients. This is the layer that matters most.
- The operating system's resolver cache.
- The application, such as a browser or a runtime with its own DNS cache.
Each layer counts the TTL down. When it reaches zero, the entry expires, and the next query triggers a fresh lookup upstream.
The trade-off
| Choice | Benefit | Cost |
|---|---|---|
| Long TTL (hours to a day) | Fewer queries, faster lookups for users, lower query cost | Changes take a long time to reach everyone |
| Short TTL (30 to 60 seconds) | Changes and failovers take effect quickly | More queries, more load on authoritative servers, and slightly higher latency on cache misses |
Route 53 bills per query for most record types, so a very short TTL on a popular name raises your bill. Alias records to AWS resources are not billed per query, which is one reason to prefer them where they apply.
Why "propagation" is a misleading word
Changing a record does not push anything to anyone. The authoritative servers have the new data almost at once. What remains is old copies sitting in caches that expire on their own schedule. The worst-case delay for a change is about the old TTL, counted from the last time each resolver fetched the record.
This leads to a standard technique. Before a planned change, lower the TTL to something short, such as 60 seconds. Wait at least the old TTL so every cache holds the short-TTL copy. Make the change, confirm it, and then raise the TTL again.
Some resolvers and applications do not follow the TTL exactly. A resolver may enforce a minimum or maximum, and some runtimes cache a lookup for the life of the process. So a short TTL is a request, not a guarantee.
Negative caching
Resolvers also cache failures. If you query a name that does not exist, the authoritative server answers NXDOMAIN, and the resolver remembers that for a time. The time comes from the zone's SOA record, using the smaller of the SOA record's own TTL and its minimum field (RFC 2308). In a Route 53 zone you can read it with dig example.com SOA.
The practical consequence: if you query a name before you create it, then create it, some resolvers keep reporting that it does not exist until the negative cache entry expires.
Common misunderstandings
- "Changing the record takes 48 hours everywhere." The delay is bounded by the TTL values in play, not by a fixed number. The 48-hour figure comes from long TTLs on NS records. For example, the
.comregistry zone typically serves NS records with a TTL of 172800 seconds, which is 48 hours. - "My resolver is authoritative." It is not. It is a cache, and it can be stale.
- "Authoritative servers recurse." They answer only about their own zones. Querying one for an unrelated name gets a refusal or a referral, not an answer.
- "If dig works, users see the same thing." Different resolvers have different cache states. Test through more than one resolver and directly against the authoritative server, as you will do in the troubleshooting chapter.
Where Route 53 fits
Route 53 plays three separate roles, and each one maps to something in this chapter:
- A registrar: it registers your domain and tells the registry which name servers to list. That produces the referral the
.comservers give. - An authoritative DNS service: your hosted zone's records are served by Route 53's name servers, the last stop in the diagram.
- A resolver for VPCs: inside a VPC, the Amazon-provided resolver acts as the recursive resolver for your instances.
You can use any one of these without the others. For example, you can register a domain elsewhere and host its zone in Route 53, which is the topic of the next chapters.
Exercise
A record for api.example.com has a TTL of 3600 and was last fetched by a recursive resolver 10 minutes ago. You now change its IP address in the hosted zone. What does a client using that resolver get for the next query, and what is the longest it can keep getting the old address? Why does lowering the TTL to 60 right now not fix this?
Show answer
The resolver still holds the cached copy, so the client gets the old address. The cache entry has about 50 minutes left (3600 seconds minus 600), so the old address can be served for up to about 50 more minutes. Lowering the TTL to 60 only applies to copies fetched after the change. The copy already cached keeps its original expiry, so you would have had to lower the TTL at least one old TTL (an hour) before making the change.
Exercise
You run dig www.example.com A twice, 30 seconds apart, and the TTL column shows 287 and then 257. What does this tell you about where the answer came from, and which command would show the TTL configured in the zone?
Show answer
The TTL counted down, so both answers came from the resolver's cache, not from a fresh lookup. The configured TTL is shown when the answer comes straight from an authoritative server, for example with dig @ns-123.awsdns-45.com www.example.com A +norecurse (use one of your zone's own name servers), or on the first, uncached query.