Check DNS (Domain Name Server) Records On Linux Using Dig Command

dig stands for domain information groper is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use and clarity of output. Other lookup tools tend to have less functionality than dig. Alternatively we can Lookup the DNS records using nslookup command & host command.

1) How to Lookup domain IP address / A record ?

Use the dig command followed by corresponding Domain Name to lookup the domain A record / IP address.

# Common Syntax for nslookup command #
# dig [-Options] [domainname.com] [Type]

# Lookup 2daygeek.com domain A Record / IP Address #
# dig 2daygeek.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> 2daygeek.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19793
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1

;; QUESTION SECTION:
;2daygeek.com.                  IN      A

;; ANSWER SECTION:
2daygeek.com.           14114   IN      A       182.71.233.70

;; AUTHORITY SECTION:
2daygeek.com.           86114   IN      NS      ns2.2daygeek.in.
2daygeek.com.           86114   IN      NS      ns1.2daygeek.in.

;; ADDITIONAL SECTION:
ns2.2daygeek.in.       14114   IN      A       182.71.233.70

;; Query time: 0 msec
;; SERVER: 83.170.69.2#53(83.170.69.2)
;; WHEN: Wed Feb 26 12:16:01 2014
;; MSG SIZE  rcvd: 110

The output is clearly shows, server is referred the DNS server IP address and 53 is referred DNS service port number.

2) How to Lookup only domain IP address / A record ?

Use the dig command followed by corresponding Domain Name with additional Query option to filter only required values such as domain A record / IP address.

# dig 2daygeek.com +nocomments +noquestion +noauthority +noadditional +nostats

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> 2daygeek.com +nocomments +noquestion +noauthority +noadditional +nostats
;; global options: +cmd
2daygeek.com.           14084   IN      A       182.71.233.70

3) How to Lookup domain IP address / A record using short Method ?

Use the dig command followed by corresponding Domain Name with additional Query option to filter only required values such as domain A record / IP address.

# dig 2daygeek.com +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> 2daygeek.com +noall +answer
;; global options: +cmd
2daygeek.com.           14101   IN      A       182.71.233.70

4) How to Lookup domain IP address / A record using +short option ?

Use the dig command followed by corresponding Domain Name with additional Query option +short to filter only required values such as domain A record / IP address.

# dig 2daygeek.com +short

182.71.233.70

5) How to Lookup the domain MX record ?

Use the dig command followed by corresponding Domain Name with additional Query option to filter only MX records.

# dig 2daygeek.com MX +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> 2daygeek.com MX +noall +answer
;; global options: +cmd
2daygeek.com.           14087   IN      MX      0 2daygeek.com.

The above output clearly shows, we have found only one MX record and the priority is 0.

6) How to Lookup the domain MX record using (-t) option ?

Use the dig command followed by -t option with corresponding Domain Name to filter only MX records.

# dig -t MX 2daygeek.com +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -t MX 2daygeek.com +noall +answer
;; global options: +cmd
2daygeek.com.           13910   IN      MX      0 2daygeek.com.

The above output clearly shows, we have found only one MX record and the priority is 0.

7) How to Lookup the domain NS record ?

Use the dig command followed by corresponding Domain Name with additional Query option to filter only NS (Name Servers) records.

# dig 2daygeek.com NS +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> 2daygeek.com NS +noall +answer
;; global options: +cmd
2daygeek.com.           86055   IN      NS      ns2.2daygeek.in.
2daygeek.com.           86055   IN      NS      ns1.2daygeek.in.

8) How to Lookup the domain TXT (SPF) record ?

Use the dig command followed by corresponding Domain Name with additional Query option to filter only TXT (SPF) record.

# dig 2daygeek.com TXT +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> 2daygeek.com TXT +noall +answer
;; global options: +cmd
2daygeek.com.           14297   IN      TXT     "v=spf1 ip4:182.71.233.70 +a +mx +ip4:49.50.66.31 ?all"

9) How to Lookup the domain SOA record ?

Use the dig command followed by corresponding Domain Name with additional Query option to filter only SOA record.

# dig 2daygeek.com SOA +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> 2daygeek.com SOA +noall +answer
;; global options: +cmd
2daygeek.com.           86391   IN      SOA     ns1.2daygeek.in. jeyakabil.gmail.com. 2013110202 86400 7200 3600000 86400

