有没有人见过这个? 请注意,这不仅发生在google.com上,而且发生在我尝试的每个域上。 这是一个无线连接(WEP),但我不知道这是如何相关的:
$ curl -v google.com # This takes about 60s to return * getaddrinfo(3) failed for google.com:80 * Couldn't resolve host 'google.com' * Closing connection #0 curl: (6) Couldn't resolve host 'google.com' $ wget google.com --2011-11-28 14:44:08-- http://google.com/ Resolving google.com... failed: Name or service not known. wget: unable to resolve host address `google.com' $ ping google.com PING google.com (209.85.148.147) 56(84) bytes of data. 64 bytes from fra07s07-in-f147.1e100.net (209.85.148.147): icmp_req=2 ttl=54 time=136 ms 64 bytes from fra07s07-in-f147.1e100.net (209.85.148.147): icmp_req=3 ttl=54 time=34.0 ms 64 bytes from fra07s07-in-f147.1e100.net (209.85.148.147): icmp_req=4 ttl=54 time=34.3 ms 64 bytes from fra07s07-in-f147.1e100.net (209.85.148.147): icmp_req=5 ttl=54 time=42.5 ms 64 bytes from fra07s07-in-f147.1e100.net (209.85.148.147): icmp_req=6 ttl=54 time=44.7 ms 64 bytes from fra07s07-in-f147.1e100.net (209.85.148.147): icmp_req=7 ttl=54 time=34.5 ms ^C --- google.com ping statistics --- 8 packets transmitted, 6 received, 25% packet loss, time 7007ms rtt min/avg/max/mdev = 34.063/54.376/136.026/36.758 ms $ host google.com google.com has address 209.85.148.106 google.com has address 209.85.148.147 google.com has address 209.85.148.99 google.com has address 209.85.148.103 google.com has address 209.85.148.104 google.com has address 209.85.148.105 google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com. $ host google.com 192.168.1.201 Using domain server: Name: 192.168.1.201 Address: 192.168.1.201#53 Aliases: google.com has address 209.85.148.103 google.com has address 209.85.148.104 google.com has address 209.85.148.105 google.com has address 209.85.148.106 google.com has address 209.85.148.147 google.com has address 209.85.148.99 google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 30 alt2.aspmx.l.google.com. $ cat /etc/resolv.conf # Generated by NetworkManager nameserver 192.168.1.201 $ cat /etc/hosts 127.0.0.1 localhost ::1 localhost $ netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 wlan0 127.0.0.0 127.0.0.1 255.0.0.0 UG 0 0 0 lo 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
基本上,包括Firefox在内的任何应用程序都无法执行名称查找。 更重要的是,如果我把无线networking连接到网线并插入以太网线,一切都很好。
也许你有一些非常奇怪和限制性的SELinux(或grsecurity)规则?
如果没有,请尝试使用strace -o /tmp/wtf -fF curl -v google.com并尝试从/tmp/wtf输出文件中找出发生了什么事情。
使用这个: https : //www.centos.org/modules/newbb/viewtopic.php?topic_id=39343
我发现了一个帮助我排除故障的关键命令:
[root @ localhost〜]#wget -6 URL失败
[root @ localhost〜]#wget -4 URL工作
这是与某些使用情况下导致问题的默认ipv6堆栈有关。 禁用ipv6来解决。
检查你的/etc/nsswitch.conf 。 如果hosts行说类似的东西
hosts: files dns
我和你一样困惑。 但是如果它说了类似的话
hosts: files
那么DNS正在工作的事实(请参阅host命令的输出)将不会帮助curl,这是通过标准的操作系统库进行名称parsing,这些库被告知不要使用DNS。
我有同样的问题 – 主机,nslookup解决好,curl – 不能在相同的主机名。
tcpdumping通信后,我发现curl试图build立TCP(除了UDP)连接到DNS端口,这是closures在我的路由器。 TCP端口53启用curl后,开始工作完美无瑕。
另一个奇怪的是,如果DNS服务器是常规的绑定安装,这个问题不表面。 如果我使用embedded到路由器DNS服务器,curl突然尝试使用TCP端口,即使它已经收到(!)通过UDP 2ms之前答案。 我想这是错误。
今天我的VE(运行在我的笔记本电脑上)出现了同样的问题,并且发现它非常令人惊讶。 挖和NSlookup的作品,但curl失败。
举个例子:
# curl -v google.com * getaddrinfo(3) failed for google.com:80 * Couldn't resolve host 'google.com' * Closing connection #0 curl: (6) Couldn't resolve host 'google.com'
但是当我在这里看到David T的post的时候,我决定用curl来试试。 所以虽然这失败:
# curl google.com -6 curl: (6) Couldn't resolve host 'google.com'
这成功了:
# curl google.com -4 <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="http://www.google.com/">here</A>. </BODY></HTML>
-6指定curl使用IPv6,-4指定使用IPv4。 我在使用wget的时候遇到了同样的错误,所以肯定会出现主机上IPv6堆栈的一些问题。
所有其他对nsswitch.conf文件和其他BIND conf文件的修改都没有帮助,因为这个实用程序没有这个问题。
你的/etc/resolv.conf文件中可能会出现nslookup允许的错误,但curl不会。
问的问题是“我怎么可能做一个主机查找,但不是curl?
这是可能的,因为curl使用getaddrinfo()来parsingFQDN,而nslookup不能。 相反,我相信nslookup使用一些其他函数或库,或通过自己的自定义代码来parsing/etc/resolv.conf。 我没有看源代码来validation这一点,但是你可以在/etc/resolv.conf的nameserver标记前添加空白来certificate。 NSLOOKUP可以parsing这个,但getaddrinfo()不能。
Example /etc/resolv.conf nameserver 8.8.8.8
如果你的resolv.conf有这个错误,或者nslookup可以容忍的其他错误而不是getaddrinfo(),那么你可以用nslookup来parsing一个FQDN,但是你将不能在这个FQDN上使用curl。
修复:以root身份编辑/etc/resolv.conf并删除名称服务器行上的任何前导空格。
curl装置是否平滑? 如果可能,请尝试重新安装curl。
尝试curl -v google.com以获取更详细的输出以进行debugging。
例如:
curl -v dnserror.test * getaddrinfo(3) failed for dnserror.test:80 * Couldn't resolve host 'dnserror.test' * Closing connection #0 curl: (6) Couldn't resolve host 'dnserror.test'
你是否得到类似的输出?