What the message looks like
$ curl -I https://shop.example.com
curl: (6) Could not resolve host: shop.example.comCommon causes
- The host name is misspelled, or the record does not exist yet, for example after a new domain, a new subdomain or a DNS migration.
- This machine uses a resolver that fails or has stale data, while others see the record.
- The record exists only in a different zone or in internal DNS, not in public DNS.
/etc/hostsor a search domain overrides or changes the name.- The server has no working DNS at all (see “Temporary failure in name resolution”).
Check
- What does the system resolver say? This is what curl uses
getent hosts shop.example.com - What does public DNS say?
- Do the authoritative servers have the record?
dig shop.example.com +trace +short - Is there an override in hosts?
grep -n 'example' /etc/hosts
Fix
- Check the spelling of the host name in the command, the config or the URL.
- If public DNS shows no record, add it at your DNS provider and wait for the TTL of a negative answer to pass.
- If public DNS has the record but only this machine fails, fix the local resolver (
resolvectl status) or flush its cache:sudo resolvectl flush-caches. - If it works with an IP, test with
curl --resolve shop.example.com:443:203.0.113.10 https://shop.example.comto separate DNS from the web server. - Remove wrong lines from
/etc/hostsand check the search domain inresolvectl status.
Typical scenario
A nightly backup job calls an endpoint with curl and suddenly logs curl: (6) Could not resolve host: backup.example.com, ever since the VM was moved to another VLAN. The same call works on your laptop. What matters is testing resolution in the same context as the job, meaning as its user or via docker exec inside the container, not on your workstation. There, /etc/resolv.conf and the reachable resolver decide the outcome.
FAQ
dig works but curl does not. Why?
dig asks DNS directly, curl uses the system resolver, which also reads /etc/hosts and uses its own cache. Compare with getent hosts.
How long until a new record works everywhere?
It depends on the TTL and on cached negative answers. See the TTL tool and the post about DNS propagation.
What separates curl (6) from curl (7)?
With (6) name resolution already fails and curl never got an IP address. With (7) Failed to connect the name resolved, but the TCP connection to the port failed. The first is a DNS matter, the second is routing, a firewall or the service.
Can I bypass resolution with --resolve?
--resolve host:443:192.0.2.10 pins the IP for that one call. That is good for testing whether the server answers, and certificate and SNI still match the hostname. It does not fix the DNS problem, it only sidesteps it.
Why does the error only appear sometimes?
Often one of several configured nameservers does not answer, and depending on the order a lookup works or not. Query each server separately in a loop with dig @server. The entry that occasionally times out is the culprit.