curl 和 wget 尝试建立 ipv6 连接

curl 和 wget 尝试建立 ipv6 连接

在我的专用服务器(由 OVH 托管)上,运行全新安装的 Ubuntu 14.04,curl 和 wget 大约需要 10 秒才能完成一个简单的请求。

$ curl -v google.com
* Rebuilt URL to: google.com/
* Hostname was NOT found in DNS cache

并且只有 10 秒后它才会真正返回一些内容。所以我决定运行斯特拉斯关于此:

write(2, "Hostname was NOT found in DNS ca"..., 36) = 36
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = 3
close(3)                                = 0
mmap(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f0a24fb8000
mprotect(0x7f0a24fb8000, 4096, PROT_NONE) = 0
clone(child_stack=0x7f0a257b7f70, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f0a257b89d0, tls=0x7f0a257b8700, child_tidptr=0x7f0a257b89d0) = 5047
poll(0, 0, 4)                           = 0 (Timeout)
poll(0, 0, 8)                           = 0 (Timeout)
poll(0, 0, 16)                          = 0 (Timeout)
poll(0, 0, 32)                          = 0 (Timeout)
poll(0, 0, 64)                          = 0 (Timeout)
poll(0, 0, 128)                         = 0 (Timeout)
poll(0, 0, 256)                         = 0 (Timeout)
poll(0, 0, 1000)                        = 0 (Timeout)
poll(0, 0, 1000)                        = 0 (Timeout)

[...] (10 times or so)

poll(0, 0, 1000)                        = 0 (Timeout)
poll(0, 0, 1000)                        = 0 (Timeout)
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
write(2, "*", 1)                        = 1
write(2, " ", 1)                        = 1
write(2, "  Trying 74.125.228.7...\n", 25) = 25

我可以清楚地看到套接字(PF_INET6)其次是套接字(PF_INET)在所有这些超时之后,wget 的行为也是一样的。

更多相关信息:

$ sudo sysctl -p
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

$ sudo cat /etc/default/bind9
RESOLVCONF=yes
OPTIONS="-4 -u bind"

$ cat /proc/sys/net/ipv6/conf/all/disable_ipv6
1

ifconfig 没有显示 inet6 地址。

我怎样才能防止这种情况发生?

答案1

可能需要您指出 IPv4 优于 IPv6,如此链接中所述。https://askubuntu.com/questions/32298/prefer-a-ipv4-dns-lookups-before-aaaaipv6-lookups

更改 /etc/gai.conf 下的设置。

相关内容