3

Let's say I'm trying to lookup the IPs mail.yahoo.com, gmail.com and mail.google.com

If I execute:

dig @8.8.8.8 +nocomments +noquestion \ +noauthority +noadditional +nostats +nocmd \ gmail.com mail.yahoo.com mail.google.com 

I get:

gmail.com. 299 IN A 173.194.123.21 gmail.com. 299 IN A 173.194.123.22 mail.yahoo.com. 0 IN CNAME login.yahoo.com. login.yahoo.com. 0 IN CNAME ats.login.lgg1.b.yahoo.com. ats.login.lgg1.b.yahoo.com. 0 IN CNAME ats.member.g02.yahoodns.net. ats.member.g02.yahoodns.net. 0 IN CNAME any-ats.member.a02.yahoodns.net. any-ats.member.a02.yahoodns.net. 17 IN A 98.139.21.169 mail.google.com. 0 IN CNAME googlemail.l.google.com. googlemail.l.google.com. 243 IN A 173.194.123.21 googlemail.l.google.com. 243 IN A 173.194.123.22 

Can I ensure that if I see a CNAME record, the A record corresponding to it won't appear before a CNAME corresponding to another machine or an A record for other hostname?

For instance, let me focus on mail.yahoo.com (I just want the IP or IPs mail.yahoo.com resolves to):

This is the output:

mail.yahoo.com. 0 IN CNAME login.yahoo.com. login.yahoo.com. 0 IN CNAME ats.login.lgg1.b.yahoo.com. ats.login.lgg1.b.yahoo.com. 0 IN CNAME ats.member.g02.yahoodns.net. ats.member.g02.yahoodns.net. 0 IN CNAME any-ats.member.a02.yahoodns.net. any-ats.member.a02.yahoodns.net. 17 IN A 98.139.21.169 

The hostname I'm looking for ( mail.yahoo.com) is the first column of the first entry. Then there's a bunch of CNAMES I really don't care about, and then an A record with the actual IP (which I do care about).

Is there a possibility of getting the CNAMES or A records out of order? Something like:

ats.login.lgg1.b.yahoo.com. 0 IN CNAME ats.member.g02.yahoodns.net. #(!)BAD ats.member.g02.yahoodns.net. 0 IN CNAME any-ats.member.a02.yahoodns.net. #(!)BAD mail.yahoo.com. 0 IN CNAME login.yahoo.com. login.yahoo.com. 0 IN CNAME ats.login.lgg1.b.yahoo.com. any-ats.member.a02.yahoodns.net. 17 IN A 98.139.21.169 

Or even worse (the actual A record on top):

any-ats.member.a02.yahoodns.net. 17 IN A 98.139.21.169 mail.yahoo.com. 0 IN CNAME login.yahoo.com. login.yahoo.com. 0 IN CNAME ats.login.lgg1.b.yahoo.com. ats.login.lgg1.b.yahoo.com. 0 IN CNAME ats.member.g02.yahoodns.net. ats.member.g02.yahoodns.net. 0 IN CNAME any-ats.member.a02.yahoodns.net. 

Or the worse of the worse (in a multi-resolution dig execution, as the one shown on top of the post):

ats.member.g02.yahoodns.net. 0 IN CNAME any-ats.member.a02.yahoodns.net. any-ats.member.a02.yahoodns.net. 17 IN A 98.139.21.169 mail.google.com. 0 IN CNAME googlemail.l.google.com. # This one I want gmail.com. 299 IN A 173.194.123.21 # This one I want gmail.com. 299 IN A 173.194.123.22 # This one I want mail.yahoo.com. 0 IN CNAME login.yahoo.com. # This one I want login.yahoo.com. 0 IN CNAME ats.login.lgg1.b.yahoo.com. ats.login.lgg1.b.yahoo.com. 0 IN CNAME ats.member.g02.yahoodns.net. googlemail.l.google.com. 243 IN A 173.194.123.21 googlemail.l.google.com. 243 IN A 173.194.123.22 
1
  • 1
    I'm almost sure dig does NOT guarantee order. When I wrote a nagios test using dig, I had to pipe the output to sort to get it to work properly: github.com/barrycarter/bcapps/blob/master/NAGIOS/… Commented Oct 30, 2014 at 0:44

1 Answer 1

3

dig does not reorder the results, it shows them in the order that the nameserver returns them. Nameservers normally shuffle the results (either randomly or round-robin) each time they're queried for a particular record (to implement a simple form of load balancing), although there may be server configuration options that override this. In the case of BIND, the relevant options are rrset-order and sortlist.

As far as I can tell, if you perform multiple queries with a single dig invocation, it's as if you had executed dig separately for each name, in that order. I can't imagine why the code wouldn't just loop through them in the order they're on the command line.

If the server has to follow CNAME records to get the final answer, the DNS specification says that each alias will be added to the response in the order they're processed. So you're guaranteed that the original name you gave will be first, and the final results will be last.

2
  • That applies to the results from a single query. The OP is making three completely independant queries on the same command line and wants to know if the results of each query will be shown sequentially. Commented Oct 30, 2014 at 19:07
  • Thanks, I didn't notice that nuance to the question. I've updated the answer with more details about multiple queries and CNAME chains. Commented Oct 30, 2014 at 19:15

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.