Skip to content

dig: troubleshooting DNS resolution end to end

A practitioner guide to the dig command for dns troubleshooting: reading the header and sections, +short, +trace, +norecurse, querying authoritative nameservers directly, DNSSEC, and reverse lookups.

dig sends one DNS query to one server and shows you exactly what came back — the question it asked, the answer it got, who claimed authority, and a status code that says whether the lookup succeeded, failed, or found nothing. That precision is the whole point. “DNS is broken” is almost never true; what is true is that some specific server, at some specific hop, is holding a specific answer you did not expect. dig is the tool that lets you walk up to each server in turn and ask it directly, instead of guessing from whatever your laptop happens to have cached.

What you’ll accomplish

  • Read every section of dig output — HEADER, QUESTION, ANSWER, AUTHORITY — and know which one answers your question.
  • Point dig at any server you choose: your resolver, a public resolver, or the authoritative nameserver itself.
  • Settle a “DNS hasn’t propagated yet” argument in about ten seconds, with evidence.
  • Tell NOERROR, NXDOMAIN, and SERVFAIL apart, and know which layer each one blames.
  • Walk the full delegation chain with +trace, read a resolver’s cache with +norecurse, and check that every nameserver for a zone agrees.

Prerequisites

  • dig installed. It ships in a package named for BIND’s tools: apt install dnsutils on Debian and Ubuntu, dnf install bind-utils on Fedora and RHEL, brew install bind on macOS. Alpine calls it apk add bind-tools.
  • Check what you have with dig -v; you should see something like DiG 9.18.24.
  • Outbound UDP and TCP on port 53. Some corporate and hotel networks silently redirect port 53 to their own resolver, which will make every one of these commands lie to you. If results look impossible, test from somewhere else before you debug further.
  • Version note: dig 9.18 and 9.20 are the current BIND lines and what this guide targets. Everything here works on 9.16 as well. The one thing worth knowing across versions is that +trace implies +dnssec in modern builds, so its output is noisier than older documentation shows.

A word on the alternatives. nslookup is older and its output hides the header flags that matter most. host is a fine one-liner for “what is this A record” and nothing more. dig is verbose on purpose — it prints the protocol rather than a summary of it, and troubleshooting lives in the details a summary drops.

How it works

When a program on your machine resolves a name, it asks a stub resolver, which forwards the question to a recursive resolver — the one in /etc/resolv.conf, usually your ISP’s, your router’s, or something like 8.8.8.8. That recursive resolver does the real work. If it has the answer cached it returns it immediately. If not, it asks a root server, which tells it which servers run com; it asks one of those, which tells it which servers run example.com; it asks one of those, and finally gets an authoritative answer. Then it caches that answer for the record’s TTL and hands it back to you.

The DNS resolution chain from stub resolver through recursive resolver, root servers and TLD servers to the authoritative nameserver, showing which dig command aims at each hop

The reason this diagram matters is that every hop is a place an answer can be stale, wrong, or missing — and each hop can disagree with the others. When someone says “the DNS change hasn’t propagated,” what they almost always mean is “some cache between me and the truth still holds the old value.” Those are very different claims, and dig can distinguish them because dig lets you pick which server you talk to.

Step-by-step

1. Run the plain query and read all of it. With no flags, dig asks your default resolver for an A record and prints the full transaction:

dig example.com
; <<>> DiG 9.18.24 <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41123
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

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

;; ANSWER SECTION:
example.com.		1483	IN	A	93.184.215.14

;; Query time: 4 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Tue Jul 15 09:12:03 EDT 2026
;; MSG SIZE  rcvd: 56

Four things carry the diagnosis. status: NOERROR means the query itself succeeded. flags are the important part everyone skips: qr is a response, rd means recursion was desired, ra means the server offered it — and critically, there is no aa here, so this answer did not come from an authoritative server. 1483 is the TTL, the seconds this record stays cached; it counts down on repeat queries, which is the fingerprint of a cached answer. And SERVER: names who actually replied — always check it matches who you thought you asked.

2. Cut the noise with +short once you know what you’re looking for. It prints just the answer data, which is what you want inside scripts and pipelines:

dig +short example.com
93.184.215.14

Use +short for the answer and plain dig for the diagnosis. A subtler middle ground is +noall +answer, which suppresses every section except the answer while keeping the record format intact:

dig +noall +answer example.com MX
example.com.		3600	IN	MX	0 .

3. Ask for a specific record type by naming it. The general form is dig @server name TYPE — any of the three can be omitted, and dig will figure out which is which from the syntax:

