You are here
configuring libresolv to timeout DNS queries to unreachable nameservers more quickly when offline
When I go offline I pull my network cable. This causes DNS queries to take forever to resolve. Actually 40 seconds but it feels like forever.
I ran across this most recently when confconsole seemed to get stuck when I reconfigured a static IP. I hadn't actually changed anything, just changed a DHCP dynamic IP to a static IP, but confconsole got stuck anyway. I traced this to /etc/network/if-up.d/ntpdate trying to resolve the hostnames for various ntp servers. Debian decided it would a good idea to fix the time whenever you brought your interface up. The problem is if you bring your interface up when you don't have network connectivity you get put on hold for about 20 seconds for each nameserver in /etc/resolv.conf.
We could disable the ntpdate hook but I've decided instead it would be a better idea to reduce the timeouts on DNS queries to something sensible like 1 second.
Here's how:
root@lamp ~# time ping www.google.com ping: unknown host www.google.com real 0m40.011s user 0m0.004s sys 0m0.000s root@lamp ~# echo 'options timeout:1' > /etc/resolvconf/resolv.conf.d/tail root@lamp ~# cat /etc/resolvconf/resolv.conf/tail options timeout:1 root@lamp ~# cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 208.122.23.22 nameserver 208.122.23.23 root@lamp ~# resolvconf -u root@lamp ~# cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 208.122.23.22 nameserver 208.122.23.23 options timeout:1 root@lamp ~# time ping www.google.com ping: unknown host www.google.com real 0m8.011s user 0m0.004s sys 0m0.000s
That's more like it. I've committed a fix to common to make this the default.
Add new comment