Can I lookup NS and A at the same time using dig
Asked Answered
R

2

15

Is it possible to lookup the A (ip address) and NS (nameservers) of a domain using a single dig command?

I can use dig google.com A +short or dig google.com NS +short but surely it's possible to do it with just one command? If not, is there a similar command that might be able to do this?

Thank you

Reinhold answered 12/12, 2010 at 9:9 Comment(0)
H
6

No, it can't be done reliably, at least not in a single DNS query. Martin's answer satisfies the "single command" criterion, but would result in two queries to the DNS server.

There is the ANY option (instead of NS or A) but it's not a reliable way to get both records.

If you ask Google's authoritative server you should indeed get everything back, but I suspect you won't know what their server is in advance, otherwise you wouldn't ask this question.

If you ask your local recursive server then you might get back both records, but only if they're both in the cache. Recursive servers aren't required to obtain every record and return them for an ANY query, they're allowed to send back just what they already have.

Hebraic answered 12/12, 2010 at 9:25 Comment(6)
Altnitak, when I use(for example): dig @208.67.222.222 example.org ANY It always seems to return the NS plus the A as I'd like. Are you saying that in some cases this might not happen? Thank youReinhold
Exactly, yes. If OpenDNS don't have it in their cache, it won't be returned. I just tried this for a domain I know - the first ANY query only returned the NS. I then sent an explicit A query. Subsequent ANY queries now return both (at least until their TTLs expire).Hebraic
Dang, that's a shame. Thanks for taking the time to explain it. It's useful to know. I guess the best solution really is two have it as two separate queries to the DNS server. I'll check the nameservers first and if there are none assigned then I wont bother checking for the IP.Reinhold
so is there any way that you can make a DNS query packet with many queries in it? If not, why does DNS header in a packet has a field to count the number of queries in that packet, would this number will always be 1?Matias
@Matias no, there's still no way to do it, although the IETF DNSOP working group has at least 5 different proposals relating to getting multiple questions and/or answers into a single DNS round trip (including one from me). As for why the header is that way, I'd have to ask Paul Mockapetris next time I see him...Hebraic
Lets suppose there is a software which just sends multiple requests with the most commonly used record types (maybe 5-10) and displays the results conveniently to the user. How would this software be called?Hoke
D
17
dig +short ns google.com a google.com
Depredation answered 12/12, 2010 at 9:24 Comment(5)
Thanks Martin. Depending on what Alnitak comes back with, this might be the route I take.Reinhold
Well it doesn't have to be, I just wanted to streamline the process if possible. E.g if dig could return both of those after a single request to the DNS server then that's faster than two separate requests.Reinhold
but that dig command still does two separate requests... try it without the +short option and you'll see them.Hebraic
Alnitak is right. It's just that dig supports multiple queries in a single command line. You see that it must be two queries because you have to repeat the host name (and the second one could be different from the first one).Stelliform
Yes, I understand that this command sends two requests to the DNS server. Although it does fulfill the requirement of being just one dig commmand, keeping running processes down when forking it out many times.Reinhold
H
6

No, it can't be done reliably, at least not in a single DNS query. Martin's answer satisfies the "single command" criterion, but would result in two queries to the DNS server.

There is the ANY option (instead of NS or A) but it's not a reliable way to get both records.

If you ask Google's authoritative server you should indeed get everything back, but I suspect you won't know what their server is in advance, otherwise you wouldn't ask this question.

If you ask your local recursive server then you might get back both records, but only if they're both in the cache. Recursive servers aren't required to obtain every record and return them for an ANY query, they're allowed to send back just what they already have.

Hebraic answered 12/12, 2010 at 9:25 Comment(6)
Altnitak, when I use(for example): dig @208.67.222.222 example.org ANY It always seems to return the NS plus the A as I'd like. Are you saying that in some cases this might not happen? Thank youReinhold
Exactly, yes. If OpenDNS don't have it in their cache, it won't be returned. I just tried this for a domain I know - the first ANY query only returned the NS. I then sent an explicit A query. Subsequent ANY queries now return both (at least until their TTLs expire).Hebraic
Dang, that's a shame. Thanks for taking the time to explain it. It's useful to know. I guess the best solution really is two have it as two separate queries to the DNS server. I'll check the nameservers first and if there are none assigned then I wont bother checking for the IP.Reinhold
so is there any way that you can make a DNS query packet with many queries in it? If not, why does DNS header in a packet has a field to count the number of queries in that packet, would this number will always be 1?Matias
@Matias no, there's still no way to do it, although the IETF DNSOP working group has at least 5 different proposals relating to getting multiple questions and/or answers into a single DNS round trip (including one from me). As for why the header is that way, I'd have to ask Paul Mockapetris next time I see him...Hebraic
Lets suppose there is a software which just sends multiple requests with the most commonly used record types (maybe 5-10) and displays the results conveniently to the user. How would this software be called?Hoke

© 2022 - 2024 — McMap. All rights reserved.