Nay*_*iya 39 linux terminal curl fedora
当我尝试将网页加载到终端时,它会curl: (6) Could not resolve host出错.
我在我的电脑上有互联网,并尝试从我家的互联网连接.所以我这里没有任何代理涉及.
[root@localhost kevin]# curl http://google.com
curl: (6) Could not resolve host: google.com; Name or service not known
Run Code Online (Sandbox Code Playgroud)
clean all 再试一次,但没有幸运.
但如果我使用IP而不是域名,它可以正常工作.
[root@localhost kevin]# curl http://173.194.46.0
有什么线索吗?
Nay*_*iya 58
问题是:
以下是我修复它的方法:
IPV6禁用
su并输入登录为超级用户cd /etc/modprobe.d/以将目录更改为/etc/modprobe.d/vi disableipv6.conf以在那里创建新文件Esc + i将数据插入文件install ipv6 /bin/true在文件上键入以避免加载与IPV6相关的模块Esc + :然后wq保存并退出reboot以重新启动fedoralsmod | grep ipv6添加Google DNS服务器
su并输入登录为超级用户cat /etc/resolv.conf以检查您的Fedora使用的DNS服务器.这主要是你的调制解调器IP地址.8.8.8.8和8.8.4.4.但将来这些可能会改变.vi /etc/resolv.conf以编辑resolv.conf文件Esc + i将数据插入文件在文件中键入以下两行
nameserver 8.8.8.8
nameserver 8.8.4.4
-Type Esc + :然后wq进行保存并退出
这是我的博客文章:http: //codeketchup.blogspot.sg/2014/07/how-to-fix-curl-6-could-not-resolve.html
没有必要像答案所建议的那样禁用 IPv6。curl 失败的原因很简单,就是缺少 DNS 解析。
有一种班轮解决方案可以解决这个问题。
如果您关心里面的内容,/etc/resolv.conf请附加它:
echo 'nameserver 1.1.1.1' | sudo tee -a /etc/resolv.conf >/dev/null
Run Code Online (Sandbox Code Playgroud)
我通常不在乎,只是替换文件的内容:
echo 'nameserver 1.1.1.1' | sudo tee /etc/resolv.conf >/dev/null
Run Code Online (Sandbox Code Playgroud)
也许你有一些非常奇怪和限制性的SELinux规则?
如果没有,尝试strace -o /tmp/wtf -fF curl -v google.com尝试从/tmp/wtf输出文件中发现正在发生的事情.
我今天有类似的问题。但更奇怪。
host pl.archive.ubuntu.comdig 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
Run Code Online (Sandbox Code Playgroud)
启示
最终我strace在 curl 上使用,发现它是与nscddeamon 的连接。
connect(4, {sa_family=AF_LOCAL, sun_path="/var/run/nscd/socket"}, 110) = 0
Run Code Online (Sandbox Code Playgroud)
解决方案
我重新启动了 nscd 服务(名称服务缓存守护程序),它帮助解决了这个问题!
systemctl restart nscd.service
Run Code Online (Sandbox Code Playgroud)