Fix the curl exit code 6 error

"curl: (6) Could not resolve host: <hostname>" - curl's wrapper text for a failed name lookup, exit code 6 (6)

Affects: Ubuntu (terminal tools and scripts using curl, wget and similar clients)

What this message means

curl prints its own text when a name lookup fails, and it exits with code 6. The libcurl error reference defines it: "CURLE_COULDNT_RESOLVE_HOST (6) Could not resolve host. The given remote host was not resolved." [1]. The resolver underneath is glibc, so this is the same failure surface as the terminal messages: the lookup asked the resolver configured for your connection and got nothing usable, or got an authoritative "not found" that curl passes through in its own wording [2].

For a Smart DNS setup this error is usually the command-line mirror of a browser error: the browser shows a lookup failure page, while scripts and commands show exit code 6. The fixes are the same.

Fix it step by step

Cause 1: The resolver configured on the connection is wrong or unreachable

The most likely cause right after changing DNS on the connection: a mistyped address, or the change was never picked up because the connection was not reconnected.

Fix:

  1. Run resolvectl status and check which DNS servers the interface actually lists. If they do not match your provider's addresses, the profile was not applied.
  2. Open Settings > Network > (gear) > IPv4, re-check the DNS field against the provider's dashboard, and click Apply.
  3. Disconnect and reconnect to the network, then rerun the curl command before assuming anything else.

Step 7 of How to change DNS on Ubuntu covers the Apply and reconnect step.

Cause 2: The hostname in the command or in a proxy setting is wrong

curl resolves two things: the target host and, if configured, a proxy host. A typo in either produces exit code 6, and a stale proxy entry in the environment keeps failing after you fix the target.

Fix:

  1. Read the exact hostname from the error message and check its spelling against the URL you meant.
  2. Check proxy variables in the shell: env | grep -i proxy. An empty-but-set http_proxy or https_proxy value points curl at a hostname that does not exist.
  3. Rerun curl with --noproxy "*" as a test; if the error disappears, the proxy entry was the failing hostname, not your resolver.

Cause 3: The resolver answers, but only for some names

If direct queries with dig find a name but curl still fails, the difference is in which resolver or which answer types the lookup used - often IPv6-first lookups or search-domain suffixes on the connection.

Fix:

  1. Compare lookups: dig example.com @1.1.1.1 versus the plain resolvectl query example.com. Different answers point at search domains or at the configured resolver.
  2. If your provider publishes no IPv6 addresses and the network is IPv6-first, set the provider's IPv6 addresses on the IPv6 tab, or leave the IPv6 DNS on Automatic while testing IPv4 only.
  3. Set the connection's DNS back to Automatic as a baseline and confirm curl works; that isolates whether the failure follows your provider's addresses.

If nothing helps

Run curl -v once more and note the exact failing hostname - if it is a proxy rather than your target, environment variables are the remaining suspect. Set the connection's DNS back to Automatic, reconnect, and confirm normal lookups with resolvectl query example.com. If automatic DNS also fails with exit code 6, the resolver service or the network path is the problem: restart systemd-resolved and, if it persists, work through the resolver error pages, starting with fix Temporary failure in name resolution and fix Name or service not known. The DNS steps themselves live in the setup guide.

FAQ

Is exit code 6 a curl bug?

No. curl wraps the resolver's answer, and its own documentation lists code 6 as the case where the given remote host was not resolved [1]. The underlying cause is the same resolver the rest of the system uses.

Does this error mean the network is down?

Not necessarily. Name resolution and network connectivity are separate layers; test with ping -c 2 1.1.1.1 to see whether raw IP traffic works before blaming DNS.

Why does wget work but curl fail?

Both use the same system resolver, so differences come from what they request: a proxy hostname in curl's configuration fails before the target does, and IPv6-first lookups can behave differently. Check curl -v output for which hostname failed.

Setting up DNS on this device?

Open the setup guide → All Ubuntu guides

Sources

  1. curl - libcurl error codes - accessed 2026-11-23
  2. Apisylux - Temporary Failure in Name Resolution on Ubuntu - accessed 2026-11-23