Anything like nslookup or dig offer the ability to search based on something contained in the name ... like a wildcard search or something?

I'm trying to make a little script with a GUI wrapper for our helpdesk team. Ideally, I'd like them to be able to search the user's last name (something that is always present in the DNS record) and then I'll populate a pulldown with the possible options to choose from.

I'm unable to find a way to effectively have the equivalent of nslookup *miller* ... it would be great to then get back

Name: sf-jacobmiller.localdomain.com

Name: sf-justinmiller.localdomain.com

..which I could then parse into a pulldown for them to pick from.

I have not yet looked into what's available with ldapsearch which may be able to do what I'm looking for. My only requirement is that this is built into OSX and I won't need to install anything else, otherwise I'm open to any solutions you can offer. Thanks


You can get a full list of entries in a zone with a zone transfer; you'd need to allow this for authorized systems in your DNS server.

Once that's done, you can run the transfer and grep the result:

dig axfr localdomain.com | grep -i miller
  • As easy and straight forward as I could have hoped for. Thanks – TryTryAgain Mar 6 '13 at 1:49
  • I'd like to edit your answer to include grep -i so that it is case insensitive, otherwise I realized case would cause too many problems. I can't make such a minor edit, though. Thanks again for such an elegant solution, exactly what I was looking for. – TryTryAgain Mar 6 '13 at 1:59

A name server will not, by design, let you search a zone or query what zones it is authoritative for. Beyond the obvious reason of reducing attack vectors (you can't make a HTTP/1.1 request to a host if you don't know its name), there is a very good reason for this: a zone can contain wildcards itself, so asking for every host in such a zone is like dividing by zero.

If you operate the name server whose records you want to search, you can do a zone transfer to a local name server and search the records directly. You will still need to parse the text records in whatever format they are transferred in, as a local name server will not respond any differently.


You can only ask a DNS-Server if it has a specific record. So, no there will be no such tool for DNS.


Zonetransfer is of course a possibility if it is available.

  • Looks like you were proven wrong, as I expected. – TryTryAgain Mar 6 '13 at 2:06
  • 3
    @TryTryAgain Actually, in the general case he is quite correct: Note the key words in the answer you accepted: need to allow this for authorized systems in your DNS server. For example, if you attempt a zone transfer for serverfault.com (or indeed pretty much any zone you don't control or for which you have not made arrangements with the DNS administrators) you will get no results. – voretaq7 Mar 6 '13 at 5:02
  • 4
    @TryTryAgain The phrasing also comes across as slightly rude. If the answer was as obvious as you're making it sound, you wouldn't have had to post the question. We're all here to help each other...usually. – Andrew B Mar 6 '13 at 5:18

Agreeing with the checked answer, I thought that a for-loop could be an alternative for someone who is not authorized to do a zone transfer. If you know the IP range:

for ip in $( seq 1 255 ); do {
    sleep 1; # be kind to the server, unauthorized user
    text="$( nslookup $net$ip 2>&1 | grep "$name" )";
    if [ -z "$text" ]; then continue; fi;
    echo "$text";
}; do

I looked up this answer because I wanted to open up my desktop to a local user whos IP and machine name I did not know.

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.