Ubuntu – curl and wget attempting an ipv6 connection

curldomain-name-systemipv6Ubuntuwget

On my dedicated server (hosted by OVH), that is running a fresh install of Ubuntu 14.04, curl and wget take approximately 10 seconds to complete a simple request.

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

and only after 10 seconds it'll actually return something. So i've decided to run strace on this:

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

I can clearly see socket(PF_INET6) followed by socket(PF_INET) after all these timeouts. wget behaves in the same way.

More relevant information:

$ 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 shows no inet6 addresses.

How can I prevent this from happening?

Best Answer

Probably you need to indicate IPv4 is preferred over IPv6 as mentioned on this link. https://askubuntu.com/questions/32298/prefer-a-ipv4-dns-lookups-before-aaaaipv6-lookups

Change setting under /etc/gai.conf.