Skip to content

How to Change the Timeout Before Falling Back to the Secondary DNS Server

Updated 2 min read

Updated: 28 September 2026 · Applies to: glibc resolver with NetworkManager on AlmaLinux and Rocky Linux 9 and 10 and RHEL 9 and 10; systemd-resolved on Ubuntu 24.04 and 26.04; Debian 13

When the first DNS server in /etc/resolv.conf does not answer, every lookup waits before trying the next one: by default 5 seconds per attempt, with 2 rounds through the list. On a server that makes many connections, that delay makes everything slow. The resolver options timeout, attempts and rotate shorten it.

The options

  • timeout:1: wait 1 second for an answer before trying the next server (default 5, maximum 30).
  • attempts:2: how many times to go through the list of servers (default 2, maximum 5).
  • rotate: use the listed servers in turn instead of always asking the first one first, which spreads the load.

AlmaLinux, Rocky Linux and RHEL (NetworkManager)

NetworkManager writes /etc/resolv.conf, so set the options on the connection:

nmcli connection modify "eth0" ipv4.dns-options "timeout:1,attempts:2,rotate"
nmcli connection up "eth0"
cat /etc/resolv.conf

The file should now contain a line options timeout:1 attempts:2 rotate.

Debian with a static resolv.conf

If nothing manages the file, add the line directly to /etc/resolv.conf:

nameserver 192.0.2.53
nameserver 192.0.2.54
options timeout:1 attempts:2 rotate

Ubuntu (systemd-resolved)

On Ubuntu, /etc/resolv.conf points to the local resolver 127.0.0.53, and these options have little effect. systemd-resolved itself moves to the next DNS server when one fails and remembers which one works. Check its current choice with resolvectl status ("Current DNS Server"). If you need faster failover there, list your most reliable server first in the netplan nameservers section.

Test

time getent hosts ucartz.com

With the first server unreachable, the lookup should now take about one second instead of five.

Official documentation: resolv.conf manual page and NetworkManager ipv4 settings.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket