curl:(6)无法解析host: google.com;不知道的名称或服务

时间:2022-05-15 13:45:35

when I try to load a web page to terminal it gives curl: (6) Could not resolve host error.

当我尝试将web页面加载到终端时,它给出了curl:(6)不能解决主机错误。

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.

但是如果我使用IP而不是域名,那就没问题了。

[root@localhost kevin]# curl http://173.194.46.0

(root@localhost凯文)# curl http://173.194.46.0

any clue please?

任何线索吗?

6 个解决方案

#1


42  

Issues were:

问题是:

  1. IPV6 enabled
  2. IPV6启用
  3. Wrong DNS server
  4. 错误的DNS服务器

Here is how I fixed it:

我是这样修复的:

IPV6 Disabling

IPV6禁用

  • Open Terminal
  • 打开终端
  • Type su and enter to log in as the super user
  • 输入su并输入以作为超级用户登录
  • Enter the root password
  • 输入根密码
  • Type cd /etc/modprobe.d/ to change directory to /etc/modprobe.d/
  • cd型/etc/modprobe.d将目录更改为/etc/modprobe.d/
  • Type vi disableipv6.conf to create a new file there
  • vi disableipv6类型。在那里创建一个新文件
  • Press Esc + i to insert data to file
  • 按Esc + i将数据插入文件
  • Type install ipv6 /bin/true on the file to avoid loading IPV6 related modules
  • 在文件中键入安装ipv6 /bin/true以避免加载与ipv6相关的模块
  • Type Esc + : and then wq for save and exit
  • 输入Esc +:然后输入wq进行保存和退出
  • Type reboot to restart fedora
  • 输入重新启动以重新启动fedora
  • After reboot open terminal and type lsmod | grep ipv6
  • 在重启终端和lsmod |型ipv6之后。
  • If no result, it means you properly disabled IPV6
  • 如果没有结果,这意味着您正确禁用了IPV6。

Add Google DNS server

添加谷歌DNS服务器

  • Open Terminal
  • 打开终端
  • Type su and enter to log in as the super user
  • 输入su并输入以作为超级用户登录
  • 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.
  • 类型的猫/etc/resolv.conf检查您的Fedora使用的DNS服务器。这主要是你的调制解调器IP地址。
  • Now we have to Find a powerful DNS server. Luckily there is a open DNS server maintain by Google.
  • 现在我们必须找到一个强大的DNS服务器。幸运的是,有一个由谷歌维护的开放DNS服务器。
  • Go to this page and find out what are the "Google Public DNS IP addresses"
  • 浏览本页,找出“谷歌公共DNS IP地址”
  • Today those are 8.8.8.8 and 8.8.4.4. But in future those may change.
  • 现在是8。8和8。4。但在未来,这些可能会改变。
  • Type vi /etc/resolv.conf to edit the resolv.conf file
  • vi型/etc/resolv.conf编辑resolv。配置文件
  • Press Esc + i for insert data to file
  • 按Esc + i插入数据到文件中
  • 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

    命名服务器8.8.8.8命名服务器8.8.4.4

    -Type Esc + : and then wq for save and exit

    -Type Esc +:然后wq保存和退出

  • 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.
  • 但每次重启电脑时,你的/etc/resolvconf将被默认替换。我会让你们找到避免这种情况的方法。

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

以下是我关于这方面的博客:http://codeketchup.blogspot.sg/2014/07/howto fix-curl-6- coul-not -resolve.html

#2


5  

Perhaps you have some very weird and restrictive SELinux rules in place?

也许您有一些非常奇怪和限制性的SELinux规则?

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.

如果没有,请尝试strace -o /tmp/wtf -fF curl -v google.com,并尝试从/tmp/wtf输出文件中找出发生了什么。

#3


0  

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?

尝试使用nslookup google.com来确定是否存在DNS问题。192.168.1.254是您的本地网络地址,看起来您的系统将其用作DNS服务器。这也是你的网关/调制解调器路由器吗?当你尝试ping google。com时会发生什么?你能在网络浏览器上浏览它吗?

#4


0  

We had the same problem on our Linux Server and we just restarted PHP as well as Apache. We believe that some DNS cache inside curls was wrong and just restarting PHP solved this.

我们在Linux服务器上也遇到了同样的问题,我们重新启动了PHP和Apache。我们认为卷中的一些DNS缓存是错误的,重新启动PHP就解决了这个问题。

#5


0  

I have today similar problem. But weirder.

我今天遇到了类似的问题。但更奇怪。

  • host - works host pl.archive.ubuntu.com
  • host - works host .archive.ubuntu.com。
  • dig - works on default and on all other DNS's dig pl.archive.ubuntu.com, dig @127.0.1.1 pl.archive.ubuntu.com
  • dig -在默认情况下工作,在所有其他DNS的dig pl.archive.ubuntu.com上工作,dig @127.0.1.1 pl.archive.ubuntu.com
  • curl - doesn't work! but for some addresses it does. WEIRD! Same in Ruby, APT and many more.
  • 旋度——不工作!但对于某些地址,它确实存在。奇怪!Ruby也是如此,APT和更多。
$ 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.

最后我在curl上使用了strace,发现它与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!

我重新启动了nscd服务(名称服务缓存守护进程),它帮助解决了这个问题!

systemctl restart nscd.service

#6


-1  

I had the same problem, except on an Ubuntu VM. Turns out my wifi had disconnected. I didn't think to check at first because my host's (Windows 10) internet had been working just fine. So all I had to do was reconnect the internet.

