Reputation: 24756
when I try to load a web page to terminal it gives curl: (6) Could not resolve host
error.
I have internet in my PC and trying from my home internet connection. So as I there is no any proxy involve here.
[root@localhost kevin]# curl http://google.com
curl: (6) Could not resolve host: google.com; Name or service not known
clean all
and tried again but no lucky.
But if I use IP instead of the domain name, it works fine.
[root@localhost kevin]# curl http://173.194.46.0
any clue please?
Upvotes: 97
Views: 714484
Reputation: 21
In my case, the problem was in the Static Route Table. Must be removed if a static route was previously added
Upvotes: 0
Reputation: 7590
My case on MacOS was simple: I closed the iTerm window I was using and opened a new one.
It seems likely that this is an issue with CURL cacheing DNS responses given that I was messing around with my DNS when I ran into the same error as the OP.
Upvotes: 0
Reputation: 31
I had an issue with IPV6 that suddenly showed up in wordpress admin where curl failed to connect to wordpress.org etc giving
An unexpected error occurred. Something may be wrong with WordPress.org
and also
Installation failed: Download failed. cURL error 28: Resolving timed out after 10005 milliseconds
I eventually sorted by adding the following as a php file in mu-plugins:
add_action( 'http_api_curl', function( $curl_handle ) { curl_setopt( $curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );});
and also when using curl directly in php by using the following option in the options array:
curl_setopt_array($curl, array(CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4));
The OS is IBM i (OS400/i5OS) v7.2 running on Power 6 and the php version is 8.1.10. Interestingly IPV6 is not active on the box.
Upvotes: 0
Reputation: 188
In Our case, the command was passed through mail/skype and the person who needs to execute copied an extra space.
we found that extra space after an hour and removing that made it work.
Upvotes: 1
Reputation: 66380
There is no need to disable IPv6 as the answer suggests. The reason curl fails is simply because the DNS resolution is missing.
There is one liner solution to this.
If you care about what is inside /etc/resolv.conf
then append it:
echo 'nameserver 1.1.1.1' | sudo tee -a /etc/resolv.conf >/dev/null
I usually don't care and just replace the content of the file:
echo 'nameserver 1.1.1.1' | sudo tee /etc/resolv.conf >/dev/null
Upvotes: 15
Reputation: 1554
I have today similar problem. But weirder.
host pl.archive.ubuntu.com
dig pl.archive.ubuntu.com
, dig @127.0.1.1 pl.archive.ubuntu.com
$ curl -v http://google.com/
* Trying 172.217.18.78...
* Connected to google.com (172.217.18.78) port 80 (#0)
> GET / HTTP/1.1
> Host: google.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 302 Found
< Cache-Control: private
< Content-Type: text/html; charset=UTF-8
< Referrer-Policy: no-referrer
< Location: http://www.google.pl/?gfe_rd=cr&ei=pt9UWfqXL4uBX_W5n8gB
< Content-Length: 256
< Date: Thu, 29 Jun 2017 11:08:22 GMT
<
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.pl/?gfe_rd=cr&ei=pt9UWfqXL4uBX_W5n8gB">here</A>.
</BODY></HTML>
* Connection #0 to host google.com left intact
$ curl -v http://pl.archive.ubuntu.com/
* Could not resolve host: pl.archive.ubuntu.com
* Closing connection 0
curl: (6) Could not resolve host: pl.archive.ubuntu.com
Revelation
Eventually I used strace
on curl and found that it was connection to nscd
deamon.
connect(4, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = 0
Solution
I've restarted the nscd service (Name Service Cache Daemon) and it helped to solve this issue!
systemctl restart nscd.service
Upvotes: 7
Reputation: 24756
Issues were:
Here is how I fixed it:
IPV6 Disabling
su
and enter to log in as the super usercd /etc/modprobe.d/
to change directory to /etc/modprobe.d/
vi disableipv6.conf
to create a new file thereEsc + i
to insert data to fileinstall ipv6 /bin/true
on the file to avoid loading IPV6 related modulesEsc + :
and then wq
for save and exitreboot
to restart fedoralsmod | grep ipv6
Add Google DNS server
su
and enter to log in as the super usercat /etc/resolv.conf
to check what DNS server your Fedora using. Mostly this will be your Modem IP address.8.8.8.8
and 8.8.4.4
. But in future those may change.vi /etc/resolv.conf
to edit the resolv.conf
fileEsc + i
for insert data to fileType below two lines in the file
nameserver 8.8.8.8
nameserver 8.8.4.4
-Type Esc + :
and then wq
for save and exit
Here is my blog post about this: http://codeketchup.blogspot.sg/2014/07/how-to-fix-curl-6-could-not-resolve.html
Upvotes: 112
Reputation: 41
Try nslookup google.com to determine if there's a DNS issue. 192.168.1.254 is your local network address and it looks like your system is using it as a DNS server. Is this your gateway/modem router as well? What happens when you try ping google.com. Can you browse to it on a Internet web browser?
Upvotes: 2
Reputation: 3870
Perhaps you have some very weird and restrictive SELinux rules in place?
If not, try strace -o /tmp/wtf -fF curl -v google.com
and try to spot from /tmp/wtf
output file what's going on.
Upvotes: 7