Quering DNS records – The dig tool

Basic format:

[email protected]:~$ dig droidzone.in

; <<>> DiG 9.8.1-P1 <<>> droidzone.in
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59555
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 0

;; QUESTION SECTION:
;droidzone.in. IN A

;; ANSWER SECTION:
droidzone.in. 27895 IN A 93.182.179.225

;; AUTHORITY SECTION:
droidzone.in. 85494 IN NS ns2.enames.in.
droidzone.in. 85494 IN NS ns1.enames.in.
droidzone.in. 85494 IN NS ns.enames.in.
droidzone.in. 85494 IN NS ns3.enames.in.

;; Query time: 24 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Sep 18 22:38:57 2012
;; MSG SIZE rcvd: 124

The printcmd options means that the command section (the name given to these first two line) is printed. You can turn it off by using the option +nocmd.

Dig can yield specific records like A or MX:

[email protected]:~$ dig droidzone.in A

; <<>> DiG 9.8.1-P1 <<>> droidzone.in A
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61546
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 0

;; QUESTION SECTION:
;droidzone.in.                  IN      A

;; ANSWER SECTION:
droidzone.in.           27811   IN      A       93.182.179.225

;; AUTHORITY SECTION:
droidzone.in.           85410   IN      NS      ns.enames.in.
droidzone.in.           85410   IN      NS      ns1.enames.in.
droidzone.in.           85410   IN      NS      ns2.enames.in.
droidzone.in.           85410   IN      NS      ns3.enames.in.

;; Query time: 24 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Sep 18 22:40:21 2012
;; MSG SIZE  rcvd: 124

[email protected]:~$ dig droidzone.in MX

; <<>> DiG 9.8.1-P1 <<>> droidzone.in MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52453
;; flags: qr rd ra; QUERY: 1, ANSWER: 7, AUTHORITY: 4, ADDITIONAL: 10

;; QUESTION SECTION:
;droidzone.in.                  IN      MX

;; ANSWER SECTION:
droidzone.in.           28800   IN      MX      30 aspmx4.googlemail.com.
droidzone.in.           28800   IN      MX      30 aspmx5.googlemail.com.
droidzone.in.           28800   IN      MX      10 aspmx.l.google.com.
droidzone.in.           28800   IN      MX      20 alt1.aspmx.l.google.com.
droidzone.in.           28800   IN      MX      20 alt2.aspmx.l.google.com.
droidzone.in.           28800   IN      MX      30 aspmx2.googlemail.com.
droidzone.in.           28800   IN      MX      30 aspmx3.googlemail.com.

;; AUTHORITY SECTION:
droidzone.in.           85401   IN      NS      ns.enames.in.
droidzone.in.           85401   IN      NS      ns3.enames.in.
droidzone.in.           85401   IN      NS      ns1.enames.in.
droidzone.in.           85401   IN      NS      ns2.enames.in.

;; ADDITIONAL SECTION:
aspmx.l.google.com.     3       IN      A       173.194.79.26
aspmx.l.google.com.     208     IN      AAAA    2607:f8b0:400e:c01::1b
alt1.aspmx.l.google.com. 234    IN      A       74.125.142.27
alt1.aspmx.l.google.com. 97     IN      AAAA    2a00:1450:4010:c04::1b
alt2.aspmx.l.google.com. 206    IN      A       74.125.130.27
alt2.aspmx.l.google.com. 96     IN      AAAA    2a00:1450:4010:c04::1a
aspmx2.googlemail.com.  212     IN      A       74.125.142.27
aspmx2.googlemail.com.  105     IN      AAAA    2a00:1450:4010:c04::1a
aspmx3.googlemail.com.  60      IN      A       74.125.130.27
aspmx3.googlemail.com.  99      IN      AAAA    2a00:1450:4010:c04::1a

;; Query time: 353 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Sep 18 22:40:30 2012
;; MSG SIZE  rcvd: 507

[email protected]:~$

In most cases, you dont need all that output.

[email protected]:~$ dig droidzone.in MX +short
20 alt2.aspmx.l.google.com.
30 aspmx2.googlemail.com.
30 aspmx3.googlemail.com.
30 aspmx4.googlemail.com.
30 aspmx5.googlemail.com.
10 aspmx.l.google.com.
20 alt1.aspmx.l.google.com.

This option can be added as default to dig by editing ~/.digrc to have the following:

To use a different name server call dig with the first parameter as@nameserver. For example we can query ns.hosteurope.com directly like this:

	
dig @ns.hosteurope.com www.droidzone.in

My ~/.digrc contains:

 

+noall 
+answer

 


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.