我也有同样的问题,除了在Ubuntu VM上。原来我的wifi已经断开了。我一开始没有想过要检查,因为我的主机(Windows 10)的网络一直运行得很好。所以我要做的就是重新连接互联网。

#1


42  

Issues were:

问题是:

  1. IPV6 enabled
  2. IPV6启用
  3. Wrong DNS server
  4. 错误的DNS服务器

Here is how I fixed it:

我是这样修复的:

IPV6 Disabling

IPV6禁用

  • Open Terminal
  • 打开终端
  • Type su and enter to log in as the super user
  • 输入su并输入以作为超级用户登录
  • Enter the root password
  • 输入根密码
  • Type cd /etc/modprobe.d/ to change directory to /etc/modprobe.d/
  • cd型/etc/modprobe.d将目录更改为/etc/modprobe.d/
  • Type vi disableipv6.conf to create a new file there
  • vi disableipv6类型。在那里创建一个新文件
  • Press Esc + i to insert data to file
  • 按Esc + i将数据插入文件
  • Type install ipv6 /bin/true on the file to avoid loading IPV6 related modules
  • 在文件中键入安装ipv6 /bin/true以避免加载与ipv6相关的模块
  • Type Esc + : and then wq for save and exit
  • 输入Esc +:然后输入wq进行保存和退出
  • Type reboot to restart fedora
  • 输入重新启动以重新启动fedora
  • After reboot open terminal and type lsmod | grep ipv6
  • 在重启终端和lsmod |型ipv6之后。
  • If no result, it means you properly disabled IPV6
  • 如果没有结果,这意味着您正确禁用了IPV6。

Add Google DNS server

添加谷歌DNS服务器

  • Open Terminal
  • 打开终端
  • Type su and enter to log in as the super user
  • 输入su并输入以作为超级用户登录
  • 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.
  • 类型的猫/etc/resolv.conf检查您的Fedora使用的DNS服务器。这主要是你的调制解调器IP地址。
  • Now we have to Find a powerful DNS server. Luckily there is a open DNS server maintain by Google.
  • 现在我们必须找到一个强大的DNS服务器。幸运的是,有一个由谷歌维护的开放DNS服务器。
  • Go to this page and find out what are the "Google Public DNS IP addresses"
  • 浏览本页,找出“谷歌公共DNS IP地址”
  • Today those are 8.8.8.8 and 8.8.4.4. But in future those may change.
  • 现在是8。8和8。4。但在未来,这些可能会改变。
  • Type vi /etc/resolv.conf to edit the resolv.conf file
  • vi型/etc/resolv.conf编辑resolv。配置文件
  • Press Esc + i for insert data to file
  • 按Esc + i插入数据到文件中
  • 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

    命名服务器8.8.8.8命名服务器8.8.4.4

    -Type Esc + : and then wq for save and exit

    -Type Esc +:然后wq保存和退出

  • 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.
  • 但每次重启电脑时,你的/etc/resolvconf将被默认替换。我会让你们找到避免这种情况的方法。

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

以下是我关于这方面的博客:http://codeketchup.blogspot.sg/2014/07/howto fix-curl-6- coul-not -resolve.html

#2


5  

Perhaps you have some very weird and restrictive SELinux rules in place?

也许您有一些非常奇怪和限制性的SELinux规则?

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.

如果没有,请尝试strace -o /tmp/wtf -fF curl -v google.com,并尝试从/tmp/wtf输出文件中找出发生了什么。

#3


0  

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?

尝试使用nslookup google.com来确定是否存在DNS问题。192.168.1.254是您的本地网络地址,看起来您的系统将其用作DNS服务器。这也是你的网关/调制解调器路由器吗?当你尝试ping google。com时会发生什么?你能在网络浏览器上浏览它吗?

#4


0  

We had the same problem on our Linux Server and we just restarted PHP as well as Apache. We believe that some DNS cache inside curls was wrong and just restarting PHP solved this.

我们在Linux服务器上也遇到了同样的问题,我们重新启动了PHP和Apache。我们认为卷中的一些DNS缓存是错误的,重新启动PHP就解决了这个问题。

#5


0  

I have today similar problem. But weirder.

我今天遇到了类似的问题。但更奇怪。

  • host - works host pl.archive.ubuntu.com
  • host - works host .archive.ubuntu.com。
  • dig - works on default and on all other DNS's dig pl.archive.ubuntu.com, dig @127.0.1.1 pl.archive.ubuntu.com
  • dig -在默认情况下工作,在所有其他DNS的dig pl.archive.ubuntu.com上工作,dig @127.0.1.1 pl.archive.ubuntu.com
  • curl - doesn't work! but for some addresses it does. WEIRD! Same in Ruby, APT and many more.
  • 旋度——不工作!但对于某些地址,它确实存在。奇怪!Ruby也是如此,APT和更多。
$ 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.

最后我在curl上使用了strace,发现它与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!

我重新启动了nscd服务(名称服务缓存守护进程),它帮助解决了这个问题!

systemctl restart nscd.service

#6


-1  

I had the same problem, except on an Ubuntu VM. Turns out my wifi had disconnected. I didn't think to check at first because my host's (Windows 10) internet had been working just fine. So all I had to do was reconnect the internet.

我也有同样的问题,除了在Ubuntu VM上。原来我的wifi已经断开了。我一开始没有想过要检查,因为我的主机(Windows 10)的网络一直运行得很好。所以我要做的就是重新连接互联网。