2

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
2

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.

  • 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. – Celada Oct 30 '14 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. – Barmar Oct 30 '14 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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