Skip to content
Loopedin Labs

DNS

It's always DNS. Learn exactly where the lookup breaks.

Mini Rush · practice

Three questions before you read

Guessing first makes the answers stick. No sign-in.

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:

  1. /etc/hosts first. If the name is there, no DNS query is sent.
  2. DNS next. The resolver asks the nameserver listed in /etc/resolv.conf. On systemd-resolved hosts, that's often the local stub at 127.0.0.53.
  3. 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

TypeMapsNote
A / AAAAname to IPv4 / IPv6the final answer
CNAMEname to another namecan't coexist with other records; not allowed at the apex
MXdomain to mail host, with a prioritymust point to a hostname, not an IP
TXTname to textSPF, 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

  • dig shows 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.
  • search and ndots also apply on VMs. A short name like db can 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.