Interview Prep/Linux/Networking, DNS and firewalls

`dig api.internal` works, but the application and `curl` fail with `Could not resolve host: api.internal`.

IntermediateTroubleshootingNetworking, DNS and firewalls
Answer

Likely causes → dig queries DNS directly and skips NSS; apps use getaddrinfo() which follows /etc/nsswitch.conf, /etc/hosts and search domains. A bad hosts: line, or a .local/mDNS rule, or the app running in a different network namespace, can differ.

Diagnose →

getent hosts api.internal          # uses the same path as apps
grep '^hosts' /etc/nsswitch.conf
cat /etc/resolv.conf               # search, options ndots

Fix → Fix nsswitch (hosts: files dns), add the correct search domain, or fix the container's DNS config.

Prevent → Test with getent hosts, not dig, when debugging application resolution.

All Linux questions Roadmap: Linux

More on Networking, DNS and firewalls