When DNS looks wrong, it's usually a cache or a different resolver. Know which one you're asking.
The mental model
When an app calls getaddrinfo("api.example.com"), the system resolver follows the hosts: line in /etc/nsswitch.conf. It's usually files dns, which means:
/etc/hostsfirst. If the name is there, no DNS query is sent.- DNS next. The resolver asks the
nameserverlisted in/etc/resolv.conf. On systemd-resolved hosts, that's often the local stub at127.0.0.53. - That recursive resolver answers from its cache, or walks from the root to the TLD to the domain's authoritative servers.
Every answer carries a TTL. Caches can keep an answer that long, and there's no way to push a change. Language runtimes can add their own cache on top; the JVM, for example, has its own DNS cache settings. NXDOMAIN answers are cached too, for the SOA's negative TTL.
Records that matter on call
| Type | Maps | Note |
|---|---|---|
| A / AAAA | name to IPv4 / IPv6 | the final answer |
| CNAME | name to another name | can't coexist with other records; not allowed at the apex |
| MX | domain to mail host, with a priority | must point to a hostname, not an IP |
| TXT | name to text | SPF, DKIM, domain verification |
Commands
dig api.example.com +short # ask DNS directly dig @8.8.8.8 api.example.com # ask a specific resolver dig api.example.com +trace # follow the delegation from the root dig example.com MX # see the answers and their TTLs getent hosts api.example.com # what apps get (honours /etc/hosts) resolvectl status # systemd-resolved upstream servers
nslookup also skips /etc/hosts, and its output is harder to script. Prefer dig for DNS and getent for "what does my app see?"
Kubernetes and ndots
Pods get a resolv.conf like this:
search prod.svc.cluster.local svc.cluster.local cluster.local nameserver 10.96.0.10 options ndots:5
Any name with fewer than 5 dots goes through the search list first. So api.example.com triggers up to 3 failed cluster lookups, each often for both A and AAAA, before the real query. Under load, that multiplies the queries CoreDNS handles. To fix it, call external hosts with a trailing dot (api.example.com.), or set dnsConfig.options with ndots: "2" on pods that make many external calls.
Gotchas
digshows the new IP but the app hits the old one. Check/etc/hosts, the app's own cache, and whether a connection pool is still holding old connections.- Lowering the TTL only helps once the old TTL has expired. Lower it a day before a migration, not an hour before.
searchandndotsalso apply on VMs. A short name likedbcan resolve to something unexpected through a search domain.
Common wrong fix
If a host has a resolution problem, hard-coding the IP in /etc/hosts makes it go away until the target IP changes. Then you get an outage that dig can't explain, because dig doesn't read that file. Fix the record or the resolver instead, and run getent hosts to confirm what the app really resolves.