Dig

From Postmaster Administration Wiki
Jump to: navigation, search

dig is a DNS record query tool, part of the ISC BIND software most commonly used, and successor to nslookup tool which is supplied with Windows. Here is a brief summary concerning the most common types of queries one would need as a postmaster. Consult the Unix man page or online documentation for more details.


Finding an IP for a name.

$ dig help.netmail.com

;  <<>> DiG 9.5.2-P2 <<>> help.netmail.com
;;  global options:  printcmd
;;  Got answer:
;;  ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39280
;;  flags: qr rd ra;  QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

;;  QUESTION SECTION:
; help.netmail.com.              IN      A

;;  ANSWER SECTION:
help.netmail.com.       1192    IN      A       68.67.42.137

;;  AUTHORITY SECTION:
netmail.com.            172792  IN      NS      dns2.easydns.net.
netmail.com.            172792  IN      NS      dns1.easydns.com.

;;  ADDITIONAL SECTION:
dns2.easydns.net.       10792   IN      A       72.52.2.1

;;  Query time: 146 msec
;;  SERVER: 192.0.2.1#53(192.0.2.1)
;;  WHEN: Wed Apr 24 18:53:59 2013
;;  MSG SIZE  rcvd: 123

$

The output from dig is verbose, showing the original query, the answer, the name servers where authoritative answers are found, and supplemental information. These are the common elements of all DNS replies and dig unpacks and displays the lot along with comments, lines starting with a semi-colon ( ; ). The following two examples repeat the same query as before, but demonstrate the more compact and terse answer formats.


Find an IP from name, compact answer.

$ dig +nocomments help.netmail.com

; <<>> DiG 9.5.2-P2 <<>> +nocomments help.netmail.com
;; global options:  printcmd
; help.netmail.com.              IN      A
help.netmail.com.       1125    IN      A       68.67.42.137
netmail.com.            125152  IN      NS      dns2.easydns.net.
netmail.com.            125152  IN      NS      dns1.easydns.com.
dns2.easydns.net.       4479    IN      A       72.52.2.1
;;  Query time: 143 msec
;;  SERVER: 192.0.2.1#53(192.0.2.1)
;;  WHEN: Thu Apr 25 08:07:59 2013
;;  MSG SIZE  rcvd: 123

$


Find an IP from name, terse answer.

$ dig +short help.netmail.com 
68.67.42.137
$

Finding an IP address from a name is often called a forward name lookup. However, it's pretty common also to want to find the domain name given an IP address, the reverse name lookup. To do so, we have to first reverse the IPv4 address and suffix it with .in-addr.arpa to find the DNS PTR resource record.


Find name from IP, the long way.

$ dig +short 137.42.67.68.in-addr.arpa. PTR
IP-68-67-42-137.static.fibrenoire.ca.
$

There is a very useful short cut for finding the PTR record, where you simply specify the -x option and the IP address without having to reverse it yourself.

Find name from IP, the easy way.
$ dig +short -x 68.67.42.137
IP-68-67-42-137.static.fibrenoire.ca.
$

Note that in the last two examples, we supplied a DNS resource record type. There are many resource records types, for which IANA maintains a DNS RR list. One RR type in the list, code 255, is the ANY wildcard type. A DNS lookup of ANY will return as much information that is known about a name, subject to packet length limits.

$ dig +nocomments netmail.com any

; <<>> DiG 9.5.2-P2 <<>> +nocomments netmail.com any
;; global options:  printcmd
;netmail.com.                   IN      ANY
netmail.com.            166     IN      TXT     "v=spf1 +ip4:68.67.42.128/25  +ip4:216.168.28.44 +ip4:64.68.0.0/16
                                                 +ip4:65.103.98.189 +ip4:24.201.245.36 +a  +mx -all"
netmail.com.            166     IN      A       68.67.42.145
netmail.com.            166     IN      SOA     dns0.easydns.com. zone.easydns.com. 1363927573 21600 7200 604800 1200
netmail.com.            166     IN      MX      10 mail.netmail.com.
netmail.com.            166     IN      MX      10 mail1.netmail.com.
netmail.com.            166     IN      NS      dns3.easydns.ca.
netmail.com.            166     IN      NS      dns1.easydns.com.
netmail.com.            166     IN      NS      dns2.easydns.net.
netmail.com.            166     IN      NS      dns2.easydns.net.
netmail.com.            166     IN      NS      dns3.easydns.ca.
netmail.com.            166     IN      NS      dns1.easydns.com.
dns2.easydns.net.       2081    IN      A       72.52.2.1
;; Query time: 159 msec
;; SERVER: 192.0.2.1#53(192.0.2.1)
;; WHEN: Thu Apr 25 08:47:57 2013
;; MSG SIZE  rcvd: 407

$


References