Fixing ipv6 DNS Delayed Server Response
Situation and Solution
The Challenge: Run IPv6, overcome slow DNS lookups
DNS lookups were taking 5 seconds each time, every time (for many applications, which rely on glibc. Net searches do show a history of this problem. And possible workarounds. Ultimately, the root cause is external, however, making the ideal solution a little hard to reach.
The Attempts: /etc/resolv.conf
The timeout option below did work - sort of. The issue was still occurring, but now only costing 1 second rather than the default 5. The other line solutions didn't have any effect, either alone or in combination with the gai.conf change.
options timeout:1 options single-request options single-request-reopen
The Attempt: /etc/gai.conf
Making this change had no apparent effect at all. Also tried with the others above in /etc/resolv.conf. No luck.
precedence ::ffff:0:0/96 100
nameserver 184.108.40.206 nameserver 2001:470:1f10:c6::2 nameserver 220.127.116.11
The nameserver lines in /etc/resolv.conf were the solution. Presumably the following would also work:
The previous structure of /etc/resolv.conf had that IPv6 nameserver first. This meant that IPv6 queries were made first - every time. And timing out, in my case, in 5 seconds. IPv6 is enabled on the host and functional. But DNS was continually timing out before I put the IPv4 nameserver at the top of the list.
There is no need to restart any application each time you change one of these files. Just try a new curl or getaddrinfo enabled request.