Dig command linux / unix examples

Dec 17 • All • 827 Views • No Comments on Dig command linux / unix examples

Hey,

So, what is DIG command used for? Well, for those who are not familiar DIG is a tool to perform DNS lookups. It has a lot of switches to find out details about the DNS record we are looking for. It is a pretty straight and direct command line utility to find DNS Records *if you know the switch to use*. So lets skip the introductions and check them out ūüôā

Simply using the dig command followed by a domain name returns the A record of the domain.

user@server:~$ dig example.com

Example:

user@server:~$ dig learntutors.com


; <<>> DiG 9.9.5-3ubuntu0.6-Ubuntu <<>> learntutors.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11391

;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1


;; OPT PSEUDOSECTION:

; EDNS: version: 0, flags:; udp: 4096

;; QUESTION SECTION:

;learntutors.com. IN A


;; ANSWER SECTION:

learntutors.com. 300 IN A 104.28.13.115

learntutors.com. 300 IN A 104.28.12.115


;; Query time: 105 msec

;; SERVER: 127.0.1.1#53(127.0.1.1)

;; WHEN: Thu Dec 17 10:59:27 IST 2015

;; MSG SIZE rcvd: 76

2) To find MX (Mail eXchanger) record:

user@server:~$ dig -t MX example.com

Example:

user@server:~$  dig -t MX learntutors.com


; <<>> DiG 9.9.5-3ubuntu0.6-Ubuntu <<>> -t MX learntutors.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25062

;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1


;; OPT PSEUDOSECTION:

; EDNS: version: 0, flags:; udp: 4096

;; QUESTION SECTION:

;learntutors.com. IN MX


;; ANSWER SECTION:

learntutors.com. 300 IN MX 20 mx2.zoho.com.

learntutors.com. 300 IN MX 50 mx3.zoho.com.

learntutors.com. 300 IN MX 10 mx.zoho.com.


;; Query time: 190 msec

;; SERVER: 127.0.1.1#53(127.0.1.1)

;; WHEN: Thu Dec 17 11:05:13 IST 2015

;; MSG SIZE rcvd: 108

3.  Find Name Servers of a domain

user@server:~$ dig -t NS example.com

Example:

user@server:~$ dig -t NS learntutors.com


; <<>> DiG 9.9.5-3-Ubuntu <<>> -t NS learntutors.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17347

;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1


;; OPT PSEUDOSECTION:

; EDNS: version: 0, flags:; udp: 512

;; QUESTION SECTION:

;learntutors.com. IN NS


;; ANSWER SECTION:

learntutors.com. 21599 IN NS greg.ns.cloudflare.com.

learntutors.com. 21599 IN NS brenda.ns.cloudflare.com.


;; Query time: 253 msec

;; SERVER: 8.8.8.8#53(8.8.8.8)

;; WHEN: Thu Dec 17 14:22:50 IST 2015

;; MSG SIZE rcvd: 98

4. To find SOA Records

user@server:~$ dig -t SOA example.com

Example:

user@server:~$ dig -t SOA learntutors.com


; <<>> DiG 9.9.5-3-Ubuntu <<>> -t SOA learntutors.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32705

;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1


;; OPT PSEUDOSECTION:

; EDNS: version: 0, flags:; udp: 512

;; QUESTION SECTION:

;learntutors.com. IN SOA


;; ANSWER SECTION:

learntutors.com. 21599 IN SOA brenda.ns.cloudflare.com. dns.cloudflare.com. 2020142160 10000 2400 604800 3600


;; Query time: 173 msec

;; SERVER: 8.8.8.8#53(8.8.8.8)

;; WHEN: Thu Dec 17 14:25:19 IST 2015

;; MSG SIZE rcvd: 105

5.  To find TXT Records

user@server:~$ dig -t TXT example.com

Example:

user@server:~$ dig -t TXT learntutors.com


; <<>> DiG 9.9.5-3-Ubuntu <<>> -t TXT learntutors.com

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54437

;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1


;; OPT PSEUDOSECTION:

; EDNS: version: 0, flags:; udp: 512

;; QUESTION SECTION:

;learntutors.com. IN TXT


;; ANSWER SECTION:

learntutors.com. 29 IN TXT “google-site-verification=ooCm8t9CMpIutAQpCVpZxsK3pkfIoint36vKLYqPcSs”

learntutors.com. 29 IN TXT “v=spf1 a mx ip4:192.186.245.100 ip4:198.252.101.197 include:servers.mcsv.net include:_spf.google.com include:zoho.com ~all”


;; Query time: 158 msec

;; SERVER: 8.8.8.8#53(8.8.8.8)

;; WHEN: Thu Dec 17 14:34:14 IST 2015

;; MSG SIZE rcvd: 260

6. To find ALL records of a Domain

user@server:~$ dig -t ANY example.com

Now instead of getting the whole output, to print out only the answer part, add +short at the end of the command.
Example:

user@server:~$ dig -t A learntutors.com +short


104.28.12.115

104.28.13.115 /

user@server:~$ dig -t MX learntutors.com +short


20 mx2.zoho.com.

50 mx3.zoho.com.

10 mx.zoho.com.

Or the same short answer can be viewed appending¬†| exec sed -n ‘/QUESTION/,/Query/p’¬†to the end of the dig command. What it does is that it prints all lines between the QUESTION and ANSWER SECTION of the output.

user@server:¬†~$¬†dig -t SOA learntutors.com¬†| exec sed -n ‘/QUESTION/,/Query/p’

;; QUESTION SECTION:

;learntutors.com. IN SOA


;; ANSWER SECTION:

learntutors.com. 21599 IN SOA brenda.ns.cloudflare.com. dns.cloudflare.com. 2020142160 10000 2400 604800 3600


;; Query time: 165 msec

The choice of command depends on your personal preference as basically all it does is the same, its just the presentation which is different

Related Posts

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

« »