Troubleshooting DNS With dig: Following a Resolution Step by Step
A method for DNS problems: reading dig output, following a delegation with +trace, comparing servers with +nssearch, and diagnosing broken setups in the lab: a lame delegation, a forgotten serial, mismatched NS records, cached NXDOMAIN, /etc/hosts overrides and blocked TCP.
kvi5hnuCode Sprout team member14 min readOn this page
"It's always DNS" is a joke among network engineers because so many outages turn out to be name problems. The good news is that DNS is unusually easy to debug: every server can be asked directly, every answer says who gave it and how long it's valid, and one tool, dig, shows all of it. This article puts together the pieces from Part 9 into a method, then applies it to broken setups built on purpose in the lab.
Reading dig output
dig sends one query and prints the whole response. A normal lookup through the lab resolver:
; <<>> DiG 9.20.30-1~deb13u1-Debian <<>> www.example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29499
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: (random) (good)
;; QUESTION SECTION:
;www.example.com. IN A
;; ANSWER SECTION:
www.example.com. 3600 IN A 198.51.100.10
;; Query time: 7 msec
;; SERVER: 198.51.100.99#53(198.51.100.99) (UDP)
;; WHEN: (date and time)
;; MSG SIZE rcvd: 88
The diagram below labels each part of that output; the list after it says what to look at first.

Things to check, in order:
- status is the RCODE (article 51).
NOERRORwith an empty answer section is NODATA: the name exists, but not with that type. - flags:
qrmarks a response (not a query), andrdechoes that you asked for recursion.aameans the answer came from an authoritative server, not a cache.rameans the server offers recursion; if it's missing, you asked a server that won't recurse for you.tcmeans the answer was truncated. - EDE (Extended DNS Errors) lines in the OPT pseudosection (article 51) often say exactly why a SERVFAIL or REFUSED happened.
- EDNS shows the UDP buffer size the server accepts (
udp: 1232), andCOOKIEis a DNS cookie, a token that lets client and server recognize each other and reject spoofed messages (RFC 7873, article 54). - TTL in the answer is the remaining time in the cache. A full value such as 3600 means a fresh fetch or an authoritative answer; a lower one means a cached copy.
- SERVER tells you who actually answered, which matters when a system has several resolvers configured.
Two options keep output short when you only need data:
2001:db8:2::10
mail.example.com. 1h IN A 198.51.100.25
+short prints just the data; +noall +answer prints full answer records, and +ttlunits shows TTLs in readable units. Other options used constantly: @server to choose who to ask, +norecurse to ask a server for only what it knows itself, +tcp to force TCP, +dnssec to request signatures, -x address for reverse lookups and +nocookie to remove cookie noise.
Following the delegation with +trace
dig +trace ignores your resolver's cache and does the iterative resolution itself, starting from the root, printing each referral (article 50):
; <<>> DiG 9.20.30-1~deb13u1-Debian <<>> +trace +nodnssec www.example.com
;; global options: +cmd
. 86400 IN NS a.root.test.
;; Received 124 bytes from 198.51.100.99#53(198.51.100.99) in N ms
com. 172800 IN NS a.gtld.test.
;; Received 141 bytes from 2001:db8:2::201#53(a.root.test) in N ms
example.com. 172800 IN NS ns1.example.com.
example.com. 172800 IN NS ns2.example.com.
;; Received 196 bytes from 2001:db8:2::202#53(a.gtld.test) in N ms
www.example.com. 3600 IN A 198.51.100.10
example.com. 3600 IN NS ns1.example.com.
example.com. 3600 IN NS ns2.example.com.
;; Received 212 bytes from 2001:db8:2::54#53(ns2.example.com) in N ms
Read it top to bottom: the resolver provided the root server list, the root referred to the com servers, the com server referred to example.com's servers, and ns2.example.com gave the answer. Each "Received" line names the server that replied at that step. When a resolution fails, +trace shows the exact step where it breaks.
A method
The flowchart below shows the order of the checks; each step is explained after it.

