Skip to content

/errors/curl/could-not-resolve-host

curl: (6) Could not resolve host

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · curl 8.21.0 (x86_64-w64-mingw32) libcurl/8.21.0 Schannel zlib/1.3.2updated
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:

bash
curl -sS https://api.nonexistent.invalid/v1/users

Output · 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

bash
# 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:

bash
curl --resolve api.example.com:443:203.0.113.10 https://api.example.com/health
Exit codeNameMeaning
5CURLE_COULDNT_RESOLVE_PROXYThe proxy host name could not be resolved
6CURLE_COULDNT_RESOLVE_HOSTThe host name in the URL could not be resolved
7CURLE_COULDNT_CONNECTThe name resolved but the TCP connection failed (refused or unreachable)
28CURLE_OPERATION_TIMEDOUTThe operation (often the connection) timed out

Sources