W3docs

CURL and HTTPS, "Cannot resolve host"

It sounds like you are trying to use curl to make a request to an HTTPS url and are encountering an error that says "Cannot resolve host." This error can occur for a few reasons:

It sounds like you are trying to use curl to make a request to an HTTPS URL and are encountering an error that says "Cannot resolve host." This error indicates that curl cannot translate the domain name into an IP address. Common causes include:

  1. The domain name is misspelled or the URL is incorrect.
  2. The DNS server you are using is unreachable or failing to resolve the domain.
  3. Local network or firewall settings are blocking DNS queries.
  4. The local hosts file contains an incorrect or conflicting entry for the domain.

To troubleshoot this issue, you could try the following:

  1. Check that the domain name is spelled correctly and that you are using the correct URL.
  2. Verify DNS resolution using standard command-line tools:
    nslookup example.com
    # or
    dig example.com
  3. Check your local hosts file (/etc/hosts on Linux/macOS or C:\Windows\System32\drivers\etc\hosts on Windows) to ensure it doesn't contain a conflicting entry for the domain.
  4. Check your network connection and ensure no firewall or proxy is blocking DNS traffic (typically UDP/TCP port 53). Try again later if the issue persists.
  5. Use curl debugging and workaround flags:
    • --verbose (-v): Shows detailed request/response info, including the DNS lookup phase.
      curl -v https://example.com
    • --resolve: Manually maps a domain to an IP address, bypassing DNS for that specific request.
      curl --resolve example.com:443:93.184.216.34 https://example.com
    • --connect-timeout: Sets a limit (in seconds) for the DNS lookup and connection phase.
      curl --connect-timeout 10 https://example.com

Note: The --insecure flag (-k) disables SSL certificate verification and will not resolve "Cannot resolve host" errors, as those are strictly DNS/network related.

I hope this helps! If you have any more questions or if there's anything else I can do to help, just let me know.