我刚刚安装了 Fedora 19 LXDE。当我第一次为 URL 运行 curl 时,它失败了:
curl -v youtube.com
* Could not resolve host: youtube.com; Name or service not known
* Closing connection 0
curl: (6) Could not resolve host: youtube.com; Name or service not known
如果我立即重新运行此命令,它将成功。
curl -v youtube.com
* About to connect() to youtube.com port 80 (#0)
* Trying 80.239.229.212...
* Connected to youtube.com (80.239.229.212) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: youtube.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Tue, 10 Sep 2013 20:05:20 GMT
< Server: gwiseguy/2.0
< Location: http://www.youtube.com/
< Content-Length: 0
< Content-Type: text/html
< X-XSS-Protection: 1; mode=block
<
* Connection #0 to host youtube.com left intact
似乎如果指定了 -4 选项,一切正常。可能是什么问题?
nslookup 工作正常,分辨率没有问题。
更新:
当我针对失败的尝试运行 strace 时,我看到以下错误:
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
和 echo $LANG LANG=/en_US.UTF-8 有关系吗?
更多信息:
我曾经拥有带有 Gnome 的 Fedora 15。一切正常。然后我尝试了带有 LXDE 和 XFCE 的 Fedora 19。他们都对 curl 有同样的问题。
解决方案:
似乎问题与 IPv6 有关。
1) 使用“--ipv4”创建 ~/.curlrc。它解决了一些浏览器的问题。
2) 要修复 yum,将“ip_resolve=4”添加到 /etc/yum.conf。