5

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?

5
  • Does your server have a v6 address?
    – EEAA
    Aug 15, 2014 at 21:12
  • Updated my post with more info - I don't think it does.
    – Daniel S
    Aug 15, 2014 at 21:24
  • 1
    Don't go out of your way to disable IPv6. This just causes more problems. If you really don't have it, it wouldn't be used anyway. If you do have it, you should be using it. Aug 15, 2014 at 21:50
  • which version of ubuntu is this? Which version of curl?
    – mc0e
    Aug 4, 2015 at 15:13
  • @MichaelHampton unfortunately that's not true as of the version of curl packaged with Ubuntu 14.04. the latest upstream libcurl does implement fallback to IPv4 if IPv6 fails, but earlier versions prefer IPv6 if it exists in DNS and don't fall back if the IPv6 network connectivity isn't actually there.
    – mc0e
    Aug 4, 2015 at 15:34

1 Answer 1

-2

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.

6
  • Curl has its own logic for such things.
    – mc0e
    Aug 4, 2015 at 15:32
  • Everything has default. So without specifically instructing what IP protocol to use, curl has to follow OS's preference as default. Make sense?
    – antimatter
    Aug 13, 2015 at 15:26
  • Curl now implements logic from the Happy Eyeballs algorithm, to smooth the transition to IPv6, though that didn't make it to release 14.04. It was adopted in curl 7.34.0 (release history), so it wasn't in Ubuntu at the time of the question (it is in 15.04). Prior to that though, curl had its own logic for doing dns requests for ipv4 and ipv6 and deciding which transport to use. Check the source code if you don't believe me.
    – mc0e
    Aug 13, 2015 at 16:04
  • Yes, let me correct my comment. Curl will make system call to resolve hostname which will be sent to getaddressinfo. The IP protocol preference of that system call is governed by gai.conf.
    – antimatter
    Aug 13, 2015 at 16:04
  • @mc0e, can you explain what is your understanding of curl logic in resolving DNS? Reference?
    – antimatter
    Aug 13, 2015 at 16:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .