Celebrazio Net

Contact Us

Fixing ipv6 DNS Delayed Server Response

October, 2017

A VPS server was experiencing strange delays. The standard approaches to fixing them didn't resolve the issue. Here is what worked.

Situation and Solution

  • The Challenge
  • First changes: /etc/resolv.conf
  • More changes: /etc/gai.conf
  • Solution: nameserver order
  • Nothing to restart - just test

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

Simple solution

nameserver 2001:470:1f10:c6::2

The nameserver lines in /etc/resolv.conf were the solution. Presumably the following would also work:

  options rotate

The previous structure of /etc/resolv.conf had that IPv6 nameserver first. This meant that the IPv6 nameservers were queried made first - every time. And timing out, in my case, in 5 seconds, for IPv4 domain lookups. IPv6 is enabled on the host and functional. But IPv4 DNS was very slow before I put the IPv4 nameserver at the top of the list. Presumably IPv6 DNS are now very slow if the v4 nameserver is queried first, but that's a separate problem.

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.

1998-2023 Celebrazio.net