- How to Fix curl: (6) Could not resolve host Error in Linux
- curl: (6) could not resolve host Error
- Solution 1: Missing Working DNS Nameserver
- Solution 2: Curl Syntax Errors
- CURL and HTTPS, «Cannot resolve host»
- 11 Answers 11
- Saved searches
- Use saved searches to filter your results more quickly
- cURL error 6: Could not resolv http://curl.haxx.se/libcurl/c/libcurl-errors.html) #1901
- cURL error 6: Could not resolv http://curl.haxx.se/libcurl/c/libcurl-errors.html) #1901
- Comments
- Actual Behavior
- Expected Behavior
- CURL and HTTPS, "Cannot resolve host"
How to Fix curl: (6) Could not resolve host Error in Linux
As Linux users continue to skillfully nurture and grow their user experience, they soon realize that they become more performant and productive while in the Linux command-line environment.
The Linux OS environment exposes its users to terminal-based tools like Curl for a non-interactive download and upload of targeted network/internet-based files, which is similar to the Wget utility and both share some similarities in their implementation and functionalities.
The primary role of the Curl utility as highlighted on its manual page is to transfer a targeted URL.
It supports numerous protocols with the common ones being FTP, FTPS, HTTP, HTTPS, SCP, SFTP, SMTP, and SMTP.
The Curl command syntax is as follows:
We can show its implementation by using it with a random URL.
$ curl https://google.com -o linuxshelltips.txt
In the above command, Curl’s findings from accessing the highlighted URL are saved in the succeeding text file.
curl: (6) could not resolve host Error
Mostly, such an error occurs when there is an issue with a Linux server’s DNS resolver. A Linux administrator will categorize/define this challenge as a server management service issue.
This error is likely to take several forms when the curl command is executed from the Linux terminal and the most popular ones include:
- curl: (6) could not resolve host: domain_name.extension; Name or service not known
- curl: (6) could not resolve host: domain_name.extension e.g. ubuntumint.com
- curl: (6) could not resolve host: application
Now that we have highlighted the primary reason that might be behind the stated curl command error during its execution on a Linux terminal, it’s time to fix the problem.
Solution 1: Missing Working DNS Nameserver
A nameserver is basically a bridge between a working/purchased domain name and the IP address of a server. When you purchase or subscribe to a domain name, and before you use/link this domain name to your remote Linux server, you need to configure a DNS nameserver. A DNS nameserver enables a user to use a domain name to access a remote server instead of using its IP address.
On your Linux server/machine, the file /etc/resolv.conf is responsible for the DNS nameserver entries auto-generated by NetworkManager.
This file can hold more than one DNS nameserver entry. As you might have noted, the syntax for adding a DNS nameserver entry in this file should resemble the following:
For instance, if you were to add Google public nameservers to this file, it would look like the following:
nameserver 192.168.100.1 nameserver 8.8.8.8 nameserver 8.8.4.4
If you are using a private DNS nameserver, add it to the /etc/resolv.conf file. Update or reboot the system if possible and the host should start resolving.
Solution 2: Curl Syntax Errors
Make sure the curl command execution adheres to its correct syntax usage. A syntax error can arise from something as simple as the misuse of an escape sequence (/) or an illegal spacing on the URL.
The curl: (6) could not resolve host error in Linux primarily relates to wrongful/missing DNS nameserver setup or a random syntax error that can be scanned and fixed.
CURL and HTTPS, «Cannot resolve host»
I’m trying to fetch the contents of a page using CURL. The page that is doing the fetching is https and the page it is trying to fetch is also https. I’m getting an error «Couldn’t resolve host» with all of the settings I try.
$c=curl_init(); curl_setopt($c, CURLOPT_URL,$url); //curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:x.x.x) Gecko/20041107 Firefox/x.x"); curl_setopt ($c, CURLOPT_RETURNTRANSFER, TRUE); //curl_setopt($c, CURLOPT_SSL_VERIFYPEER, TRUE); //curl_setopt($c, CURLOPT_SSL_VERIFYHOST, TRUE); curl_setopt($c, CURLOPT_HEADER, FALSE); $html=curl_exec($c); if($html === false) < echo curl_error($c); >else < echo 'Operation completed without any errors'; >curl_close($c);
11 Answers 11
I found that curl can decide to use IPv6, in which case it tries to resolve but doesn’t get an IPv6 answer (or something to that effect) and times out.
You can try the curl command line switch -4 to test this out:
In PHP, you can configure this line by setting this:
curl_setopt($c, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
Just an FYI. Had an issue with PHP Curl not working. Everything else on the server was working fine. Added these options and fixed it. The strange thing is that everything was working fine without any changes until recently. Obscure issue for sure but glad this worked!
Not sure what happened yesterday (21st of March 2017) but we experienced this problem on multiple servers to running PHP 7. Problem was solved after adding this line to the Curl request and restarting PHP-FPM.
Yesterday (21st March 17) we also found servers stopped working with DNS lookups for curl, really strange. Restart of php5.6-fpm worked then failed again a day later (today), will put the ipv4 dns option in and test when it fails again.
The Ubuntu bug is fixed. Check your apt logs to see if it’s updated yet with cat /var/log/apt/history.log . If not you probably need to run a apt-get update and apt-get upgrade . A restart of PHP-FPM will do the trick after the fix.
$_h = curl_init(); curl_setopt($_h, CURLOPT_HEADER, 1); curl_setopt($_h, CURLOPT_RETURNTRANSFER, 1); curl_setopt($_h, CURLOPT_HTTPGET, 1); curl_setopt($_h, CURLOPT_URL, 'YOUR_URL' ); curl_setopt($_h, CURLOPT_DNS_USE_GLOBAL_CACHE, false ); curl_setopt($_h, CURLOPT_DNS_CACHE_TIMEOUT, 2 ); var_dump(curl_exec($_h)); var_dump(curl_getinfo($_h)); var_dump(curl_error($_h));
Maybe this helps someone. Using docker I stumble in this error. Editing hosts file in guest machine fixed. No brainer but useful if you’ve your mind elsewhere
I had the same problem. Coudn’t resolve google.com. There was a bug somewhere in php fpm, which i am using. Restarting php-fpm solved it for me.
This happened to me as well. Hostname resolved fine on the CLI, but PHP-FPM couldn’t resolve the hostname of our ElasticSearch cluster until a restart of PHP-FPM. Pretty annoying since I don’t know how to prevent it yet and we’re about to put this server into production.
For me it is not cURL, but hostname in SOAP client & PDO, after restart it will come back after awhile. i’m still pulling my hair
Just a note which may be helpful- I was having this trouble with Apache on my laptop (which connects by wifi AFTER startup), and restarting the server (after connect) fixed the issue. I guess in my case this may be to do with apache starting offline and perhaps there noting that DNS lookups fail?
There is a current bug in glibc on Ubuntu which can have this effect: https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1674733
To resolve it, update libc and all related (Packages that will be upgraded: libc-bin libc-dev-bin libc6 libc6-dev libfreetype6 libfreetype6-dev locales multiarch-support) and restart the server.
After tried all above, still can’t resolved my issue yet. But got new solution for my problem.
At server where you are going to make a request, there should be a entry of your virtual host.
The reason if you are making request from server to itself then, to resolve your virtual host or to identify it, server would need above stuff, otherwise server won’t understand your requesting(origin) host.
We need to add host security certificate to php.ini file. For local developement enviroment we can add cacert.pem in your local php.ini.
do phpinfo(); and file your php.ini path open and add uncomment ;curl.capath
Unfortunately your post is covering a different issue. I don’t think this solution relates to the «Cannot resolve host» error.
If you do it on Windows XAMPP/WAMP it probaly won’t work as in my case.
I solved the problem setting up Laravel’s Homestead/Vagrant solution to create my (Ubuntu) development environment — it has built-in: Nginx, PHP 5.6, PHP 7.3, PHP 7.2, PHP 7.1, MySQL, PostgreSQL, Redis, Memcached, Node. to name just a few.
See here for info how to set up the environment — it’s really worth the effort!
Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes!
Then you can easily switch PHP versions or set up more virtual hosts, new databases just in seconds.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cURL error 6: Could not resolv http://curl.haxx.se/libcurl/c/libcurl-errors.html) #1901
cURL error 6: Could not resolv http://curl.haxx.se/libcurl/c/libcurl-errors.html) #1901
Comments
Actual Behavior
Getting this error message when trying to work with passport in my project on my local server.
CurlFactory.php line 186:
cURL error 6: Could not resolve host: api.project.local (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
Expected Behavior
Get oauth authentication tokens after calling post url to project/oauth/token
< "token_type": "Bearer", "expires_in": 518399, "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6Ijk0MWU3Y2Q2Y2I1ZTEyYmYyYzAzYTIzY2I1YWM5YjY3YjI0MmU2NTUwOWRhODVlZTMxNzc3MjIwODA3ZTA2ZGY1YWIwYjMzNDg2MDA2MTZlIn0.eyJhdWQiOiIxIiwianRpIjoiOTQxZTdjZDZjYjVlMTJiZjJjMDNhMjNjYjVhYzliNjdiMjQyZTY1NTA5ZGE4NWVlMzE3NzcyMjA-rkLpvJhuju4Qlo0QNjsXUUHXq6GyqqiQTNa2d0IUsWdAOSLsy1bMu4Z2ga_Jj1L1ThwbDOfy7kE4_5SDfKKIyKXO_-iw", "refresh_token": "L8p2NAqRZfi1fP1XyO3NW36dCqa6HZJWgNKkuR8IMz2LJe5711nRHPMP734caln1+8m+GC6K79yTjRjru01iR7LKP1CCseixQ8mkzXWZb+roQv32qdkXVSeCzObecOI2ZWq+l1KNs12NA3KIZJ4bS0N2rOYxlw3KTNx55uydH13vmanbeXIpym0ha8op0M9s9HvwPc+dJUhjL20JzDGCcyuhciGIe6CTKyBuqi4dNA8tIeALLPSSqtvd0QsRWCWTVBL72RVeEeIq/4kFppE auto">Steps to Reproduce install laravel 5.3
install passport package
extract laravel auth scaffold to app directory.
put this line of code inside of authentication controller when user is logged in :
path = Project/app/Foundation/Auth/AuthenticatesUsers.php
post('Project.local/oauth/token', [ 'form_params' => [ 'grant_type' => 'password', 'client_id' => 1, 'client_secret' => 'xKqNbzcXyjySg20nVuVLw5nk5PAMhFQOQwRTeTjd', 'username' => $userobject['email'], 'password' => $userobject['password'], 'scope' => '', ], ]); "> $http = new Client; $response = $http->post('Project.local/oauth/token', [ 'form_params' => [ 'grant_type' => 'password', 'client_id' => 1, 'client_secret' => 'xKqNbzcXyjySg20nVuVLw5nk5PAMhFQOQwRTeTjd', 'username' => $userobject['email'], 'password' => $userobject['password'], 'scope' => '', ], ]);
On some servers it works, on some it doesn't and I don't know what is the cause. the server I'm facing problem right now is ubuntu14.04 server with php5.6 and apache2 and mysql5.5
The text was updated successfully, but these errors were encountered:
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:
- The domain name you are trying to access could not be resolved to an IP address. This could be because the domain name is spelled incorrectly, or because the DNS server you are using is unable to resolve the domain name.
- There could be a network issue preventing curl from reaching the target server. This could be a problem with your network connection or with the server itself.
- There could be a problem with curl or the SSL/TLS certificate on the server you are trying to access.
To troubleshoot this issue, you could try the following:
- Check that the domain name is spelled correctly and that you are using the correct URL.
- Check your network connection and try again later.
- If the problem persists, you could try using the --resolve option to specify the IP address of the target server manually.
- You could also try using the --insecure option to disable certificate validation. This is not recommended for production environments, but it can be useful for troubleshooting.
- You could try using the --verbose option to get more information about the request and response. This might give you more clues about what is causing the problem.
- You could also try using the --connect-timeout option to specify a timeout for establishing a connection to the server. This can be useful if the server is taking a long time to respond.
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.