Lesson 12 of 14 · 10 min · Troubleshooting networks

DNS troubleshooting with dig

Covers: Ubuntu 24.04 LTS, BIND dig 9.18. Updated 13 Nov 2026. Part of the DevOps Engineer roadmap.

What you will learn

  • How to read a full dig answer
  • Useful options: +short, +noall +answer, @server, +trace, +norecurse
  • A method to find out whether the fault is the client, the resolver or the zone
  • What NXDOMAIN, SERVFAIL, timeouts and stale caches look like
  • Why dig can succeed when your application fails

In simple words

When a name doesn't open, you need to find who is at fault: your machine, the phone-book service it asks, or the entry itself. dig asks DNS questions directly and shows the raw answer. This lesson teaches you to read that answer and narrow the fault down step by step.

Words to know

  • dig: a command that asks DNS a question and prints the full answer.
  • NXDOMAIN: the answer "this name does not exist".
  • SERVFAIL: the answer "the DNS server could not get a result".
  • Cache: a remembered answer. An old one can keep pointing to the wrong place until it expires.

Reading a dig answer

dig example.com A
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63809
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; QUESTION SECTION:
;example.com.			IN	A

;; ANSWER SECTION:
example.com.		250	IN	A	104.20.23.154
example.com.		250	IN	A	172.66.147.243

;; Query time: 16 msec
;; SERVER: 192.168.0.1#53(192.168.0.1) (UDP)

What to read:

  • status: the outcome. NOERROR means the query worked (even if the answer section is empty, meaning the name exists but has no record of that type). NXDOMAIN means the name does not exist. SERVFAIL means the resolver could not get an answer (broken delegation, DNSSEC failure, unreachable authoritative servers). REFUSED means the server will not answer you.
  • flags: qr is a response, rd recursion was desired, ra recursion is available, aa (authoritative answer) is set only when the answer comes straight from the zone's own server.
  • ANSWER SECTION: name, TTL (250 seconds left in this cache), class, type, data. Two A records means round-robin DNS: clients receive both.
  • Query time and SERVER: which resolver answered and how fast. 16 msec here from the local router's cache.

Quiet forms for scripts and quick checks:

dig example.com A +short                  # only the data
dig example.com A +noall +answer          # only the answer section
dig example.com MX +short
dig -x 1.1.1.1 +short                     # reverse lookup

Choosing who to ask

By default dig asks the resolver in /etc/resolv.conf. Asking particular servers separates the possible causes:

dig @1.1.1.1 example.com A +short         # a public resolver
dig @8.8.8.8 example.com A +short
dig @ns1.provider.net example.com A +norecurse   # the authoritative server itself

We compared two public resolvers and the answer was the same from both (104.20.23.154), with query times of 127 ms and 171 ms from this network. Asking the authoritative name server directly (found with dig example.com NS +short) returned the record with TTL 300, the zone's configured value, while caches show lower, counting-down TTLs.

The decision table:

Result Meaning
Authoritative server gives the right answer, your resolver gives an old one cache not yet expired; wait for the TTL or flush the resolver
Authoritative server gives the wrong answer fix the record in your DNS provider
Authoritative server does not answer or answers wrongly for the zone delegation (NS at the registrar) or provider problem
Public resolvers work, your configured one does not your resolver (company or ISP) is broken or filtering
dig works but the application fails the application uses a different path (see below)

Following the delegation: +trace

dig +trace example.com A