dig +noall +answer NS example.com
example.com.		86400	IN	NS	a.iana-servers.net.
example.com.		86400	IN	NS	b.iana-servers.net.

This is the query that sets up everything below: it tells you which servers actually hold the zone, and those are the servers you go ask directly.

4. Query the authoritative nameserver directly with @. This is the single most useful move in DNS troubleshooting. Prefix a server with @ and dig sends the query straight there, bypassing every cache in between:

dig @a.iana-servers.net example.com A
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51402
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; ANSWER SECTION:
example.com.		86400	IN	A	93.184.215.14

Now the flags read qr aa rd — the aa bit is there. That is the server saying “I own this zone, this is the truth, not a copy.” Notice too that the TTL is the full 86400 rather than a countdown, because nothing is cached: you are reading the zone file itself. When a colleague insists a DNS change hasn’t gone out yet, this command answers the only question that matters. If the authoritative server shows the new value, the change is published, and everything else is caches expiring on their own schedule. If it shows the old value, the change was never actually saved and no amount of waiting will help.

5. Walk the whole delegation with +trace. Instead of asking a recursive resolver to do the work, dig performs the recursion itself, starting at the root and printing each referral:

dig +trace example.com
.			518400	IN	NS	a.root-servers.net.
;; Received 525 bytes from 127.0.0.53#53(127.0.0.53) in 3 ms

com.			172800	IN	NS	a.gtld-servers.net.
com.			172800	IN	NS	b.gtld-servers.net.
;; Received 1170 bytes from 198.41.0.4#53(a.root-servers.net) in 24 ms

example.com.		172800	IN	NS	a.iana-servers.net.
example.com.		172800	IN	NS	b.iana-servers.net.
;; Received 576 bytes from 192.5.6.30#53(a.gtld-servers.net) in 18 ms

example.com.		86400	IN	A	93.184.215.14
;; Received 56 bytes from 199.43.135.53#53(a.iana-servers.net) in 12 ms

Read it as a staircase: root hands you com, com hands you example.com, example.com hands you the record. Where it stops is where the delegation is broken. If +trace dies at the TLD step, the nameservers registered at your registrar are wrong or unreachable — a category of failure that no amount of editing zone records will fix, because nobody is being sent to your zone in the first place.

6. Read a resolver’s cache with +norecurse. This tells the server “answer only from what you already have; do not go look it up.” It is how you inspect a specific cache without disturbing it:

dig +norecurse @8.8.8.8 example.com A
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22711
;; flags: qr ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; ANSWER SECTION:
example.com.		1054	IN	A	93.184.215.14

An answer here means the record is cached, and the TTL tells you how many seconds until that cache lets go. An empty ANSWER section means it isn’t cached — which is itself useful, since the next real query will fetch a fresh copy.

7. Check every nameserver agrees. A zone with two nameservers can serve two different answers if a zone transfer failed or someone edited one server by hand. Loop over them:

for ns in $(dig +short NS example.com); do
  echo "$ns -> $(dig +short @"$ns" example.com A)"
done
a.iana-servers.net. -> 93.184.215.14
b.iana-servers.net. -> 93.184.215.14

Any disagreement in that output is a real bug, and it explains the “works for me, broken for them” reports perfectly — clients get whichever server their resolver happened to pick. dig +nssearch example.com does something similar, querying every nameserver for the zone’s SOA record so you can compare serial numbers.

8. Check DNSSEC with +dnssec. This sets the DO bit, asking for signature records alongside the answer:

dig +dnssec +noall +answer cloudflare.com A
cloudflare.com.		300	IN	A	104.16.132.229
cloudflare.com.		300	IN	RRSIG	A 13 2 300 20260817000000 20260715000000 34505 cloudflare.com. Ug7rK9...

The RRSIG record is the signature. In the full output, an ad flag in the header means your resolver validated that signature and vouches for the data.

9. Do reverse lookups with -x. Given an IP, find the name that claims it. dig handles the in-addr.arpa construction for you:

dig +short -x 8.8.8.8
dns.google.

Reverse records are configured by whoever owns the IP block, not by whoever owns the domain — so a missing PTR is normal and usually not your bug, unless you run a mail server, where it very much is.

Validate it works

Put the pieces together on a live name and prove the chain end to end. Three commands, one conclusion:

