The easy way to make dig more useful: .digrc

Posted on

I’ve been a long-time “dig” user (on Mac and Linux) to retrieve DNS records before I start transferring a domain to a new registrar. Every time I issue the same dig commands to gather the data I need and put it in a text file for easy reference later. Dig always outputs way more information than I need and I end up fishing through most of it to find the one or two lines that interest me.

$ dig jssm.com any

; <<>> DiG 9.3.6-APPLE-P2 <<>> jssm.com any
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37409
;; flags: qr rd ra; QUERY: 1, ANSWER: 7, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;jssm.com.                      IN      ANY

;; ANSWER SECTION:
jssm.com.               7200    IN      MX      5 ALT1.ASPMX.L.GOOGLE.com.
jssm.com.               7200    IN      MX      0 ASPMX.L.GOOGLE.com.
jssm.com.               7200    IN      A       216.98.141.250
jssm.com.               7200    IN      A       69.72.142.98
jssm.com.               7200    IN      SOA     ns8.zoneedit.com. soacontact.zoneedit.com. 1255263341 14400 7200 950400 7200
jssm.com.               7200    IN      NS      ns17.zoneedit.com.
jssm.com.               7200    IN      NS      ns8.zoneedit.com.

;; Query time: 62 msec
;; SERVER: 172.16.0.100#53(172.16.0.100)
;; WHEN: Tue Mar  9 10:10:20 2010
;; MSG SIZE  rcvd: 203

Dig Options

After perusing the man page for dig, I discovered the magical combination of options that hides all the stuff I don’t want to see while still returning all the data I do want to see: +nostats +nocomments +nocmd +noquestion +recurse.

Now my command is messy, cumbersome, and difficult to remember, but I have what I want:

$ dig +nostats +nocomments +nocmd +noquestion +recurse jssm.com any

jssm.com.               7200    IN      MX      0 ASPMX.L.GOOGLE.com.
jssm.com.               7200    IN      MX      5 ALT1.ASPMX.L.GOOGLE.com.
jssm.com.               7200    IN      A       69.72.142.98
jssm.com.               7200    IN      A       216.98.141.250
jssm.com.               7200    IN      SOA     ns8.zoneedit.com. soacontact.zoneedit.com. 1255263341 14400 7200 950400 7200
jssm.com.               7200    IN      NS      ns8.zoneedit.com.
jssm.com.               7200    IN      NS      ns17.zoneedit.com.

.digrc

I was delighted to see that dig supports a .digrc file for setting default options. I simply plopped the options I like into my ~/.digrc file all on a single line, issued my simple query, and voila! just the data I need without the extra stuff I don’t.

$ dig jssm.com any
jssm.com.               7200    IN      MX      0 ASPMX.L.GOOGLE.com.
jssm.com.               7200    IN      MX      5 ALT1.ASPMX.L.GOOGLE.com.
jssm.com.               7200    IN      A       69.72.142.98
jssm.com.               7200    IN      A       216.98.141.250
jssm.com.               7200    IN      SOA     ns8.zoneedit.com. soacontact.zoneedit.com. 1255263341 14400 7200 950400 7200
jssm.com.               7200    IN      NS      ns8.zoneedit.com.
jssm.com.               7200    IN      NS      ns17.zoneedit.com.

Bonus Syntax

I also discovered that dig supports multiple queries on the command line. I can now issue a single command and get all the DNS information I need for a domain:

$ dig jssm.com any www.jssm.com any mail.jssm.com any
jssm.com.               7200    IN      MX      5 ALT1.ASPMX.L.GOOGLE.com.
jssm.com.               7200    IN      MX      0 ASPMX.L.GOOGLE.com.
jssm.com.               7200    IN      A       216.98.141.250
jssm.com.               7200    IN      A       69.72.142.98
jssm.com.               7200    IN      SOA     ns8.zoneedit.com. soacontact.zoneedit.com. 1255263341 14400 7200 950400 7200
jssm.com.               7200    IN      NS      ns17.zoneedit.com.
jssm.com.               7200    IN      NS      ns8.zoneedit.com.
www.jssm.com.           7200    IN      CNAME   wfb.zoneedit.com.
wfb.zoneedit.com.       951     IN      A       216.98.141.250
wfb.zoneedit.com.       951     IN      A       69.72.142.98
mail.jssm.com.          7200    IN      CNAME   ghs.google.com.
Advertisement

3 thoughts on “The easy way to make dig more useful: .digrc

    kansalgaurav said:
    August 3, 2013 at 12:41 pm

    Really useful post

    Very knowledgeable.

    Abdulla Bushlaibi said:
    April 15, 2014 at 9:59 am

    Thanks for the fruitful article. What about having the same for Windows OS?

      Fixed Computer (@fixed_computer) said:
      February 9, 2021 at 5:48 pm

      I know this is an old article but it’s one of the first google search results so I want to answer your question for anyone else who is trying to use the .digrc file on Windows. Obviously you will need to create the .digrc file but you also need to create a user environment variable called “home” with a value of the path to the directory where the .digrc file lives.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s