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!!! 🙂

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

2 thoughts on “DIG command usage with examples

Leave a Reply

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