Using The Dig Command

  • Applies To: All Services
  • Difficulty: Medium
  • Time Needed: 5 minutes
  • Tools Needed: None
  • Reading Time: 0:07 min

The command dig is a tool for querying DNS nameservers for information about host addresses, mail exchanges, nameservers, and related information. This tool can be used from any Linux (Unix) or Macintosh OS X operating system. The most typical use of dig is to simply query a single host.

Run The Command

dig crucialwebhost.com

View The Output

; <<>> DiG 9.3.4-P1 <<>> crucialwebhost.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 35785
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 3

;; QUESTION SECTION:
;crucialwebhost.com.            IN      A

;; ANSWER SECTION:
crucialwebhost.com.     14400   IN      A       208.43.148.151

;; Query time: 63 msec
;; SERVER: 67.228.89.10#53(67.228.89.10)
;; WHEN: Fri Apr 17 17:37:34 2009
;; MSG SIZE  rcvd: 154

Understanding The Results

The opening section of dig's output tells us a little about itself (version 9.3.4) and the global options that are set (in this case, printcmd):

; <<>> DiG 9.3.4-P1 <<>> crucialwebhost.com
;; global options:  printcmd

Here, dig tells us some technical details about the answer received from the DNS server. This section of the output can be toggled using the +[no]comments option—but beware that disabling the comments also turns off many section headers:

;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 35785
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 3

In the question section, dig reminds us of our query. The default query is for an Internet address (A):

;; QUESTION SECTION:
;crucialwebhost.com.            IN      A

Now we have our anwser, the address of crucialwebhost.com is 208.43.148.151:

;; ANSWER SECTION:
crucialwebhost.com.     14400   IN      A       208.43.148.151

The final section of the default output contains statistics about the query; it can be toggled with the +[no]stats option:

;; Query time: 63 msec
;; SERVER: 67.228.89.10#53(67.228.89.10)
;; WHEN: Fri Apr 17 17:37:34 2009
;; MSG SIZE  rcvd: 154

What can I find using the dig command?

dig will let you perform any valid DNS query, the most common of which are A (the IP address), TXT (text annotations), MX (mail exchanges), and NS nameservers.

Use the following command to get the addresses for crucialwebhost.com:

dig crucialwebhost.com A +noall +answer

Use the following command to get a list of all the mailservers for crucialwebhost.com:

dig crucialwebhost.com MX +noall +answer

Use the following command to get a list of authoritative DNS servers for crucialwebhost.com:

dig crucialwebhost.com NS +noall +answer

Use the following command to get a list of all the above in one set of results:

dig crucialwebhost.com ANY +noall +answer

Use the following command to query using a specific nameserver:

dig @ns1.crucialwebhost.com crucialwebhost.com

Use the following to trace the path taken:

dig crucialwebhost.com +trace

Save. Share. Submit.

Related Articles

Sorry, no related entries exist for this article.

Rate Article

Hide Sidebar