Errors / checked October 9, 2026
curl: (6) Could not resolve host: api.example.com
The error
Output of a curl call, often in a cron job or CI step, when the hostname in the URL could not be turned into an IP address.
Quick fix
- Check the URL for typos and stray characters: a space, a quote or a trailing newline from a variable ends up in the hostname.
- Run getent hosts api.example.com (Linux) or nslookup api.example.com on the same machine. If that fails too, the problem is DNS on that machine, not curl.
- In cron, print the URL to a log before calling it: an environment variable that is set in your shell is often empty under cron, leaving a broken URL.
Why this happens
Exit code 6 means curl could not resolve the host name: no DNS answer for it on that machine at that moment. Typos, empty variables, a domain that lapsed and DNS outages on the server all look the same from curl.
Source: curl man page: exit codes
Other solutions
- Containers and CI runners use their own resolver; a name that works on your laptop can fail there.
- If the host resolves sometimes and fails sometimes, retry the call. Plain --retry only covers timeouts and some HTTP codes, so use --retry 3 --retry-all-errors (only for calls that are safe to send twice: curl warns it can duplicate data). Plain cron never retries on its own. A hosted scheduler like RunLater retries failed calls with backoff and logs each attempt, so a short DNS blip does not mean a missed run.
Check a schedule before you deploy it: the cron expression explainer shows the next 10 run times.
Frequently asked questions
What does curl exit code 6 mean?
Could not resolve host: the host name in the URL did not resolve to an address. The curl man page lists it as exit code 6.
Why does it work in my terminal but not in cron?
Cron runs with a minimal environment. If the URL is built from a variable you set in your shell profile, that variable is empty under cron and the URL is broken. Set it in the crontab or the script itself.
Have the URL called on schedule, with retries
RunLater calls your URL on a cron schedule or at an exact time, in your timezone, retries failed calls with backoff and logs each response, so a timeout or a 5xx shows up in a log instead of disappearing.