I want to do a bulk reverse DNS query to a specific nameserver.

Currently, after searching here and Google. I got it to work for 1 entry at the time with the following command:

dig @NAMESERVER -x +short

This returns exactly what I want. But If I want to do this for multiple IP addresses, it fails. What I did was to make a list of 2 IP addresses to test.

I'm trying to use the following command:

dig @NAMESERVER -x -f dnsquery.txt +short

This does not show any result, what am I doing wrong?

The input files has 2 lines, each with 1 IP address: 
  • You'll probably want to covert the a.b.c.d to the reverse d.c.b.a.in-addr.arpa and then do PTR ... lookups, or use a loop around dig that calls -x a.b.c.d for each IP. – thrig Nov 23 '16 at 0:08
  • Ho do I do a loop, sorry newbie here.... – frankguthrie Nov 23 '16 at 7:34

As thrig mentioned, you could loop the dig call.

You can use for example this little bash script ans save it in a file called e.g. bulkreverse.sh:

filename='ip_in.txt' # name of file with IPs to handle
nameserver='' # nameserver to query

for ip in `cat $filename`
echo 'Handling reverse DNS for $ip'
dig @$nameserver -x $ip +short

The variable filename specifies the name of the file with the list of IP addresses (like you example, oen IP per line). nameserver is the nameserver to query.

If you saved the script in a file called bulkreverse.sh you need to make it executable by running

chmod +x bulkreverse.sh

After that you can execute it with


I hope that helps!

| improve this answer | |

If there are a lot then GNU Parallel may help speed up the processing:

parallel -j100 --retries 3 dig @$nameserver -x {} +short :::: ip_in.txt
| improve this answer | |

You can use awk to convert the forwards addresses to reverse ones, and then pipe the result to dig

awk -F. '{printf "%s.%s.%s.%s.in-addr.arpa\n",$4,$3,$2,$1}' dnsqueries.txt |
    dig +short ptr @NAMESERVER -f -
| improve this answer | |

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.