Randomize DNS Nameservers

domain-name-systemresolv.conf

Is it possible to list multiple nameservers in /etc/resolv.conf on a Unix system and resolve dns queries using a random nameserver when making a dns query and not just the first one?

Best Answer

For Linux systems, I use the timeout and rotate options in /etc/resolv.conf... I usually lower the DNS timeout to 1 second.

timeout:n
    sets the amount of time the resolver will wait for a response from a remote name server
    before  retrying  the  query  via  a  different  name server.  Measured in seconds, the
    default is RES_TIMEOUT (currently 5, see  <resolv.h>).   The  maximum  value  for  this
    option is silently capped to 30.

and

rotate 
    sets RES_ROTATE in _res.options, which causes round robin selection of nameservers from
    among  those  listed.  This has the effect of spreading the query load among all listed
    servers, rather than having all clients try the first listed server first every time.