- Is it really DNS? Applications resolve through the system's resolver library, which may consult
/etc/hosts, mDNS or a local cache first (article 50). Comparegetent ahosts name(what applications see) withdig name(what DNS says). - What does the resolver say?
dig name. Note the status, any EDE, and whether the query timed out. - What do the zone's own servers say? Ask each one directly with
+norecurse. If they disagree, compare zone serials withdig +nssearch zone. - Is the delegation right?
dig +trace name, and ask the parent zone's servers for the zone's NS records. Look for timeouts and mismatches. - Is it caching? If the zone's servers have the right data but your resolver doesn't, it's serving a cached answer, possibly a cached NXDOMAIN. Wait for the TTL, or flush the resolver's cache (
rndc flushname namein BIND,unbound-control flush namein Unbound,resolvectl flush-cachesfor systemd-resolved).
The rest of the article walks through problems the lab was set up to have.
Problem 1: a lame delegation
The zone example.com delegates lame.example.com to a server, nowhere.example.com at 198.51.100.250, that doesn't exist. Through the resolver, the user sees only:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 50654
SERVFAIL says something went wrong upstream but not what. +trace finds the step:
;; Received 146 bytes from 2001:db8:2::201#53(a.root.test) in N ms
example.com. 172800 IN NS ns1.example.com.
example.com. 172800 IN NS ns2.example.com.
;; Received 201 bytes from 198.51.100.202#53(a.gtld.test) in N ms
lame.example.com. 3600 IN NS nowhere.example.com.
;; Received 99 bytes from 198.51.100.53#53(ns1.example.com) in N ms
;; Connection to 198.51.100.250#53(198.51.100.250) for www.lame.example.com failed: timed out.
;; no servers could be reached
The trace reached example.com's server, which referred it to nowhere.example.com, and the connection to that server timed out. A lame delegation is a delegation to a server that doesn't answer, or answers without being authoritative for the zone. Fix it at the parent: remove or correct the NS records, and make sure every listed server actually serves the zone.
Problem 2: servers disagree
An administrator changed www.example.com on the primary from .10 to .11 and reloaded, but forgot to increase the serial. Asking each server directly:
198.51.100.53 serial 2026112101 www -> 198.51.100.11
198.51.100.54 serial 2026112101 www -> 198.51.100.10
The primary has the new address, the secondary the old one, and both report the same serial, so the secondary sees no reason to transfer the zone (article 53). Clients get one answer or the other depending on which server their resolver picked. +nssearch asks every listed server for the SOA, and shows the trap clearly. In each SOA line, the numbers after the two names are the serial (2026112101), then the refresh, retry and expire timers and the negative-caching TTL, all in seconds (article 52):
SOA ns1.example.com. hostmaster.example.com. 2026112101 7200 900 1209600 300 from server 198.51.100.54 in 0 ms.
SOA ns1.example.com. hostmaster.example.com. 2026112101 7200 900 1209600 300 from server 198.51.100.54 in 0 ms.
SOA ns1.example.com. hostmaster.example.com. 2026112101 7200 900 1209600 300 from server 2001:db8:2::54 in 0 ms.
SOA ns1.example.com. hostmaster.example.com. 2026112101 7200 900 1209600 300 from server 198.51.100.53 in 0 ms.
SOA ns1.example.com. hostmaster.example.com. 2026112101 7200 900 1209600 300 from server 2001:db8:2::53 in 0 ms.
All serials match, so +nssearch alone looks healthy. It catches a broken transfer (different serials) but not a forgotten serial bump; for that, compare the actual data. (It lists one server more than once here because it queried every address it found.) The fix is to increase the serial on the primary and reload; NOTIFY (article 53) then triggers a transfer.
Problem 3: parent and child NS records differ
The NS records for a zone exist in two places: the delegation in the parent zone and the apex of the zone itself (article 49). They should match, but they're maintained by different people, often through a registrar's web form for the parent. Comparing them for example.net:
-- the parent (net TLD server) says:
example.net. 172800 IN NS ns1.example.com.
example.net. 172800 IN NS ns2.example.com.
example.net. 172800 IN NS ns3.example.com.
-- the zone itself says:
example.net. 3600 IN NS ns2.example.com.
example.net. 3600 IN NS ns1.example.com.
-- does ns3 exist?
status: NXDOMAIN
The net server (the top-level domain, or TLD, server for .net) lists three name servers, the zone lists two, and the third, ns3.example.com, doesn't even exist. Resolvers that pick ns3 waste time, and may fail if they don't find a working server quickly. Tools such as DNSViz and Zonemaster check for this and many other problems automatically.
Problem 4: a cached NXDOMAIN
A user looks up newhost.example.com before it exists, gets NXDOMAIN, then the administrator adds it. The zone's server has it, but the resolver keeps saying it doesn't exist:
opcode: QUERY, status: NXDOMAIN, id: 12428
-- authoritative server now:
198.51.100.95
-- resolver (negative answer still cached):
opcode: QUERY, status: NXDOMAIN, id: 21766
example.com. 298 IN SOA ns1.example.com. hostmaster.example.com. 2026112101 7200 900 1209600 300
The resolver cached the negative answer (article 50). The SOA record that came with it shows the remaining time: 298 seconds here, from the zone's negative TTL of 300. Keeping the SOA minimum field low (5 minutes to 1 hour) limits this; otherwise flush the name from the resolver's cache.
Problem 5: it isn't DNS at all
A host's /etc/hosts file has an old entry for www.example.net. Applications and dig disagree:
-- getent (follows /etc/nsswitch.conf, files first):
198.51.100.250 STREAM www.example.net
-- dig (asks DNS directly):
www.example.com.
198.51.100.10
getent follows /etc/nsswitch.conf, which consults files (that is, /etc/hosts) before dns, and found the stale entry. dig asked the DNS server directly and got the real answer: www.example.net is a CNAME for www.example.com (article 52), whose address is 198.51.100.10. dig never reads /etc/hosts, so when an application and dig disagree, look at the host's local configuration: /etc/hosts, nsswitch, systemd-resolved (resolvectl query name), VPN (virtual private network) software, or the browser's own DNS cache and DoH setting (article 55).
Problem 6: TCP blocked
A firewall in front of the resolver allows UDP port 53 but drops TCP. Small answers work, but a large one fails:
;; Truncated, retrying in TCP mode.
;; Connection to the resolver(198.51.100.99) for big.example.com failed: timed out.
;; no servers could be reached
The UDP response was truncated, dig retried over TCP as it should, and the TCP connection timed out. Firewalls that block DNS over TCP break large responses, DNSSEC and zone transfers, which is why RFC 7766 requires TCP support. If small names work but some don't, test the failing one with +tcp and with +notcp.
Other tools
host and nslookup give shorter, friendlier output:
-- host:
example.com mail is handled by 10 mail.example.com.
example.com mail is handled by 20 mail2.example.net.
-- nslookup:
Server: 198.51.100.99
Address: 198.51.100.99#53
Non-authoritative answer:
Name: www.example.com
Address: 2001:db8:2::10
They're fine for quick checks, but dig shows the full header, flags and sections, which you need for diagnosis. kdig (from Knot DNS) and delv (from BIND, for DNSSEC validation, article 84) are also useful, and drill comes with ldns. On Windows, Resolve-DnsName in PowerShell is the closest to dig. For packet-level problems, capture port 53 with tcpdump or Wireshark (article 6).
Part 9 in one page
- Names form a tree of labels. Zones are the administrative pieces of the tree, connected by delegations with NS and glue records (article 49).
- Resolvers walk the tree from the root using referrals, cache everything with its TTL, cache failures and negative answers too, and serve most answers from cache (article 50).
- Messages have a 12-byte header and four sections, use EDNS(0) for bigger UDP messages and extra options, and fall back to TCP when truncated (article 51).
- Records hold addresses, aliases, mail routing, service locations, policy and more, with HTTPS and SVCB the newest common types (article 52).
- Zones change through dynamic updates, NOTIFY and incremental or full zone transfers, secured with TSIG (article 53).
- Operations add round robin, split DNS, local multicast name resolution and defenses against amplification and poisoning (article 54). Encryption with DoT, DoH and DoQ protects the stub-to-resolver hop (article 55), and DNSSEC authenticates the data (article 84).
- Debugging follows a fixed path: application versus DNS, resolver, the zone's servers, delegation, cache.
Common questions
What's the difference between dig and nslookup?
Both send DNS queries. dig prints the complete response in the zone file format, with header, flags and every section, and has options for nearly every protocol feature. nslookup prints a simplified summary and hides details such as flags and TTLs. For troubleshooting, dig is the standard tool.
Why does dig give a different answer from my browser?
The browser uses the system's resolver library or its own DoH resolver, and both may have caches. dig asks the server in /etc/resolv.conf (or the one you name with @) directly and skips /etc/hosts. Compare with getent ahosts name, check the browser's DoH setting, and clear its DNS cache.
What does +norecurse show?
What a server knows by itself. On an authoritative server, it returns the zone's data with aa, or a referral. On a resolver, it returns only what's already in the cache, which is a way to check whether a name is cached and with how much TTL left.
How do I check that a change has propagated?
DNS changes don't propagate; caches expire. Ask every authoritative server directly with +norecurse to confirm they all have the change, and check that their serials match. Resolvers that cached the old data will keep it until its TTL runs out, so lower the TTL well before planned changes.
dig +trace works but my resolver returns SERVFAIL. Why?
+trace doesn't validate DNSSEC and may try different servers. Common causes: a DNSSEC validation failure (check with +cd, which disables validation, and delv), a server that answers dig but not the resolver's address, or a resolver that cached an earlier failure. Look at the EDE in the SERVFAIL response.
Why does my resolver still answer for a zone whose servers are all down?
It may be serving stale data. With serve-stale (RFC 8767), a resolver that can't reach any of a zone's servers may return expired records from its cache instead of SERVFAIL, typically for up to 1 to 3 days after they expired, with a TTL of 30 seconds. Many large public resolvers do this, and BIND and Unbound can be configured to. dig then shows EDE 3 (Stale Answer). It hides outages from users, but it also means an answer you see may be older than its TTL suggests.
What is a lame delegation?
A delegation whose listed name server doesn't answer for the zone: it's unreachable, or it answers but isn't authoritative. Resolvers waste time on it, and if every listed server is lame, the zone can't be resolved.
Summary
digshows the full response: check status, flags (aa,ra,tc), EDE, TTL and which server answered.+tracefollows the delegation from the root and shows the step where resolution breaks.+nssearchcompares the SOA serial across a zone's servers.+norecurse @serverasks a server only for what it knows itself.- Work through the layers: application versus DNS (
getentversusdig), the resolver, the zone's servers, the delegation and finally caching. - In the lab: a lame delegation gave SERVFAIL, and
+tracefound the timed-out server; a forgotten serial left servers with different data and the same serial; parent and child NS sets differed; a cached NXDOMAIN outlived the fix by its negative TTL;/etc/hostsoverrode DNS; and blocked TCP broke a large answer. hostandnslookupare handy for quick checks,dig,kdiganddelvfor diagnosis, and packet captures for the rest.
Practice questions
1. dig www.example.com returns status: NOERROR with ANSWER: 0 and one SOA record listed under AUTHORITY. What does that mean?
Answer
It's a NODATA response: the name exists, but has no records of the requested type (A). The SOA is included so the resolver can cache the negative answer for the time given by the SOA's minimum field or TTL. Try other types, for example AAAA or CNAME.
2. Users report that shop.example.com sometimes shows the new site and sometimes the old one. Which commands would you run first?
Answer
Ask each authoritative server directly: dig +norecurse @ns1.example.com shop.example.com and the same for the other servers, then compare serials with dig +nssearch example.com. Different data with the same serial means the serial wasn't increased; different serials mean zone transfers are failing. Also check the TTL resolvers report, since some may still have the old data cached.
3. dig +trace stops with "connection timed out" right after a referral listing ns.example.net. Where's the fault, and who should fix it?
Answer
The referral points to a server that doesn't answer: a lame delegation, or a network or firewall problem reaching it. The zone owner must make that server answer, or ask the parent zone's operator (usually through the registrar) to remove or correct the NS record.
4. A colleague added a record for api.example.com ten minutes ago. It resolves on the zone's servers but not through the office resolver, which says NXDOMAIN. The zone's SOA has minimum 3600. What's happening, and what can you do?
Answer
The resolver cached the NXDOMAIN from a lookup before the record existed, and keeps it for up to the negative TTL, which is at most the SOA minimum, 3600 seconds. Flush the name in the resolver (for example rndc flushname api.example.com) or wait. Lowering the SOA minimum makes this less painful in future.
5. ping db.example.com reaches 192.0.2.77, but dig +short db.example.com returns 198.51.100.77. Explain.
Answer
ping resolves through the system's resolver library, which follows nsswitch and probably found an entry in /etc/hosts (or a local cache, VPN rule or mDNS). dig asks DNS directly. Compare with getent ahosts db.example.com and check /etc/hosts.
6. Small queries through a resolver work, but dig big.example.com TXT prints "Truncated, retrying in TCP mode" and then times out. What's wrong?
Answer
The UDP answer didn't fit in the buffer, so it was truncated, and the follow-up query over TCP port 53 was blocked, probably by a firewall. Allow TCP port 53 to the resolver, as RFC 7766 requires.
Review quiz
Test what you've learned in Part 9 with the DNS review quiz.
Previous: Encrypted DNS: DNS over TLS, HTTPS and QUIC
Next: How Reliable Transport Works: ARQ, Sliding Windows, Flow Control and Timeouts

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.