Mac OS X

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

Protected: Ben Henderson’s Mac G4

Posted on

This content is password protected. To view it please enter your password below: