Sub topic 11
Testing and troubleshooting with dig and TTL awareness
This chapter assumes you know what a hosted zone, a record and a TTL are, and that you can run commands in a terminal. You will use dig to see what DNS returns at each step. You will also learn why a change you made may not appear yet.
Why DNS problems look random
Two people can query the same name and get different answers. Each recursive resolver keeps its own cache. A cached answer stays until its TTL (time to live, in seconds) runs out. Route 53 answers correctly as soon as a change is in sync. Resolvers that cached the old answer keep serving it until their copy expires.
So most "it doesn't work" reports come down to one question: which server gave this answer, and is it a cached copy?
Query the way a resolver does
Start with the default resolver, then ask the authoritative server directly.
dig NS example.com +short
dig www.example.com A
dig @ns-123.awsdns-45.com www.example.com A +norecurse- The first command lists the name servers the public DNS has for the domain. They should match the four name servers in your hosted zone.
- The second goes through your configured resolver. The answer may come from cache.
- The third asks one Route 53 name server directly. Replace
ns-123.awsdns-45.comwith one of your zone's own name servers.+norecursetells the server not to look up names on your behalf.
Compare the second and third results. If the authoritative answer is correct and the resolver's answer is old, you are waiting for a cache to expire.
Read the TTL in the answer
In a dig answer, the number after the name is the remaining TTL.
www.example.com. 187 IN A 192.0.2.10Here the resolver will keep this answer for 187 more seconds. Run the same query again and the number drops. When it reaches zero, the resolver fetches a fresh copy. Asking the authoritative server directly always shows the full configured TTL, such as 300.
Plan changes around TTL
The old TTL controls how long the world may keep the old value. Lower it before a planned change, not after.
- Lower the record's TTL to 60 seconds.
- Wait at least the old TTL, so every cache holds the short-lived copy.
- Make the change.
- Verify with
dig. - Raise the TTL again once the change is stable.
Common problems and checks
| Symptom | Likely cause | Check |
|---|---|---|
| `NXDOMAIN` for the whole domain | Delegation missing or pointing at the wrong zone | `dig NS example.com +short` and compare with the hosted zone |
| `NXDOMAIN` for one name | Record missing or misspelled | Query the Route 53 name server directly |
| Old IP address still returned | Resolver cache | Read the remaining TTL and wait |
| Authoritative answer is right, your machine is wrong | Local or operating system cache | Query another resolver, such as `dig @8.8.8.8 www.example.com` |
| Different answers on each query | Weighted, latency or failover policy | Query repeatedly and check the records' set identifiers |
| Name works from the internet but not in the VPC, or the reverse | Public and private hosted zone for the same name | Query from inside the VPC |
Delegation errors are common. If you registered the domain elsewhere, the registrar's name servers must match the four in your hosted zone. If you deleted and recreated a hosted zone, it received a new set of name servers, so update the registrar.
Check the SOA and trace the path
dig SOA example.com +short
dig www.example.com A +trace+trace starts at the root servers and follows each delegation down to the authoritative answer. If the trace stops at the parent zone with the wrong name servers, the problem is delegation, not your records.
Exercise
You changed the A record for www.example.com from 192.0.2.10 to 192.0.2.99 with a 300-second TTL. Ten minutes later your laptop still shows the old address, but dig @ns-123.awsdns-45.com www.example.com A +norecurse returns the new one. What do you check next, and why?
Show answer
Route 53 is correct, so the old value comes from a cache. Run dig www.example.com A and read the remaining TTL. A 300-second TTL should have expired after ten minutes, so also query a different resolver such as dig @8.8.8.8 www.example.com A. If that returns the new address, the stale copy is in your local resolver or operating system cache, and flushing it or restarting the resolver fixes it. If the TTL was longer than you expected, check that the record you edited is the one being served.