Short answer: curl: (6) Could not resolve host means curl could not turn the host name in your URL into an IP address, and git prints the same words because it fetches https:// remotes through libcurl. First read the name after "host:" for a typo, then test the lookup with getent ahosts, check which DNS server /etc/resolv.conf names, and look for proxy variables.
curl -v https://github.com 2>&1 | head -3 # which name does curl try?
getent ahosts github.com # does the system resolver find it?
cat /etc/resolv.conf # which DNS server is asked?
env | grep -i _proxy # is a proxy in play?If getent prints addresses but curl still fails, the problem is in the command (the URL, a proxy, a container). If getent prints nothing, the resolver is the problem, and the full repair of a broken resolver is in Temporary failure in name resolution. This page is about the curl and git side of it.
What does curl error 6 mean, and how is it different from 5, 3 and 7?
The curl man page lists exit code 6 as "Could not resolve host. The given remote host could not be resolved." In libcurl it is CURLE_COULDNT_RESOLVE_HOST. Three neighbours look similar and point somewhere else:
| Message | Where it comes from | What it means |
|---|---|---|
curl: (6) Could not resolve host: X | curl, CURLE_COULDNT_RESOLVE_HOST | The lookup of X failed. X is exactly the string curl tried. |
curl: (5) Could not resolve proxy: P | curl, CURLE_COULDNT_RESOLVE_PROXY | A proxy is configured and its name P does not resolve. |
curl: (3) URL using bad/illegal format or missing URL | curl, CURLE_URL_MALFORMAT | The URL never got as far as DNS: a space, smart quotes, a stray carriage return. |
curl: (7) Failed to connect | curl, CURLE_COULDNT_CONNECT | The name resolved; the connection failed. Not a DNS problem. |
fatal: unable to access '...': Could not resolve host: github.com | git over HTTPS (libcurl) | The same as curl error 6, for the remote's host name. |
ssh: Could not resolve hostname github.com | git over SSH (git@github.com:... remotes) | The same failure, reported by the ssh client instead of libcurl. |
We reproduced the curl and git messages on our Debian 12 host (curl 7.88.1, git 2.39.5) with names under .invalid, a top-level domain reserved by RFC 2606 that never resolves, so nothing left the machine:
$ curl -sS https://nonexistent.invalid; echo "exit=$?"
curl: (6) Could not resolve host: nonexistent.invalid
exit=6
$ git ls-remote https://nonexistent.invalid/x.git; echo "exit=$?"
fatal: unable to access 'https://nonexistent.invalid/x.git/': Could not resolve host: nonexistent.invalid
exit=128
$ curl -sS --resolve nonexistent.invalid:47999:127.0.0.1 http://nonexistent.invalid:47999/
curl: (7) Failed to connect to nonexistent.invalid port 47999 after 0 ms: Couldn't connect to serverThe last line shows the split: with --resolve curl skips the lookup, uses the address you give, and the error changes from 6 to 7. The same trick tells you whether a server answers at a known IP while DNS is broken. More curl flags like this are in the curl command examples.
Is the host name in the error really a host name?
Read the word after "Could not resolve host:" before touching DNS. When it is https, api or a word from your own command, the URL is wrong. Three mistakes we reproduced:
$ curl -sS -o /dev/null "https://https://example.com"
curl: (6) Could not resolve host: https
$ curl -sS -o /dev/null "https://$HOSTX/api" # HOSTX was empty
curl: (6) Could not resolve host: api
$ curl -sS -o /dev/null -H Content-Type: application/json https://nonexistent.invalid
curl: (6) Could not resolve host: application
curl: (6) Could not resolve host: nonexistent.invalid- A doubled scheme (
https://https://) makes curl readhttpsas the host. - An empty shell variable turns
https://$HOST/apiintohttps:///api, and curl 7.88 then looks upapi. Runset -uin scripts so an unset variable stops the script instead. - An unquoted header or JSON body splits into several arguments, and curl treats each extra word as another URL. Windows
cmd.exedoes not treat single quotes as quotes, so-H 'Content-Type: application/json'copied from a Linux tutorial fails the same way there; use double quotes.
A space inside the URL, typographic quotes pasted from a chat or a document, and a trailing carriage return from a file saved with Windows line endings give error 3, not 6, in the same curl version. For git, check the remote itself with git remote -v: a typo in github.com or a missing scheme shows up there.
getent, dig or resolvectl: which lookup matches curl?
These three tools ask different things, and the difference is the diagnosis:
getent ahosts namecallsgetaddrinfo(), the same function a standard curl build (the threaded resolver, as in Debian's package) and git use. It follows/etc/nsswitch.conf, so with the usualhosts: files dnsline it reads the hosts file first and then DNS. This is the test that matches curl.dig namesends a DNS query straight to the servers in/etc/resolv.confand ignores/etc/hostsand nsswitch.dig @1.1.1.1 nameasks a public resolver instead.resolvectl query nameasks systemd-resolved, where it runs. It is the most useful view on Ubuntu and other systems with the stub resolver.
$ getent ahosts nonexistent.invalid; echo "exit=$?"
exit=2
$ dig nonexistent.invalid | grep -o 'status: [A-Z]*'
status: NXDOMAIN
$ resolvectl query nonexistent.invalid
nonexistent.invalid: Name 'nonexistent.invalid' not foundHow to read the combinations:
- dig says NXDOMAIN: the name does not exist in DNS. Typo, expired domain, or an internal name you can only see on another network (see split DNS below).
- dig times out (BIND 9.18 prints
communications error to ...: timed outandno servers could be reached): no DNS server inresolv.confanswers. Ifdig @1.1.1.1works, the configured server is the problem; if that fails too, outbound DNS or the network is blocked. - dig works, getent fails: the system resolver path is broken, typically a
hosts:line in/etc/nsswitch.confwithoutdns, or a stopped systemd-resolved behind a127.0.0.53stub. - getent works, curl fails: look at the URL, a proxy, or a container that has its own resolver.
Which DNS server does the machine ask?
Read the file, and find out who writes it before changing anything:
ls -l /etc/resolv.conf
grep -E '^(nameserver|search)' /etc/resolv.confnameserver 127.0.0.53, usually through a symlink tostub-resolv.conf: the systemd-resolved stub. The real upstream servers are inresolvectl status.- A header
# Generated by NetworkManager: set DNS withnmcli, not in the file. - A plain
nameserver 203.0.113.53line with a DHCP, resolvconf or cloud-init comment: that tool rewrites it, so fix it at the source. - No nameserver line at all: per resolv.conf(5) the resolver then asks a name server on the local machine, so unless one runs there, every lookup fails with error 6.
The repair for each case, per distribution, is in the resolv.conf section of the name resolution guide. On a fresh VPS, check this file first: the image and cloud-init put the provider's resolvers there, and a resolver that does not answer from your network breaks every git clone and curl while the remote host is perfectly fine.
Is a proxy variable in the way?
curl reads http_proxy (lower case only), HTTPS_PROXY or https_proxy, ALL_PROXY and NO_PROXY; the lower case form wins when both exist. git uses the same variables through libcurl, and its http.proxy setting overrides them. When a proxy is set and its own name does not resolve, the error changes to 5 and names the proxy:
$ http_proxy=http://proxy.invalid:3128 curl -sS http://nonexistent.invalid/
curl: (5) Could not resolve proxy: proxy.invalid
$ git -c http.proxy=http://proxy.invalid:3128 ls-remote https://nonexistent.invalid/x.git
fatal: unable to access 'https://nonexistent.invalid/x.git/': Could not resolve proxy: proxy.invalidenv | grep -i _proxy # variables in this shell
git config --show-origin --get-regexp 'proxy' # which git config file sets one
git config --global --unset http.proxy # remove it from ~/.gitconfig
curl --noproxy '*' https://example.com # one call without any proxyThe opposite case: you need the proxy, and get error 6 instead of 5. Then curl is not using it, usually because the URL is http:// and the variable was written as HTTP_PROXY in upper case (curl ignores it), or the host matches no_proxy. What each kind of proxy does is explained in what is a proxy server.
Does curl -4 change anything?
curl -4 uses IPv4 addresses only. If curl -4 URL works and the plain call does not, the IPv6 side of the lookup or the route is broken, and the fix is in the network, not the URL. getent ahostsv4 name and getent ahostsv6 name show which address families the system resolver returns. git fetch and git push document the same switch as -4 (--ipv4).
Why does it fail inside Docker but not on the host?
Containers on the default bridge get a copy of the host's resolv.conf, and Docker removes loopback nameservers from it, because a loopback address inside a container is the container itself. When 127.0.0.53 is the only nameserver, Docker assumes systemd-resolved and copies /run/systemd/resolve/resolv.conf (the real upstream servers) instead. If no other server is left, for example with only a local 127.0.0.1 cache, the Docker source falls back to Google's 8.8.8.8 and 8.8.4.4, which fails on networks that block outside resolvers. Containers on a custom network (every Compose project) ask Docker's embedded DNS server at 127.0.0.11, which forwards to the host's servers.
docker run --rm busybox cat /etc/resolv.conf
docker run --rm busybox nslookup github.com
docker build --network=host . # RUN steps use the host's network for one buildSetting fixed servers for all containers in /etc/docker/daemon.json is covered in the Docker section of the name resolution guide.
Internal git host: VPN and split DNS
A name like git.corp.example often exists only in your company's DNS. With split DNS the VPN client sends lookups for the company domain to the company resolver and everything else to your normal one. If the VPN is down, or its DNS settings did not apply, github.com resolves and the internal host gives error 6.
resolvectl status # look for the VPN link and its "DNS Domain"
resolvectl query git.corp.exampleIf the VPN link shows no DNS servers or no domain, reconnect it or fix its profile. On Windows the matching checks are in DNS server not responding.
Frequently asked
What does curl: (6) Could not resolve host mean?
Exit code 6 means curl could not turn the host name in the URL into an IP address. The name after "host:" is exactly what curl tried to look up, so check it for a typo first. If it is correct, test the lookup with getent ahosts and check the nameserver in /etc/resolv.conf.
Why does git say Could not resolve host: github.com?
git fetches https:// remotes through libcurl, so this is the same failure as curl error 6. Test with getent ahosts github.com, look for a stale http.proxy with git config --show-origin --get-regexp proxy, and check /etc/resolv.conf. SSH remotes report it as ssh: Could not resolve hostname instead.
Why does curl say Could not resolve host: application?
A header such as Content-Type: application/json was not quoted, so the shell split it and curl treated application/json as a second URL. Put the whole header in quotes. Windows cmd.exe does not accept single quotes as quoting, so use double quotes there.
What is the difference between curl error 5 and error 6?
Error 5 means the name of the configured proxy could not be resolved, and the message names the proxy. Error 6 means the target host itself could not be resolved. With a proxy you expected but error 6, curl is not using the proxy, for example because HTTP_PROXY was set in upper case for an http:// URL, which curl ignores.