The dig command is a tool for querying DNS servers to request information about host addresses, mail exchangers, name servers, and related information. This tool can be used on any Linux ( Unix ) or Mac OS X operating system.
For example:
dig ejemplo.com
Result:
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-16.P1.el5 <<>> ejemplo.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62559
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;ejemplo.com. IN A
;; ANSWER SECTION:
ejemplo.com. 666 IN A xxx.xxx.xxx.xxx
;; AUTHORITY SECTION:
ejemplo.com. 155962 IN NS ns1.ejemplo.com.
ejemplo.com. 155962 IN NS ns2.ejemplo.com.
;; ADDITIONAL SECTION:
ns1.fabulous.com. 6844 IN A xxx.xxx.xxx.xxx
ns2.fabulous.com. 6844 IN A xxx.xxx.xxx.xxx
;; Query time: 78 msec
;; SERVER: xxx.xxx.xxx.xxx#53(xxx.xxx.xxx.xxx)
;; WHEN: Tue Mar 19 18:27:53 2013
;; MSG SIZE rcvd: 170
Understanding the results
The initial part of the result shows the version and the global options that are specified ( in this case printcmd ):
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-16.P1.el5 <<>>
ejemplo.com
;; global options: printcmd
In the following section, dig shows various technical details about the DNS server's response. This section of the result can be disabled using the +[no]comments option, but keep in mind that disabling this option will also disable various information headers:
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62559
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 2, ADDITIONAL: 2
In the "question" section, dig reminds us of our query. The default query is for an Internet address (A):
;; QUESTION SECTION:
;ejemplo.com. IN A
The next section is the answer to the query. In this case, it returns an IP address, which in the example is xxx.xxx.xxx.xxx:
;; ANSWER SECTION:
ejemplo.com. 666 IN A xxx.xxx.xxx.xxx
The final section of the default result contains statistics about the query. These can also be disabled with the +[no]stats option:
;; Query time: 78 msec
;; SERVER: xxx.xxx.xxx.xxx#53(xxx.xxx.xxx.xxx)
;; WHEN: Tue Mar 19 18:27:53 2013
;; MSG SIZE rcvd: 170
What can I find using dig
The dig command lets you perform any DNS query; the most common are queries for A records ( IP addresses ), TXT records ( text annotations ), MX records ( mail servers ), and name servers.
Using the above with ejemplo.com will show the following results.
For the IP address of the domain:
dig ejemplo.com A +noall +answer
The following command displays all the mail servers:
dig ejemplo.com MX +noall +answer
The following command displays all the name servers:
dig ejemplo.com NS +noall +answer
The following command will display everything mentioned above:
dig ejemplo.com ANY +noall +answer
The following query will perform the lookup using a specific name server:
dig @ns1.siliconhosting.com ejemplo.com
And finally, the command to trace the route of the response to the query:
dig ejemplo.com +trace