Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl: (6) Could not resolve host: google.com; Name or service not known

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?

like image 541
Nayana Adassuriya Avatar asked Jul 26 '14 05:07

Nayana Adassuriya


People also ask

Could not resolve host cURL 6?

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.

What does cURL error 6 mean?

Hi, cURL error 6. The error indicates that the network that UpdraftPlus is attempting to connect to is unreachable. This shows that the connection isn't being blocked, but is failing to reach the UpdraftPlus.com servers.

Could not resolve host reason?

This error means that the hostname you are trying to connect to cannot be resolved to an IP address. (Hostnames are resolved to IP addresses by a DNS (Domain NameServer)). Please check what you have entered in the Address field. You will need the valid hostname of an FTP server or a valid IP address.


2 Answers

Issues were:

  1. IPV6 enabled
  2. Wrong DNS server

Here is how I fixed it:

IPV6 Disabling

  • Open Terminal
  • Type su and enter to log in as the super user
  • Enter the root password
  • Type cd /etc/modprobe.d/ to change directory to /etc/modprobe.d/
  • Type vi disableipv6.conf to create a new file there
  • Press Esc + i to insert data to file
  • Type install ipv6 /bin/true on the file to avoid loading IPV6 related modules
  • Type Esc + : and then wq for save and exit
  • Type reboot to restart fedora
  • After reboot open terminal and type lsmod | grep ipv6
  • If no result, it means you properly disabled IPV6

Add Google DNS server

  • Open Terminal
  • Type su and enter to log in as the super user
  • Enter the root password
  • Type cat /etc/resolv.conf to check what DNS server your Fedora using. Mostly this will be your Modem IP address.
  • Now we have to Find a powerful DNS server. Luckily there is a open DNS server maintain by Google.
  • Go to this page and find out what are the "Google Public DNS IP addresses"
  • Today those are 8.8.8.8 and 8.8.4.4. But in future those may change.
  • Type vi /etc/resolv.conf to edit the resolv.conf file
  • Press Esc + i for insert data to file
  • Comment all the things in the file by inserting # at the begin of the each line. Do not delete anything because can be useful in future.
  • Type 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

  • Now you are done and everything works fine (Not necessary to restart).
  • But every time when you restart the computer your /etc/resolv.conf will be replaced by default. So I'll let you find a way to avoid that.

Here is my blog post about this: http://codeketchup.blogspot.sg/2014/07/how-to-fix-curl-6-could-not-resolve.html

like image 174
Nayana Adassuriya Avatar answered Oct 16 '22 17:10

Nayana Adassuriya


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.

like image 42
Sathish Avatar answered Oct 16 '22 17:10

Sathish