/errors/curl/could-not-resolve-host
curl: (6) Could not resolve host
- tool
- curl
- exit code
- 6
- versions
- curl 7.x, curl 8.x
- os
- linux, macos, windows
curl: (6) Could not resolve host: NAME means curl could not translate the host name in the URL into an IP address, so it never connected. Exit code 6 is CURLE_COULDNT_RESOLVE_HOST. Check the spelling of the host and the quoting of the URL first, then whether the machine can resolve any name at all (nslookup example.org), then proxy and VPN settings.
Reproduce it
The .invalid top-level domain is reserved by RFC 6761 and never resolves:
curl -sS https://api.nonexistent.invalid/v1/usersOutput · exit 6
curl: (6) Could not resolve host: api.nonexistent.invalid
A malformed command line produces the same error. An unquoted space in a URL, for example, makes the shell pass the rest as a second argument, which curl treats as another URL whose host is the word after the space.
Diagnose
# does the name resolve outside curl?
getent hosts api.example.com # Linux
nslookup api.example.com # Linux, macOS, Windows
# which proxy does curl use?
env | grep -i _proxy
# verbose output shows the name curl tries to resolve
curl -v https://api.example.com/If nslookup works but curl fails, look at proxy variables (http_proxy, https_proxy, no_proxy) and at ~/.curlrc.
Test against an IP without DNS
--resolve pins a host name to an address for one request, while keeping the correct Host header and TLS server name:
curl --resolve api.example.com:443:203.0.113.10 https://api.example.com/healthRelated exit codes
| Exit code | Name | Meaning |
|---|---|---|
| 5 | CURLE_COULDNT_RESOLVE_PROXY | The proxy host name could not be resolved |
| 6 | CURLE_COULDNT_RESOLVE_HOST | The host name in the URL could not be resolved |
| 7 | CURLE_COULDNT_CONNECT | The name resolved but the TCP connection failed (refused or unreachable) |
| 28 | CURLE_OPERATION_TIMEDOUT | The operation (often the connection) timed out |