Home/Blog/How to Fix cURL Error 6: Could Not Resolve Host (2026)

How to Fix cURL Error 6: Could Not Resolve Host (2026)

Terminal showing cURL error 6 could not resolve host message on dark screen

Your terminal command fails with curl: (6) Could not resolve host. This cURL error 6 fix guide explains the single thing that went wrong — cURL could not translate the hostname into an IP address — and walks through the exact DNS checks and fixes on Windows, Linux, and macOS. Updated for 2026.

Here is the one-line mental model: before cURL can connect to anything, it must ask DNS “what IP address is this name?” Error 6 means that question got no usable answer. The hostname might be mistyped, your DNS server might be down, a firewall might be blocking DNS queries, or a proxy might be misconfigured. The steps below isolate which one in minutes, because each has a different fix.

What Causes cURL Error 6

  • Typo in the hostname: a misspelled domain or wrong subdomain — the most common cause by far.
  • DNS server down or unreachable: your configured resolver is not answering queries.
  • Missing nameserver config: /etc/resolv.conf empty or wrong on Linux servers.
  • Firewall blocking DNS: UDP port 53 blocked, so queries never leave (or return to) your machine.
  • Stale DNS cache: old cached entries pointing at dead addresses.
  • Proxy misconfiguration: http_proxy/https_proxy env vars routing DNS through a broken proxy.
  • Bad /etc/hosts entries: manual host mappings overriding real DNS with wrong IPs.

How to Fix cURL Error 6: 7 Steps

Step 1: Check the URL for typos

Copy the hostname from the error and inspect it character by character — transposed letters, wrong TLD (.com vs .org), and stray spaces are the top cause. Test the exact URL in a browser too; if the browser also fails, the name itself is the problem, not cURL.

Step 2: Test DNS resolution directly

Run nslookup example.com (or dig example.com on Linux/macOS) and ping example.com. If these also fail, DNS is broken system-wide — continue below. If they succeed but cURL fails, the problem is cURL-specific: check proxy variables (Step 5) and cURL’s resolver build.

Step 3: Switch to a reliable public DNS

Point your system at Google DNS (8.8.8.8, 8.8.4.4) or Cloudflare DNS (1.1.1.1, 1.0.0.1). On Linux servers, edit /etc/resolv.conf and add nameserver 8.8.8.8 (note: NetworkManager or systemd-resolved may overwrite this — configure through your network manager for permanence). On Windows/macOS, change DNS in the network adapter settings.

Step 4: Flush the DNS cache

Stale entries cause mysterious failures. Windows: ipconfig /flushdns. Linux (systemd): sudo systemd-resolve --flush-caches or sudo resolvectl flush-caches. macOS: sudo killall -HUP mDNSResponder. Retest with curl -v afterwards.

Terminal showing DNS lookup with nslookup command on screen

Step 5: Check proxy environment variables

Run env | grep -i proxy. If http_proxy or https_proxy point at a dead or wrong proxy, cURL fails at the proxy stage. Unset them with unset http_proxy https_proxy and retry, or bypass the proxy for one request with curl --noproxy "*" https://example.com.

Step 6: Inspect firewall and hosts file

Confirm UDP port 53 (DNS) is open outbound in your firewall — corporate firewalls sometimes block it. Then check /etc/hosts (Linux/macOS) or C:\Windows\System32\drivers\etc\hosts (Windows) for manual entries mapping the hostname to a wrong IP, and remove or correct them.

Step 7: Verify end-to-end

Run curl -v https://example.com and watch the verbose output: you should see the resolved IP, then a TCP connection, then TLS. If resolution now works but the connection fails differently (e.g. error 7 or 60), you have moved past DNS — see our cURL error 7 guide or cURL error 60 guide for the next stage.

How to Prevent cURL Error 6

Standardise DNS in your environments: provision servers with at least two reliable resolvers, monitor resolver health, and avoid single points of failure like one ISP DNS. In scripts, validate hostnames before requests and log the resolver used on failure — “could not resolve host” at 3 AM is far easier to debug with the DNS server in the log line. For cron-driven API calls, add a pre-flight nslookup check that alerts before the main job fails. A quick connectivity check with a free network diagnostic tool confirms your DNS path is healthy.

Conclusion

cURL error 6 is purely a name-resolution failure: check the spelling, test with nslookup, switch to a public DNS, flush the cache, and clear bad proxy settings. Work the steps in order and DNS stops being a mystery. For more command-line errors explained plainly, follow the KamiWeb blog.