14

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
Stevie
  • 245
  • 4
  • 9

2 Answers2

15
dig +short ns google.com a google.com
Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
  • Thanks Martin. Depending on what Alnitak comes back with, this might be the route I take. – Stevie Dec 12 '10 at 09:51
  • 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. – Stevie Dec 12 '10 at 10:02
  • but that dig command still does two separate requests... try it without the `+short` option and you'll see them. – Alnitak Dec 12 '10 at 10:07
  • 1
    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). – Martin v. Löwis Dec 12 '10 at 10:11
  • 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. – Stevie Dec 12 '10 at 10:16
7

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.

Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • 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 you – Stevie Dec 12 '10 at 09:49
  • 1
    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). – Alnitak Dec 12 '10 at 09:52
  • 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. – Stevie Dec 12 '10 at 09:58
  • 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? – weefwefwqg3 Nov 24 '17 at 05:32
  • @weefwefwqg3 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](https://tools.ietf.org/html/draft-bellis-dnsext-multi-qtypes)). As for why the header is that way, I'd have to ask Paul Mockapetris next time I see him... – Alnitak Nov 24 '17 at 09:10