"Could not resolve host": debugging DNS on Linux
Find out why a Linux machine cannot resolve a name, step by step through /etc/hosts, resolv.conf and the DNS server, with getent, dig and resolvectl.
Checked 2026-11-19curl: (6) Could not resolve host: api.internal means the name never became an address. Nothing was sent to the server, so the fix is not in the app. Work through the lookup in the order the system does it.
1. Ask the way programs ask
getent hosts api.internal
getent uses the same library calls as curl, ssh and most programs, so it follows the same rules. If it prints an address, name resolution works and the problem is elsewhere (wrong address, firewall, the program's own resolver).
2. Which sources are used, in which order
grep hosts /etc/nsswitch.conf
# hosts: files dns
files is /etc/hosts, dns is the DNS servers. Some systems add resolve (systemd-resolved) or mdns.
3. /etc/hosts
grep api.internal /etc/hosts
An old line here wins over DNS, silently, which is the cause surprisingly often.
4. Which DNS server is asked
cat /etc/resolv.conf
Look at nameserver and search. If it says nameserver 127.0.0.53, systemd-resolved is in the middle; see the real servers with:
resolvectl status
A search line explains why a short name like api may work on one machine and not another: it is tried as api.<search domain>.
5. Ask the DNS server directly
dig api.internal # the configured server
dig @10.0.0.2 api.internal # a specific server
dig +short api.internal
Read the status: in the header:
NOERRORwith an answer: DNS is fine; go back to steps 2 and 3.NXDOMAIN: the server says the name does not exist. Check the spelling and the zone.SERVFAILor a timeout: the server, or the path to it, is the problem. Try another server to compare.
dig talks to DNS only and ignores /etc/hosts; that difference between dig and getent is itself a clue.
In containers
A container has its own /etc/resolv.conf and /etc/hosts. On a Docker user-defined network, other containers are found by name through Docker's resolver at 127.0.0.11; on the default bridge network they are not.