Sub topic 11
Testing and troubleshooting with dig and TTL awareness
This chapter assumes you can create a hosted zone, add records, and read a change batch. You should also know what a recursive resolver and an authoritative server are, from the first chapter. You need dig installed. It is part of bind-utils or dnsutils on Linux, and it ships with macOS.
Most DNS problems come down to two questions. What does the authoritative server say? What does the resolver your client uses say? When the two answers differ, a cache or a delegation is almost always the cause. This chapter shows how to ask each question separately, how to read the TTL in the answer, and how to match symptoms to causes.
Reading dig output
Run a plain query first:
dig www.example.com AA typical response looks like this:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41873
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;www.example.com. IN A
;; ANSWER SECTION:
www.example.com. 187 IN A 192.0.2.10
;; Query time: 24 msec
;; SERVER: 192.168.1.1#53(192.168.1.1) (UDP)Four parts of this output matter most.
- status is the response code.
NOERRORmeans the query worked, even if the answer section is empty.NXDOMAINmeans the name does not exist.SERVFAILmeans the server could not produce an answer.REFUSEDmeans the server will not answer you. - flags show how the answer was produced.
qrmarks a response.rdmeans recursion was desired andrameans the server offers recursion.aameans the answer is authoritative, so it came from the zone's own name server and not from a cache. - The number after the name in the answer section is the remaining TTL in seconds. Here it is 187, although the record may have been created with a TTL of 300. The resolver cached the record 113 seconds ago, and the value counts down until it expires.
- SERVER names the resolver that answered. Check this line first. If you expected to query a public resolver and the line shows your router, you are reading a different cache than you thought.
For scripts and quick checks, trim the output:
dig www.example.com A +noall +answer
dig www.example.com A +shortAsking the authoritative server directly
To bypass every cache, query one of your hosted zone's name servers. The +norecurse option is polite. An authoritative server does not recurse anyway.
aws route53 get-hosted-zone --id ZONE_ID \
--query "DelegationSet.NameServers" --output text
dig @ns-123.awsdns-45.com www.example.com A +norecurseReplace ns-123.awsdns-45.com with a name server from your own zone's list. The response should include the aa flag and the TTL you configured, undecremented. Route 53 does not count the TTL down, because it is the source of the value.
If the authoritative server returns the right answer and your normal resolver returns something else, the zone is correct and the difference is caching. If the authoritative server returns the wrong answer, the problem is in the zone: the wrong record, the wrong zone, or a change that has not finished.
Checking whether a change has finished
change-resource-record-sets returns a change ID. Check its status:
aws route53 get-change --id /change/C0123456789ABCDEFGHIJThe status is PENDING while Route 53 pushes the change to its name servers and INSYNC once all of them have it. This usually takes under a minute. INSYNC says nothing about resolver caches. It only means the authoritative side is ready.
Letting Route 53 test the answer
For records that use routing policies, a single dig shows only one possible answer. The test-dns-answer command asks Route 53 what it would return for a given query:
aws route53 test-dns-answer \
--hosted-zone-id ZONE_ID \
--record-name app.example.com \
--record-type AThe output includes ResponseCode, RecordData, and the name server that answered. You can add --resolver-ip and --edns0-client-subnet-ip to simulate a query from another location. This helps when you test latency or geolocation records.
TTL awareness
Resolvers cache an answer for as long as its TTL allows. Three consequences follow from that.
- A change is not visible everywhere at once. After you change a record, a resolver that cached the old value keeps serving it until its copy expires. The worst case is the old TTL, counted from that resolver's last lookup.
- Lowering the TTL does not help immediately. The new TTL only applies to caches filled after the change. To make a migration fast, lower the TTL at least one old-TTL period before the change. For example, drop 86400 to 60, wait a day, make the change, then raise it again.
- Failures are cached too. When a name does not exist, resolvers cache the
NXDOMAINfor a time set by the zone's SOA record. The negative cache time is the lesser of the SOA record's own TTL and the SOA minimum field. A new Route 53 zone has an SOA TTL of 900 seconds and a minimum of 86400, so a negative answer is cached for up to 900 seconds. If you query a name before you create it, you may keep seeingNXDOMAINfor up to 15 minutes after the record exists.
You can watch a cache at work by repeating a query:
dig www.example.com A +noall +answer
sleep 10
dig www.example.com A +noall +answerIf the second TTL is about 10 lower, you are talking to a caching resolver. If the TTL is the same each time, the server may be authoritative, or the resolver may be refreshing on every query.
Compare several public resolvers to see how far a change has spread:
for r in 8.8.8.8 1.1.1.1 9.9.9.9; do
echo "== $r"
dig @$r www.example.com A +noall +answer
doneLocal caches
Your operating system and browser may also cache answers, so dig can disagree with what a browser shows. dig talks to the resolver directly and skips the system cache. If dig is right and the browser is wrong, flush the local cache:
resolvectl flush-caches # Linux with systemd-resolved
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder # macOS
ipconfig /flushdns # WindowsFollowing the delegation
When a whole domain fails to resolve, check the chain from the top. +trace makes dig start at the root and follow each referral:
dig www.example.com A +traceRead the output for the step where the chain stops or changes. The most useful comparison is between the NS set at the parent and the NS set in your zone.
dig NS example.com +short
dig NS example.com @a.gtld-servers.net +norecurse +noall +authority
aws route53 get-hosted-zone --id ZONE_ID \
--query "DelegationSet.NameServers" --output textThe first command shows what resolvers see. The second asks a .com server (use the right parent for your TLD) for the delegation your registrar published. The third lists the name servers Route 53 assigned to the zone. All three lists should match. If the registrar lists different servers, update them at the registrar. If you deleted and recreated a hosted zone, the new zone has a new set of name servers, so the old delegation points at servers that do not know your zone.
Matching symptoms to causes
| Symptom | Likely cause | How to check |
|---|---|---|
| `NXDOMAIN` for every name in the domain | Registrar name servers do not match the hosted zone | Compare the three NS lists above |
| `NXDOMAIN` for one name | Record missing, misspelled, or in a different zone; negative cache still active | Query the authoritative server with `+norecurse`; check the SOA timing |
| `SERVFAIL` | Lame delegation (a listed server does not serve the zone), or a DNSSEC chain that does not validate | Query each delegated server directly; try `+cd` to see if validation is the problem |
| Old IP address still returned | Cached answer within TTL | Compare the TTL from your resolver with the authoritative TTL |
| Works from the VPC, fails from the internet | Record lives in a private hosted zone | Query from both places; check zone type |
| API rejects a CNAME at the apex | A CNAME cannot coexist with the SOA and NS records at the zone apex | Use an alias A or AAAA record instead |
| Answers change between queries | Weighted, latency, or multivalue routing, which is expected | Run the query repeatedly or use `test-dns-answer` |
| Failover never happens | Health check not attached to the primary record, or the checker cannot reach the endpoint | Look at the health check status and the record's `HealthCheckId` |
When you suspect SERVFAIL from DNSSEC, dig www.example.com A +cd sets the "checking disabled" flag. If the query succeeds with +cd and fails without it, the problem is validation and not the record data.
Sampling a weighted record
The distribution of a weighted policy is easier to trust once you measure it. Query the authoritative server many times and count the answers:
for i in $(seq 1 100); do
dig @ns-123.awsdns-45.com app.example.com A +short
done | sort | uniq -cWith weights of 90 and 10, you should see roughly 90 and 10, though not exactly. If you go through a recursive resolver instead, you will see the same answer repeated until the TTL expires. This is why weighted records for gradual rollouts use short TTLs, such as the 60 seconds in the earlier example.
A troubleshooting sequence
The following order avoids chasing the wrong layer.
- Query the authoritative server. If the answer is wrong, stay in Route 53 and fix the zone.
- If the answer is right, query your resolver and a public resolver. Compare the TTLs to see how long the old data can live.
- Compare delegation across the registrar, the parent TLD servers, and the zone.
- Only then look at local caches and the application.
Exercise
You changed www.example.com from 192.0.2.10 to 192.0.2.99 in the hosted zone. The record's TTL was 3600. get-change reports INSYNC. A query to the Route 53 name server returns 192.0.2.99, but dig @8.8.8.8 www.example.com +noall +answer still shows 192.0.2.10 with a TTL of 2400. What is happening, and how long can it last?
Show answer
Route 53 has the new value, so the zone is correct. The public resolver cached the old answer and will serve it until its remaining TTL reaches zero, which here is about 2400 seconds (40 minutes). Nothing in the zone needs fixing. To avoid this next time, lower the TTL well before the change, at least one old-TTL period ahead.
Exercise
A new domain returns NXDOMAIN for every name. The hosted zone has the records. dig NS example.com +short lists name servers that are not the four in get-hosted-zone. What is the most likely cause and the fix?
Show answer
The registrar still delegates to a different name server set. This often happens after a hosted zone is deleted and recreated, because the new zone gets new name servers. Update the registrar's name servers to the four listed in the zone's delegation set, then confirm with dig NS example.com +short once the parent's NS TTL expires.