Skip to content

Instantly share code, notes, and snippets.

@dlangille
Created October 25, 2023 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlangille/d78e970e507f8ee04f9b356485b1ddaa to your computer and use it in GitHub Desktop.
Save dlangille/d78e970e507f8ee04f9b356485b1ddaa to your computer and use it in GitHub Desktop.
Let's test the timeout option for /etc/resolv.conf (note host(8) is not a valid test; it does not honor options)
I have N nameservers. If one, or more, of them are down, I still want DNS to resolve quickly.
I could use carp or vrrp. But I'm not there yet.
The pro of carp/vrrp - no changes to clients.
THe pro of /etc/resolv.conf - don't have to set up carp/vrrp - easy to test
% cat /etc/resolv.conf
#nameserver 10.55.0.124
nameserver 10.55.0.1
options attempts:1 timeout:1 reload-period:0
% time ping -c1 google.com
PING google.com (142.251.40.174): 56 data bytes
64 bytes from 142.251.40.174: icmp_seq=0 ttl=119 time=7.687 ms
--- google.com ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 7.687/7.687/7.687/0.000 ms
ping -c1 google.com 0.00s user 0.00s system 20% cpu 0.013 total
Very fast
% # there is no nameserver at 10.55.0.124, to simulate an offline host
% cat /etc/resolv.conf
nameserver 10.55.0.124
nameserver 10.55.0.1
options attempts:1 timeout:1 reload-period:0
% time ping -c1 google.com
PING google.com (142.251.40.174): 56 data bytes
64 bytes from 142.251.40.174: icmp_seq=0 ttl=119 time=9.443 ms
--- google.com ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 9.443/9.443/9.443/0.000 ms
ping -c1 google.com 0.00s user 0.00s system 0% cpu 3.252 total
3.2 seconds to time out and try the next host.
% cat /etc/resolv.conf
nameserver 10.55.0.124
nameserver 10.55.0.1
#options attempts:1 timeout:1 reload-period:0
% time ping -c1 google.com
PING google.com (142.251.40.174): 56 data bytes
64 bytes from 142.251.40.174: icmp_seq=0 ttl=119 time=8.725 ms
--- google.com ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 8.725/8.725/8.725/0.000 ms
ping -c1 google.com 0.00s user 0.00s system 0% cpu 15.610 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment