20110212 dig in batch mode - plembo/onemoretech GitHub Wiki

title: Dig in batch mode link: https://onemoretech.wordpress.com/2011/02/12/dig-in-batch-mode/ author: lembobro description: post_id: 68 created: 2011/02/12 09:26:31 created_gmt: 2011/02/12 09:26:31 comment_status: open post_name: dig-in-batch-mode status: publish post_type: post

Dig in batch mode

The Internet Software Consortium's (ISC) dig is the recommended tool for querying Domain Name System (DNS) servers. Recently I needed to check a number of DNS entries tied to the same IP address (the typical A record with associated CNAME records). After leafing through the manual page and some examples I found on the Internet, I came up with this solution. The key to efficiently handling queries of multiple host names in one shot with dig is making maximum use of the different options and flags available in the utility. According to the man page, dig will process a list of host names contained in a plain text file having one host name per line. Take a file like this (call it hostnames.txt):

example.com
www.example.com
www2.example.com
blog.example.com
dev.example.com

(be sure there are no blank lines leading, trailing or in-between — these will return a messy dump of root server info) Then run dig against it like dig -f hostnames.txt. The output you'll get from this will be pretty verbose. That's dig. To strip that output down to the essentials (A and CNAME records), try this syntax:

dig -f hostnames.txt +noall +answer

The “+noall” flag toggles the display of full information off, “+answer” ensures that the answer section of each record is returned. The response you'll get will be something like this:

example.com.      300 IN A     99.99.99.100
www.example.com.  300 IN CNAME example.com.
www2.example.com. 300 IN CNAME example.com.
blog.example.com. 300 IN CNAME example.com.
dev.example.com.  300 IN CNAME example.com.

Note for those with Windows workstations: For a long time anyone who wanted to run dig on Windows needed to load up a bulky Unix emulation environment like Cygwin. Although I'm a big fan of Cygwin, there's a better solution for those who just need dig and maybe a few other up-to-date DNS utilities. To get them all you have to do is go up and grab the latest BIND for Windows. Once downloaded, just extract the following files to their own folder (e.g. c:appsbind):

dig.exe
libbind9.dll
libdns.dll
libeay32.dll
libisc.dll
libisccc.dll
libisccfg.dll
liblwres.dll
libxml2.dll

These are the bare minimum. You might also consider getting host.exe and other utiltiies, as well as the man pages in .html format or the full BIND Administrator's Manual in pdf format. After extracting the files, add the folder path to the Windows system environment so that you can execute the utilities from any command prompt.

Copyright 2004-2019 Phil Lembo