Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Was hoping to implement the "options rotate" directive within resolv.conf to have DNS lookups rotate through the nameservers listed in that file. As I understand it that is the point of this directive. It does not work on any system that I have tried to date. It always uses the first nameserver directive in the file and disregards the rest unless of an error.

I tested by using a fake DNS python script that mimics a DNS server and always replies with the same bogus 192.168.1.1 address regardless of the request. When placed first in the file it would always go to this server and when placed second it would never go. This is with the "options rotate" directive included in the file.

# cat /etc/resolv.conf
search some.toplevel
options rotate
nameserver 10.0.0.2 <- fake python DNS server
nameserver 10.0.0.3 <- real DNS server

Fake DNS server pythons script used

Also, I used the dig command and the host command. I verified they make use of the resolv library. I tried this on CentOS 5.6 as well as on my personal ubuntu with totally different versions of the related packages. I'm totally stumped here, need some help on this one.

share|improve this question
add comment

2 Answers 2

up vote 6 down vote accepted

There's a hint about this on http://docstore.mik.ua/orelly/networking_2ndEd/dns/ch06_01.htm:

In other words, an instance of the resolver still queries the first name server in resolv.conf first, but for the next domain name it looks up, it queries the second name server first, and so on.

Note that many programs can't take advantage of this since most programs initialize the resolver, look up a name, then exit. Rotation has no effect on repeated ping commands, for example, because each ping process initializes the resolver, queries the first name server in resolv.conf, and then exits before using the resolver again. Each successive invocation of ping has no idea which name server the previous one used -- or even that ping was run earlier. But long-lived processes that send lots of queries, such as a sendmail daemon, can take advantage of rotation.

share|improve this answer
    
Confirmed using python's socket.gethostbyname() which does rotate. I was under the impression some "previously used" variable was being stored somewhere, which didn't seem "clean". This makes more sense. Thanks! –  CarpeNoctem Oct 28 '11 at 19:41
add comment

Since the 'dig' and 'host' commands only make one query, it is impossible for them to rotate their queries. Rotation requires a program that issues multiple queries. (It is literal rotation, not random distribution. The first query goes to the first server, the second to the second, and so on.)

Note that many programs can't take advantage of this since most programs initialize the resolver, look up a name, then exit. Rotation has no effect on repeated ping commands, for example, because each ping process initializes the resolver, queries the first name server in resolv.conf, and then exits before using the resolver again. Each successive invocation of ping has no idea which name server the previous one used -- or even that ping was run earlier. But long-lived processes that send lots of queries, such as a sendmail daemon, can take advantage of rotation. -- O'Reilly, DNS and Bind

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.