This will shows only answer section which i excepted, cool...

10) How to Lookup the domain reverse DNS (PTR) record ?

Use the dig command followed by corresponding Domain Name with additional Query option to filter only DNS (PTR) record.

# dig -x 182.71.233.70 +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> -x 182.71.233.70 +noall +answer
;; global options: +cmd
70.233.71.182.in-addr.arpa. 86388 IN    PTR     NSG-Static-070.233.71.182.airtel.in.

11) How to Lookup ALL domain records ?

Use the dig command followed by corresponding Domain Name with additional Query option to Shows all the DNS records such as A, NS, PTR, MX, SPF, TXT records.

# dig 2daygeek.com ANY +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> 2daygeek.com ANY +noall +answer
;; global options: +cmd
2daygeek.com.           12922   IN      TXT     "v=spf1 ip4:182.71.233.70 +a +mx +ip4:49.50.66.31 ?all"
2daygeek.com.           12693   IN      MX      0 2daygeek.com.
2daygeek.com.           12670   IN      A       182.71.233.70
2daygeek.com.           84670   IN      NS      ns2.2daygeek.in.
2daygeek.com.           84670   IN      NS      ns1.2daygeek.in.

12) How to Lookup particular nameserver IP address / record ?

Use the dig command followed by corresponding Name Server ns1.2daygeek.in or ns2.2daygeek.in with Domain Name and additional Query option to filter particular Name Server IP Address.

# dig @ns1.2daygeek.in 2daygeek.com ANY +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> @ns1.2daygeek.in 2daygeek.com ANY +noall +answer
; (1 server found)
;; global options: +cmd
2daygeek.com.           14400   IN      TXT     "v=spf1 ip4:182.71.233.70 +a +mx +ip4:49.50.66.31 ?all"
2daygeek.com.           14400   IN      MX      0 2daygeek.com.
2daygeek.com.           86400   IN      SOA     ns1.2daygeek.in. jeyakabil.gmail.com. 2013110202 86400 7200 3600000 86400
2daygeek.com.           86400   IN      NS      ns1.2daygeek.in.
2daygeek.com.           86400   IN      NS      ns2.2daygeek.in.
2daygeek.com.           14400   IN      A       182.71.233.70

13) How to use Bulk DNS Query to Lookup domain details ?

Use the dig command followed by Domain Name with additional options + Query to filter Necessary Records, Here i'm going to Lookup MX & NS records of 2daygeek.com domain name.

# dig 2daygeek.com NS +noall +answer mrclks.com MX +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> 2daygeek.com NS +noall +answer mrclks.com MX +noall +answer
;; global options: +cmd
2daygeek.com.           84199   IN      NS      ns1.2daygeek.in.
2daygeek.com.           84199   IN      NS      ns2.2daygeek.in.
mrclks.com.             14400   IN      MX      0 mrclks.com.

14) How to Lookup Bulk DNS Query using file with (-f) Option ?

First create a fill and add the list of domains which you want to Lookup DNS records (In my case i'm going to create a file called dig-demo.txt and will add few domains, then perform the action).

# nano dig-test.txt
2daygeek.com
mrclks.com
clickbanklocations.in

I have created a file, the name of dig-test.txt with three domains and Now, I'm going to lookup NS Record of above mentioned domains using file command.

# dig -f dig-test.txt NS +noall +answer
2daygeek.com.           70014   IN      NS      ns2.2daygeek.in.
2daygeek.com.           70014   IN      NS      ns1.2daygeek.in.
mrclks.com.             72216   IN      NS      ns7.999servers.com.
mrclks.com.             72216   IN      NS      ns8.999servers.com.
clickbanklocations.in.  86059   IN      NS      ns2.basetech.net.
clickbanklocations.in.  86059   IN      NS      ns1.basetech.net.

15) How to store default dig option to file and perform only answer section ?

If you want to perform dig command with only answer section, use the below steps. Just create a file called .digrc on root folder and open the file with your favorite text editor and store the default options +noall and +answer.

# nano .digrc
+noall +answer

Now, I'm going to perform the action using the .digrc file which i created before to check whether the above file is working or not.

# dig 2daygeek.com NS
2daygeek.com.           67029   IN      NS      ns2.2daygeek.in.
2daygeek.com.           67029   IN      NS      ns1.2daygeek.in.

This will shows only answer section which i excepted, cool...)

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...