Sub topic 12
Troubleshooting with dig and friends
This chapter assumes you know the record types (A, AAAA, CNAME, MX, TXT, NS, SOA), how a recursive resolver walks root, TLD, and authoritative servers, and how TTL caching works. You should also be able to run commands in a terminal. The goal is a repeatable method for finding out where a name or site is broken, and which tool answers each question.
A method: work from the name down
Most "my site is down" reports come from one of five layers. Check them in order, and stop at the first one that fails.
- Delegation. Do the TLD servers point to the name servers you expect?
- Authoritative data. Do those name servers hold the records you expect?
- Resolver view. Do public resolvers return those records, or are they serving cached older ones?
- Transport. Does the IP address answer on port 80 or 443?
- Application. Does the server return the right site and a valid certificate for this name?
Reading dig output
dig (domain information groper) sends a DNS query and prints the whole response. The default output has several parts. A typical answer looks like this:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41233
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; ANSWER SECTION:
www.example.com. 300 IN CNAME example.com.
example.com. 300 IN A 192.0.2.10
;; Query time: 24 msec
;; SERVER: 192.0.2.1#53(192.0.2.1)Read these fields first:
- status is the response code.
NOERRORmeans the query worked.NXDOMAINmeans the name does not exist.SERVFAILmeans the resolver could not get a usable answer.REFUSEDmeans the server declined to answer you. - flags show how the answer was produced.
aameans the answer came from an authoritative server.rdmeans you asked for recursion, andrameans the server offers it. - ANSWER SECTION lists the records. The second column is the remaining TTL in seconds.
- SERVER shows which resolver answered. Always check it, because a VPN or router can change it without telling you.
NOERROR with an empty ANSWER SECTION is called NODATA. The name exists, but it has no record of the type you asked for. A common cause is asking for AAAA on a name that only has A.
Querying records
Start with the record types your site and mail depend on. +short prints only the values.
dig example.com A +short
dig example.com AAAA +short
dig example.com MX +short
dig example.com NS +shortFor output that is compact but still shows TTLs and record types, use +noall +answer:
dig +noall +answer www.example.com AOther useful forms:
dig example.com TXT +short
dig -x 192.0.2.10 +short
dig example.com ANY +noall +answerThe -x option does a reverse lookup, which matters for mail servers. Many servers publish only a small answer to ANY queries (or refuse them), so use specific types instead.
Checking delegation with +trace
If the zone looks right at your provider but nothing resolves, check what the parent zone says. +trace makes dig do the iterative walk itself instead of asking a recursive resolver:
dig +trace www.example.comThe output shows root servers answering with the TLD name servers, then the TLD servers answering with the NS records for your domain, then your authoritative servers giving the final answer. Watch for these patterns:
- The NS records at the TLD step name a provider you no longer use. The registrar still has old name servers.
- The trace stops at the TLD step with no further answer. The delegated servers do not respond or are misspelled.
- The final step returns
REFUSEDor an empty answer. The delegated server does not host a zone for your domain.
A related check is dig +nssearch, which asks every authoritative server for the SOA record:
dig +nssearch example.comIf the serial numbers differ between servers, zone transfers or provider syncing have not finished. This is the usual cause of answers that change between repeated queries.
Asking one server directly
The @ syntax sends a query to the server you choose. Use it in two ways.
Authoritative check. Ask a server from the NS list, and turn off recursion with +norecurse:
dig @ns1.example.com example.com A +norecurseIf this returns the right value with the aa flag, the zone is correct, and any remaining problem is delegation or caching. If it returns the wrong value, edit the zone.
Resolver comparison. Ask several public resolvers the same question:
dig @1.1.1.1 example.com AIf one resolver shows the new IP address and another shows the old one, the old answer is cached. Compare the TTL column on the stale resolver. It counts down on each query, and when it reaches zero the resolver fetches fresh data. Nothing you do on your side can flush a public resolver's cache. Some providers offer a cache-purge page, but otherwise you wait.
Common failure patterns
| Symptom in dig | Likely cause | What to check |
|---|---|---|
| `NXDOMAIN` for a name you created | Record missing, typo, or the record was added to the wrong zone | Query the authoritative server directly. Check the zone name |
| `NOERROR`, no answer | Wrong record type | Query `A`, `AAAA`, `CNAME` separately |
| `SERVFAIL` from one resolver only | Broken DNSSEC chain or unreachable name servers | Retry with `dig +cd` and see the next section |
| `REFUSED` from a delegated server | Server is not configured for your zone | Compare the NS list with the provider's assigned servers |
| Different answers on each query | Stale server or multiple records with round robin | Run `+nssearch` and compare serials |
| Right IP, wrong site | Host has no virtual host for this name | Test with `curl` (below) |
| CNAME at the apex fails or breaks mail | A CNAME cannot coexist with other records on the same name | Use A/AAAA records or an ALIAS/ANAME feature from your provider |
DNSSEC failures
If DNSSEC validation fails, a validating resolver returns SERVFAIL even though the authoritative data is fine. A common cause is moving a signed domain to a new provider without updating the DS record at the registrar. Run the query with checking disabled (+cd):
dig example.com A +cd
dig example.com A +dnssecIf the +cd query returns an answer and the normal one gives SERVFAIL, the problem is the DNSSEC chain. Fix or remove the DS record at the registrar. Do not just wait.
Beyond DNS: curl, openssl, and whois
Once DNS returns the right address, test the layers above it. These are the "friends" of dig.
curl shows the HTTP response. The --resolve option forces a name to a specific IP address for that one request, so you can test a new server before changing DNS:
curl -I https://example.com
curl -sS -o /dev/null -w "%{http_code} %{remote_ip}\n" https://example.com
curl -I --resolve example.com:443:192.0.2.10 https://example.comA 404 or a default page from the right IP usually means the host does not have your domain configured. A connection timeout points to a firewall or a stopped service.
openssl s_client shows the certificate the server presents. The -servername option sends SNI (the name the client wants), without which a shared server may return the wrong certificate:
openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -datesCheck that the subject or SAN list includes your name, and that the notAfter date is in the future.
whois shows registration data: the registrar, expiry date, status codes such as clientTransferProhibited, and name servers. An expired domain is a cause people often miss.
Checking what your own machine sees
Your programs do not call dig. They call the operating system's resolver, which also reads the hosts file and may use its own cache. If dig works but an application fails, compare against the system view:
import socket
for family, _, _, _, sockaddr in socket.getaddrinfo("example.com", 443, type=socket.SOCK_STREAM):
print(family.name, sockaddr[0])If this prints different addresses than dig, look for an entry in /etc/hosts, a local DNS cache, or a different resolver configured by a VPN.
Exercises
Exercise
dig +trace www.example.com ends at the TLD servers, and they list name servers from your old provider. The zone at your new provider is correct. Which layer is broken, and where do you fix it?
Show answer
Delegation is broken. The parent zone (the TLD) still points to the old name servers. Update the name server list at the registrar. Editing records at the new provider will not help until the registrar's NS records change.
Exercise
A normal dig example.com A against a validating resolver returns SERVFAIL, but dig example.com A +cd returns an address. What is the likely cause, and what is the fix?
Show answer
DNSSEC validation is failing, probably because the DS record at the registrar does not match the keys the current name servers use. Update the DS record to match, or remove it if the new provider does not sign the zone.
Exercise
dig @ns1.example.com example.com A +norecurse returns the new IP with the aa flag, but dig @1.1.1.1 example.com A returns the old IP with a TTL of 1800. What do you do?
Show answer
Nothing is wrong with the zone. The resolver is serving a cached answer, which will expire within 1800 seconds. Wait for the TTL to run out, and check again.