rotate and resolv.conf

2,692 views
Skip to first unread message

Robert Citek

unread,
Sep 11, 2012, 9:49:47 AM9/11/12
to CWE-LUG, SLUUG general discussion
I am puzzled by the rotate option in /etc/resolv.conf. From the man page:

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.

$ cat /etc/resolv.conf
options rotate
nameserver 8.8.8.8
nameserver 8.8.4.4

However if I run multiple tests with dig, I always hit the same
server, the first server:

$ seq 1 100 | xargs dig +noall +stats google.com | grep SERVER | uniq -c
101 ;; SERVER: 8.8.8.8#53(8.8.8.8)

To demonstrate, if I swap the position of the first and second nameserver:

$ cat /etc/resolv.conf
options rotate
nameserver 8.8.4.4
nameserver 8.8.8.8

And rerun the test:

$ seq 1 100 | xargs dig +noall +stats google.com | grep SERVER | uniq -c
101 ;; SERVER: 8.8.4.4#53(8.8.4.4)


That does not look like round-robin. What am I missing?

Regards,
- Robert

Robert Citek

unread,
Sep 11, 2012, 11:03:23 AM9/11/12
to SLUUG general discussion, CWE-LUG
host appears to give similar results:

$ seq 1 10 | xargs -i host -v google.com | grep ^Recei | grep -o
8.8.[0-9.#]* | uniq -c
30 8.8.8.8#53

As for the strace, can you give an example of what I should be looking for?

Regards,
- Robert

On Tue, Sep 11, 2012 at 10:09 AM, Andrew Freiberger
<afrei...@gmail.com> wrote:
> my guess is that "dig" is not set to use the resolv libraries, but instead
> figures out a nameserver using the resolv.conf file and then goes about it's
> own business. If you did a "strace" on the "host <dns name>" command, I
> wonder if you'd see the resolver flip-flopping in your socket connections.
>
> -Drew
>> _______________________________________________
>> Discuss mailing list
>> Dis...@sluug.org
>> http://www.sluug.org/mailman/listinfo/discuss
>
>
>
> _______________________________________________
> Discuss mailing list
> Dis...@sluug.org
> http://www.sluug.org/mailman/listinfo/discuss
>

David Dooling

unread,
Sep 11, 2012, 11:12:30 AM9/11/12
to cwe...@googlegroups.com
There may be some caching on one end or the other (or both). I would
think the DNS server at least would want to have the same response for
the same query from the same host to minimize overhead. Do you have
the ability to run your test on a bunch of hosts simultaneously?
> --
> Central West End Linux Users Group (via Google Groups)
> Main page: http://www.cwelug.org
> To post: cwe...@googlegroups.com
> To subscribe: cwelug-s...@googlegroups.com
> To unsubscribe: cwelug-un...@googlegroups.com
> More options: http://groups.google.com/group/cwelug



--
David Dooling

Robert Citek

unread,
Sep 12, 2012, 12:20:15 AM9/12/12
to SLUUG general discussion, CWE-LUG
Very nice explanation. Your two well-chosen examples clarified how
rotation works beautifully.

Thanks, Brian.

Regards,
- Robert

On Tue, Sep 11, 2012 at 10:03 PM, Brian Pitts <br...@polibyte.com> wrote:
> Host and dig are a little tricky to run under strace, since they fork
> several times. I might try a simple python program like this.
>
> #!/usr/bin/env python
> import socket
> for x in range(4):
> socket.getaddrinfo('google.com', 80)
>
> Now, if I trace the connect system call and filter only for port 53,
> I'll see
>
> strace -e trace=connect ./lookup_google.py 2>&1 | grep 53
>
> connect(4, {sa_family=AF_INET, sin_port=htons(53),
> sin_addr=inet_addr("208.67.220.220")}, 16) = 0
> connect(4, {sa_family=AF_INET, sin_port=htons(53),
> sin_addr=inet_addr("208.67.222.222")}, 16) = 0
> connect(4, {sa_family=AF_INET, sin_port=htons(53),
> sin_addr=inet_addr("208.67.220.220")}, 16) = 0
> connect(4, {sa_family=AF_INET, sin_port=htons(53),
> sin_addr=inet_addr("208.67.222.222")}, 16) =
>
> (Instead of using strace, I could have used tshark or tcpdump to watch
> the traffic, e.g. tshark -i wlan0 'udp port 53')
>
> Which is what I would expect when my resolv.conf is
>
> options rotate
> nameserver 208.67.222.222
> nameserver 208.67.220.22
>
> However, what if I change my program to just
>
> #!/usr/bin/env python
> import socket
> socket.getaddrinfo('google.com', 80)
>
> And run it four times?
>
> for i in $(seq 1 4); do strace -e trace=connect ./lookup_google.py 2>&1
> | grep 53; done
>
> connect(4, {sa_family=AF_INET, sin_port=htons(53),
> sin_addr=inet_addr("208.67.220.220")}, 16) = 0
> connect(4, {sa_family=AF_INET, sin_port=htons(53),
> sin_addr=inet_addr("208.67.220.220")}, 16) = 0
> connect(4, {sa_family=AF_INET, sin_port=htons(53),
> sin_addr=inet_addr("208.67.220.220")}, 16) = 0
> connect(4, {sa_family=AF_INET, sin_port=htons(53),
> sin_addr=inet_addr("208.67.220.220")}, 16) = 0
>
> Now you see that it always hits the first nameserver. The rotation only
> takes place for multiple lookups within a single program. That makes
> sense when you think about it. There's not some central program the all
> the programs on your system are talking to to make these lookups (unless
> you're using nscd); instead, each program is loading and executing
> library function independently.
Reply all
Reply to author
Forward
0 new messages