brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: options timeout and attempts in resolv.conf decide how long a Linux DNS failure takes

Linux
~/tips/tip-linux-resolv-conf-timeout-attempts

options timeout:2 attempts:2 rotate

Shorten the wait when the first name server in resolv.conf is down.

When the first name server in /etc/resolv.conf stops answering, every lookup waits for it before it tries the next one. By default that wait is five seconds per try.

The man page lists the defaults: timeout is 5 seconds and attempts is 2. With two dead servers, a single lookup can hang for a long time, and every program on the box feels frozen. You can make that shorter with an options line:

nameserver 192.0.2.53
nameserver 203.0.113.53
options timeout:2 attempts:2 rotate

timeout:2 waits two seconds per server and attempts:2 runs the round twice. rotate spreads lookups over the servers instead of always asking the first one first. The glibc resolver caps the values silently: timeout at 30 and attempts at 5. It also reads only the first three nameserver lines.

Before you edit the file, check what writes it:

ls -l /etc/resolv.conf

On many systems it is a symlink managed by systemd-resolved, NetworkManager or resolvconf, and your change will be overwritten. With systemd-resolved the file usually lists only the local stub at 127.0.0.53, and the timeouts toward the real servers are handled by resolved itself, so these options make little difference there. I think they fit plain servers and containers best, where resolv.conf really is the whole story.

Further reading: resolv.conf(5) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link