The client side: how Linux resolves names
Resolution order
/etc/nsswitch.conf: hosts: files dns myhostname
files→/etc/hosts(static overrides — great for testing, dangerous when forgotten).dns→ the resolvers in/etc/resolv.conf.- Other sources (mDNS,
myhostname, LDAP) if configured.
getent hosts api.example.com resolves exactly like applications do (honouring nsswitch and /etc/hosts); dig and nslookup query DNS servers directly and bypass /etc/hosts. When "dig works but the app can't resolve", compare getent and check /etc/hosts, nsswitch, the app's own cache, or a DoH-enabled client.
resolv.conf
nameserver 10.0.0.2
nameserver 10.0.0.3
search ap-south-1.compute.internal shop.svc.cluster.local
options ndots:5 timeout:2 attempts:2 rotate
- nameserver — up to 3 resolvers, tried in order (or rotated with
rotate). - search — suffixes appended to names during lookups.
- ndots:N — if a name has fewer than N dots, try the search suffixes first; otherwise try the name as-is first. A name with a trailing dot is absolute and skips the search list.
- timeout / attempts — per-query timeout (default 5 s) and retries — the source of mysterious "5-second" delays when a resolver drops a packet.
On systemd-resolved systems, /etc/resolv.conf points at the local stub 127.0.0.53; resolvectl status shows the real upstream servers per interface, and resolvectl query name resolves through it.
Application runtimes
Language runtimes add their own behaviour: the JVM caches lookups (networkaddress.cache.ttl), Go has a pure-Go resolver that reads resolv.conf itself, Node.js uses the OS via libuv's thread pool (high DNS volume can saturate it), and connection pools keep using already-resolved IPs. (Covered in the TTL topic.)