DIG command usage with examples

The “dig command” – A detailed view!

It’s a well known and commonly using DNS lookup tool under Unix. It has a lot of uses by the help of different switches along with it. Some important dig command usages and examples are explained below.

Note :: The installation is simple "yum install bind-utils"

1) Simple usage; for finding the A record.

dig domain.com

This command simply displays the Address record(A record IP) of the domain.com

Example:

# dig crybit.com

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5 <<>> crybit.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER< ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

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

;; ANSWER SECTION:
crybit.com. 14400 IN A 133.Ip.Ip.Ip

2) To find out the Name Servers of a domain.

Usage:

dig -t NS domain.com
Or
dig domain.com NS

Example:

# dig -t NS crybit.com OR dig crybit.com NS

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5 <<>> -t NS crybit.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER< ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;crybit.com. IN NS

;; ANSWER SECTION:
crybit.com. 21600 IN NS ns1.eclinux.com.
crybit.com. 21600 IN NS ns2.eclinux.com.

Dig

3. For mail server (MX) record.

Usage:

dig -t MX domain.com
Or
dig domain.com MX

Example:

# dig -t MX crybit.com OR dig crybit.com MX

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5 <<>> -t MX crybit.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER< ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;crybit.com. IN MX

;; ANSWER SECTION:
crybit.com. 14148 IN MX 0 crybit.com.

4. For find out SOA details.

Usage:

dig -t SOA domain.com
Or
dig domain.com SOA

Example:

# dig -t SOA crybit.com OR dig crybit.com SOA

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5 <<>> -t SOA crybit.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER< ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;crybit.com. IN SOA

;; ANSWER SECTION:
crybit.com. 21600 IN SOA ns1.eclinux.com. admin.eclinux.com.. 2013082902 86400 7200 3600000 86400

5. To list out ALL available records under a domain..

Usage:

dig -t ANY domain.com 
Or 
dig domain.com ANY

Example:

# dig -t ANY crybit.com ANY

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5 <<>> -t ANY crybit.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER< ;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0

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

;; ANSWER SECTION:
crybit.com. 14400 IN MX 0 crybit.com.
crybit.com. 21600 IN SOA ns1.eclinux.com. admin.crybit.com. 2013082902 86400 7200 3600000 86400
crybit.com. 21600 IN NS ns1.eclinux.com.
crybit.com. 21600 IN NS ns2.eclinux.com.
crybit.com. 14400   IN A 133.Ip.Ip.Ip

6. View Short Output Using dig +short

dig domain.name +short

Example:

# dig crybit.com +short
198.15.127.170

# dig NS crybit.com +short
ns1.eclinux.com.
ns2.eclinux.com.

7. To trace out the complete path use +trace switch with dig

dig domain.com +trace

Example:

# dig crybit.com +trace

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-20.P1.el5 <<>> crybit.com +trace
;; global options:  printcmd
.            12438    IN    NS    i.root-servers.net.
.            12438    IN    NS    m.root-servers.net.
.            12438    IN    NS    d.root-servers.net.
.            12438    IN    NS    b.root-servers.net.
.            12438    IN    NS    l.root-servers.net.
.            12438    IN    NS    g.root-servers.net.
.            12438    IN    NS    j.root-servers.net.
.            12438    IN    NS    a.root-servers.net.
.            12438    IN    NS    c.root-servers.net.
.            12438    IN    NS    f.root-servers.net.
.            12438    IN    NS    e.root-servers.net.
.            12438    IN    NS    k.root-servers.net.
.            12438    IN    NS    h.root-servers.net.
;; Received 228 bytes from 8.8.8.8#53(8.8.8.8) in 150 ms

in.            172800    IN    NS    b2.in.afilias-nst.org.
in.            172800    IN    NS    ns7.cdns.net.
in.            172800    IN    NS    a0.in.afilias-nst.info.
in.            172800    IN    NS    c0.in.afilias-nst.info.
in.            172800    IN    NS    a1.in.afilias-nst.in.
in.            172800    IN    NS    b0.in.afilias-nst.org.
in.            172800    IN    NS    b1.in.afilias-nst.in.
in.            172800    IN    NS    a2.in.afilias-nst.info.
;; Received 493 bytes from 192.36.148.17#53(i.root-servers.net) in 140 ms

crybit.com.        86400    IN    NS    ns1.eclinux.com.
crybit.com.        86400    IN    NS    ns2.eclinux.com.
;; Received 83 bytes from 199.249.125.1#53(b2.in.afilias-nst.org) in 138 ms

crybit.com.        14400    IN    A    198.15.127.170
crybit.com.        86400    IN    NS    ns1.eclinux.com.
crybit.com.        86400    IN    NS    ns2.eclinux.com.
;; Received 131 bytes from 198.15.127.170#53( ns2.eclinux.com.) in 0 ms

8. DNS Reverse Look-up.

# dig -x IP

That’s it!!! 🙂

Arunlal Ashok

Sr. Linux Server Administrator. I'm managing Linux servers since 2012. I started this blog to share and discuss my ideas. Check My Profile in uPwork (oDesk) and create a job, if you need any administration help. Thanks!!

You may also like...

2 Responses

  1. Shridhar says:

    Good reference for linux learners as well as sys admins.

Leave a Reply

Your email address will not be published. Required fields are marked *