DNS Troubleshooting on Linux: A Systematic Approach
\"It's always DNS\" is a joke because the failure modes are so scattered: resolver config, caching, search domains, split DNS. Here is where to actually look.
Key takeaways
- Troubleshoot Linux DNS layer by layer.
- Query an upstream server directly with dig @server to see what DNS really says, then compare resolvectl status or /etc/resolv.conf, the ndots search-domain walk, local caches like systemd-resolved and nscd, and application caches such as the JVM's. getent hosts shows what applications actually resolve.
On this page
To troubleshoot DNS on Linux, run dig @<upstream-server> <name> first: it bypasses every local layer and shows what DNS really returns. If that answer is right, the fault is local, so check resolvectl status or /etc/resolv.conf, the ndots search-domain walk, local caches (resolvectl flush-caches), and application caches, then compare with getent hosts <name>.
Verified against
systemd 262 resolvectl man page, the Linux resolv.conf(5) man page, Kubernetes DNS for Services and Pods, and the Java SE 25 networking properties docs. Checked October 2026.
"It's always DNS" is a running joke because resolution on a modern Linux box passes through more layers than people expect: an application's own resolver library, nsswitch.conf, systemd-resolved's local stub, /etc/resolv.conf, search domains, and often a caching layer on top of all of it. A name that resolves from one tool and fails from another usually means two of those layers disagree, not that DNS itself is broken. The fix is finding out which layer is lying.
Start with the tool that bypasses the most layers
dig talks directly to a nameserver and skips the local resolver stack entirely, which makes it the right first tool: it tells you what the actual authoritative or upstream server thinks, independent of anything misconfigured locally:
dig +short api.example.com
203.0.113.42
dig api.example.com
;; ANSWER SECTION:
api.example.com. 284 IN A 203.0.113.42
;; SERVER: 127.0.0.53#53(127.0.0.53)
That SERVER: 127.0.0.53 line matters. On most current distros that's systemd-resolved's local stub listener, not your actual upstream DNS server. To skip the stub and query an upstream directly:
dig @8.8.8.8 api.example.com +short
203.0.113.42
If the direct query to a public resolver returns a different answer than the local stub, the problem is in local resolution (caching or config), not in DNS itself.
Find out what's actually answering locally
resolvectl status
Global
Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub
Link 2 (eth0)
Current Scopes: DNS
DNS Servers: 10.0.0.2 10.0.0.3
DNS Domain: ~.
resolvectl status (on distros using systemd-resolved) shows the real per-interface DNS servers and search domains, often more accurate than reading /etc/resolv.conf directly, because that file may just point at the local 127.0.0.53 stub rather than showing the real upstream servers systemd-resolved is actually using.
If the box doesn't run systemd-resolved, /etc/resolv.conf is the direct source of truth:
cat /etc/resolv.conf
nameserver 10.0.0.2
nameserver 10.0.0.3
search prod.internal example.com
options ndots:5
The ndots and search-domain trap
The resolv.conf(5) default for ndots is 1, but kubelet writes options ndots:5 into every pod's /etc/resolv.conf, and people copy it elsewhere. It means: if a name has fewer than 5 dots, try it against every search domain before trying it as-is. A pod in the prod namespace gets search prod.svc.cluster.local svc.cluster.local cluster.local, so a lookup for api.example.com (two dots) first tries api.example.com.prod.svc.cluster.local, then api.example.com.svc.cluster.local, and so on, only reaching the real name last. That's the classic cause of DNS lookups that are slow (several failed queries before the real one) or that resolve to the wrong thing when an unexpected search domain happens to have a matching record. The Kubernetes side of this, including CoreDNS, is in fixing DNS resolution in Kubernetes.
dig +search +showsearch api # prints each search-domain attempt before the final answer
If a hostname resolves differently (or times out longer) than a fully-qualified version of the same name, this is the first thing to check:
time dig api # walks the search list
time dig api.example.com # fully qualified, no search-list walk
Caching: three layers that can each be stale independently
systemd-resolved's own cache: flush it and retest before assuming anything upstream changed:Bashsudo resolvectl flush-cachesnscdorunbound, if either is running on the box, cache independently ofsystemd-resolved. Check withsystemctl status nscd unbound; a box can be running more than one caching layer without anyone remembering why.- Application-level caching. The JVM, for example, caches successful lookups in-process. The Java SE 25 docs give
networkaddress.cache.ttla default of 30 seconds andnetworkaddress.cache.negative.ttl10 seconds, but older JVMs cached forever when a security manager was installed, and a negative value (set injava.security) still means forever. That's a frequent cause of "the DNS record changed 20 minutes ago but the app is still hitting the old IP" even though the OS resolved correctly: the app just never asked again.
Reading DNS off the wire when nothing else explains it
sudo tcpdump -i eth0 -n port 53
14:05:02.118331 IP 10.0.0.5.51422 > 10.0.0.2.53: 41231+ A? api.example.com. (33)
14:05:02.119820 IP 10.0.0.2.53 > 10.0.0.5.51422: 41231 1/0/0 A 203.0.113.42 (49)
If a query never shows up in the capture at all, the application isn't even reaching the network for DNS. It's serving from an in-process cache, a hosts-file entry, or NSS module (like nss-mdns or a container's /etc/hosts injection) further up the resolution chain than the network layer. getent hosts <name> shows you the result after the full NSS chain runs, which is the closest thing to "what will the application actually see":
getent hosts api.example.com
203.0.113.42 api.example.com
The fix in order
dig @<upstream> <name>: bypass every local layer and confirm what DNS actually says at the source.resolvectl status(or/etc/resolv.confdirectly): confirm which servers and search domains the box is actually configured to use, not what you assume it's using.- If a bare or short name behaves differently than the FQDN, suspect
ndotsand the search-domain walk; check withdig +search +showsearch. - Flush
systemd-resolved's cache and check for a second caching daemon (nscd,unbound) before assuming the record itself is wrong. - If the app-level behavior still doesn't match what
dig/getentshow, suspect application-level DNS caching (the JVM is the classic offender); that's a restart or a cache-TTL setting, not a DNS problem at all. tcpdump port 53when nothing above explains it: if the query never leaves the box, something upstream of the network (hosts file, NSS module, in-process cache) is answering first.
This pairs with Linux network debugging with tcpdump, ss, and eBPF for the rest of the network-layer diagnostic toolkit, and the broader Linux troubleshooting guide.
Questions people ask
Why does dig work but my application can't resolve the name?
dig talks to a nameserver directly and skips the Name Service Switch, so it ignores /etc/hosts, NSS modules and in-process caches. Applications go through getaddrinfo and nsswitch.conf. Run getent hosts <name> to see what the NSS chain returns. If that differs from dig, the problem is a hosts entry, an NSS module, or a cache; if they match, suspect caching inside the application.
How do I flush the DNS cache on Linux?
On systems running systemd-resolved, run sudo resolvectl flush-caches; the man page describes it as roughly equivalent to sending SIGUSR2 to the service. Then check whether nscd or unbound is also running, since each keeps its own cache and needs its own flush or restart. Application caches, such as the JVM's, only clear when the process restarts or its TTL expires.
Why is 127.0.0.53 in /etc/resolv.conf?
That address is the local stub listener of systemd-resolved. Applications send queries there, and systemd-resolved forwards them to the real upstream servers configured per interface. Reading /etc/resolv.conf in that mode tells you nothing about the upstream servers; run resolvectl status to see them, along with per-link search domains and DNSSEC settings.
The call we'd make
Reach for dig @<upstream> before anything else. It's the one query that isolates "is this actually a DNS problem" from "is this a local resolver, cache, or search-domain problem," and every other step in this guide exists to answer that second question once the first one is ruled out.
Sources
Cite this article
Kiril Urbonas (2026). DNS Troubleshooting on Linux: A Systematic Approach. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/dns-troubleshooting-linux
[DNS Troubleshooting on Linux: A Systematic Approach](https://www.devopsness.com/blog/dns-troubleshooting-linux) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from Linux
Explore more articles in this category
zram vs zswap: Compress Linux Memory Before You Buy More RAM
Both compress memory in RAM, but zram replaces your swap device and zswap sits in front of one. On a server with a disk, that difference decides which one you want.
systemd Timers vs Cron: What Changes When You Switch
Moving scheduled jobs from cron to systemd timers: the wins, the gotchas, and the cases that should stay on cron anyway.
Shell Scripting Best Practices: Writing Maintainable Scripts
We have a few hundred shell scripts in production. The patterns that make them survive contact with reality, and the ones we've stopped writing.
You might have missed
Evergreen posts worth revisiting.