What is Dig (command) ?

Understanding Dig Command Basics:

Dig (Domain Information Groper) is  a command-line tool for querying Domain Name System name servers, mail exchangers, hosts, etc. Dig command is mostly used for troubleshooting DNS problems because of its ease of use and clarity of results. Dig is part of the BIND domain name server software suite. 

Dig is normally used with command-line arguments, but also has a batch mode in which querying information from a file. If no server is specified in the command invocation, the lookup is made to each of the servers listed in the . Without arguments given, it queries the DNS root zone. 

The simple usage of dig looks like that  

dig @server name type

Where: 

server is the IP address of the name server to query. If the server provided is a host name, then dig resolves it before querying. If no server argument is provided, dig searches in the resolve.conf file. The results are displayed.
Name is the resource record you want to lookup.
Type is the type of the query – any, A, MX, etc. If no type is specified, dig will make a lookup for the A record.

; <<>> DiG 9.10.3-P4-Ubuntu <<>> yourdomain.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6242
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 5

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;yourdomain.com.            IN    A

;; ANSWER SECTION:
yourdomain.com.        300    IN    A    69.172.201.153

;; AUTHORITY SECTION:
yourdomain.com.        45676    IN    NS    buy.internettraffic.com.
yourdomain.com.        45676    IN    NS    sell.internettraffic.com.

;; ADDITIONAL SECTION:
buy.internettraffic.com. 5519    IN    A    64.96.241.73
buy.internettraffic.com. 5519    IN    A    64.96.240.54
sell.internettraffic.com. 5519    IN    A    176.74.176.175
sell.internettraffic.com. 5519    IN    A    176.74.176.176

;; Query time: 3 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Fri Sep 09 11:26:51 EEST 2016
;; MSG SIZE  rcvd: 176

 

; <<>> DiG 9.10.3-P4-Ubuntu <<>> yourdomain.com any
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51811
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 2, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;yourdomain.com.            IN    ANY

;; ANSWER SECTION:
yourdomain.com.        300    IN    A    69.172.201.153
yourdomain.com.        86400    IN    SOA    ns1.uniregistrymarket.link. hostmaster.hostingnet.com. 1473260832 10800 3600 604800 86400
yourdomain.com.        65877    IN    NS    ns1.uniregistrymarket.link.
yourdomain.com.        65877    IN    NS    ns2.uniregistrymarket.link.

;; AUTHORITY SECTION:
yourdomain.com.        65877    IN    NS    ns1.uniregistrymarket.link.
yourdomain.com.        65877    IN    NS    ns2.uniregistrymarket.link.

;; Query time: 4 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Fri Sep 09 11:44:12 EEST 2016
;; MSG SIZE  rcvd: 203
 
Understanding the results: 

You can see that there are several sections displayed in the results:

  1. Header – this is the dig version
  2. Question section – the section where your request is shown.
  3. Answer section – shows the answer of your particular question
  4. Authority section – shows who has the authority to provide you with the answer.
  5. Addition section – shows additional information, basically the Ip of the name servers given in the authority section.
  6. Statistics – Query time, server, date and size of a message.

In most cases, you need only the answer section, so there is an option for you to turn off all other section writing your dig request like that :

dig yourdomain.com +noall +answer

 

dig yourdomain.com +noall +answer

; <<>> DiG 9.10.3-P4-Ubuntu <<>> yourdomain.com +noall +answer
;; global options: +cmd
yourdomain.com.        300    IN    A    69.172.201.153

 

What can I find using the dig command?

Using the dig command 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 yourdomain.com :

dig yourdomain.com A +noall +answer

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

dig yourdomain.com MX +noall +answer

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

dig yourdomain.com NS +noall +answer

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

dig yourdomain.com ANY +noall +answer 

Use the following command to query using a specific nameserver:

dig @ns1.yourdomain.com yourdomain.com 

Use the following to trace the path taken:

dig yourdomain.com +trace

 

Be Smarter!

Ready to use what you've learned? Awesome. Enjoy increased power, flexibility, and control for your websites with us.   Start now

X