starts at the root servers and follows each referral down to the authoritative server, showing every step, independent of any cache. If a delegation is broken (the registrar's NS records point to servers that do not host the zone, or a name server is unreachable) the trace stops or errors at that level. This is the first tool when a newly registered or moved domain "does not work".

Common errors and what they mean

  • status: NXDOMAIN: the name does not exist. Typos, a missing record, a record in the wrong zone, or a negative answer still cached from before you created it. We saw this for nosuch.example.invalid.
  • status: SERVFAIL: the resolver tried and failed. Often a broken or expired DNSSEC setup, or lame delegation. Test with dig +cd (checking disabled) and dig +trace to separate DNSSEC from other causes.
  • ;; no servers could be reached / connection timed out: the query got no answer from the server: wrong resolver address, a firewall blocking UDP/TCP 53, or the server down. We got exactly this querying a non-answering address (dig @192.0.2.1 example.com).
  • Empty output with +short: either no record of that type, or the query failed; run without +short to see the status.
  • Different answers from different resolvers: cache timing, or geo/latency-based DNS that answers per location (CDNs and cloud DNS do this on purpose).

When dig works but the application does not

dig talks straight to DNS. Applications use the system resolver, which follows /etc/nsswitch.conf (hosts: files dns here, so /etc/hosts comes first) and may use a local caching daemon (systemd-resolved). Proof:

echo "10.1.2.3 internal.test" >> /etc/hosts
getent hosts internal.test        # 10.1.2.3       internal.test
dig internal.test +short          # (empty)

getent found the name through /etc/hosts; dig did not, because it never reads that file. Therefore:

  • Test applications' view with getent hosts name (or resolvectl query name).
  • Check /etc/hosts for stale entries (a classic after migrations), /etc/resolv.conf, and resolvectl status for which server is used.
  • Remember the application's own caches: the JVM caches DNS answers (by default forever if a security manager is used, or 30 seconds), Nginx resolves upstream names once at startup unless a resolver is configured, Node and Python caches vary. After a DNS change, long-running services may need a restart or a TTL-aware configuration.
  • In containers and Kubernetes, the pod's /etc/resolv.conf points to the cluster DNS and has a search list and ndots setting that can multiply lookups; dig from your laptop sees a different world than the pod.

DNS checks worth automating

  • Certificate and domain expiry (an expired domain stops everything).
  • The A/CNAME of critical names against expected values.
  • Resolver latency (Query time).
  • Email records: dig example.com TXT +short for SPF; dig default._domainkey.example.com TXT for DKIM; dig _dmarc.example.com TXT.

Common mistakes

  • Testing only through your local resolver and trusting its cache.
  • Using dig as proof that the application can resolve the name.
  • Forgetting the dot and search domains: dig host may append search domains; use the full name ending in a dot to avoid surprises.
  • Not lowering the TTL before a migration.
  • Changing NS at the registrar without copying all records to the new provider first.

Try it yourself

  1. Run dig for a domain, then run it again and watch the TTL fall. Then query the authoritative server with +norecurse and compare the TTL.
  2. Make up a name under a domain you control that does not exist and read the NXDOMAIN status; create it and query again.
  3. Add a line to /etc/hosts that overrides a real name; compare getent hosts, dig and curl.
  4. Use dig +trace on a domain and write down the name servers at each level.

Check yourself

What does status: NOERROR with an empty answer section mean?

The name exists but has no record of the type you asked for (for example you asked for AAAA and only an A record exists).

How do you check whether the authoritative server or only your resolver has the old record?

Query the authoritative server directly with dig @<ns> name +norecurse. If it returns the new data and your resolver the old one, the resolver cache will update when the TTL expires.

Why does dig return nothing for a name that ping resolves from /etc/hosts?

dig queries DNS only and ignores /etc/hosts. Applications use the system resolver, which reads /etc/hosts first (per nsswitch.conf). Use getent hosts to see what applications see.

What do SERVFAIL and NXDOMAIN each tell you?

NXDOMAIN: the name does not exist. SERVFAIL: the resolver failed to obtain an answer (broken delegation, DNSSEC problem, unreachable servers), so the name may well exist.

Interview questions

Users report that a site is unreachable after a DNS change. How do you debug it?

Check the authoritative servers for the new record (dig @ns), check public resolvers (dig @1.1.1.1, @8.8.8.8), compare TTLs and wait for caches, run dig +trace for delegation problems, and confirm what the affected clients' resolver returns and whether application-level caches exist.

What is the difference between a recursive query and an iterative one?

A recursive query asks the server to find the complete answer (stub to resolver). Iterative queries return referrals, and the resolver follows them itself (resolver to root, TLD, authoritative).

How can DNS be used for load balancing, and what are its limits?

Returning several A records (round robin) or location-based answers. Limits: caching means clients keep using unhealthy addresses until TTL expires; DNS does not know server load unless the provider runs health checks.

Summary

  • Read dig: status, flags, answer section with TTL, query time and server.
  • Ask specific servers (@) and the authoritative one (+norecurse) to separate cache, record and delegation problems; +trace follows the delegation from the root.
  • NXDOMAIN = does not exist, SERVFAIL = resolver failed, timeout = cannot reach the server.
  • Applications use the system resolver and their own caches; verify with getent hosts.

Going deeper

See how much of this you can explain

A free mock interview asks you new questions on Networking for DevOps for DevOps Engineer and scores every answer, with what to fix.