dig +short NS github.com
dig +short @$(dig +short NS github.com | head -1) github.com A
dig +short github.com A
dns1.p08.nsone.net.
dns2.p08.nsone.net.
dns3.p08.nsone.net.
dns4.p08.nsone.net.
ns-1707.awsdns-21.co.uk.
ns-421.awsdns-52.com.
ns-520.awsdns-01.net.
ns-1283.awsdns-32.org.
140.82.112.4
140.82.112.4

The first command finds the authority. The second asks that authority directly. The third asks your own resolver. When the last two agree, resolution is healthy from the zone all the way down to your machine — and you have demonstrated it rather than assumed it. When they disagree, you now know exactly which side is wrong, and the sections below tell you what to do about it.

Troubleshooting

A decision tree mapping the dig status codes NOERROR, NXDOMAIN and SERVFAIL to their likely causes and the next command to run

  • Stale cache versus authoritative answer. Your resolver says the old IP, the authoritative server says the new one. Nothing is broken; a cache is holding the previous value and will drop it when its TTL expires. Confirm with dig +norecurse @<resolver> <name> and read the TTL — that number is literally your remaining wait in seconds. Flushing your local cache (resolvectl flush-caches on systemd, sudo dscacheutil -flushcache on macOS) fixes your machine and nobody else’s, which is why the honest answer to “when will it update for everyone?” is “as each cache’s TTL runs out.”
  • NXDOMAIN versus SERVFAIL. These look equally like failure and mean opposite things. NXDOMAIN is a successful query with a definitive answer: the zone was reached, it was asked, and it said this name does not exist. Look for a typo, a missing record, or a query against the wrong zone. SERVFAIL means no answer was produced at all — the resolver hit an error or gave up. Suspect DNSSEC validation failure, dead nameservers, or a broken delegation. The fastest split is dig +cd <name> (checking disabled): if +cd succeeds where the plain query SERVFAILs, DNSSEC validation is your culprit. Then dig +trace <name> to find which hop breaks.
  • Negative answers cache too. After an NXDOMAIN, look at the AUTHORITY section: example.com. 3600 IN SOA ns.icann.org. noc.dns.icann.org. 2025011653 7200 3600 1209600 3600. That last field is the minimum TTL, and it governs how long resolvers remember the absence of the name. Query a hostname before you create it and you have taught every resolver you touched that it does not exist — for that many seconds. This is why a record that “should be live” sometimes still 404s for the one person who checked too early.
  • CNAME at the apex. A CNAME on the bare domain (example.com, not www.example.com) is invalid, because a CNAME means “nothing else exists at this name” while the apex must also carry NS and SOA records. Some providers accept the config and then behave strangely; others offer ALIAS or ANAME records that do the flattening server-side. Diagnose with dig +noall +answer example.com CNAME alongside dig +noall +answer example.com NS — if both return records, the zone is in a contradictory state and its MX or NS lookups will misbehave in ways that look random.
  • TTL confusion during a migration. The TTL that governs a cutover is the one that was in effect when the old record was last fetched, not the one you set this morning. Lowering a TTL from 86400 to 300 an hour before the switch accomplishes nothing — resolvers that cached the record yesterday hold it for the full day regardless. Lower the TTL at least one old-TTL period before the change, verify with dig +noall +answer <name> against the authority, and only then move the record.
  • Split-horizon giving different answers. If dig from the office returns one IP and dig from a laptop on cellular returns another, the zone likely has an internal and an external view, and both answers are correct for their audience. Confirm by querying a public resolver and an internal one side by side: dig @8.8.8.8 +short app.example.com versus dig @<internal-resolver> +short app.example.com. The bug is then usually a client on the wrong resolver rather than anything wrong in DNS.

When this is the wrong approach

dig tells you what the DNS layer says, and nothing else. It cannot tell you whether the host at that IP is listening, whether the certificate matches the name, or whether a firewall is dropping your packets. When resolution is provably correct and the service is still unreachable, the problem has moved up the stack and dig has done its job — breaking down request latency with curl picks up where it stops, and verifying a certificate chain with openssl covers the TLS layer that trips people up immediately after a DNS cutover.

dig is also a poor fit for continuous checking. It is a manual instrument for a human at a terminal; if you need to know that a record changed at 3 a.m., that is monitoring, not a command. And it queries one server at a time from one vantage point, so it cannot answer “what does the rest of the world see” — for that you want a distributed checker or a query log on the resolvers themselves. Finally, dig reads DNS but never writes it: registrar settings, zone edits, and DNSSEC key management all happen elsewhere. The reference for dig and the rest of the BIND toolset is the BIND 9 documentation.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.