dig – DNS lookup utility
The command dig is a tool for querying DNS nameservers for information about host addresses, mail exchanges, nameservers, and related information. . The most typical use of dig is to simply query a single host.
dig [ @server ] [ -b address ] [ -c class ] [ -f filename ] [ -k filename] [ -p port# ] [ -t type ] [ -x addr ] [ -y name:key ] [ name ] [ type ] [class ] [ queryopt… ]
dig [ -h ]
dig [ global-queryopt… ] [ query… ]
dig (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.
Unless it is told to query a specific name server, dig will try each of the servers listed in /etc/.
When no command line arguments or options are given, will perform an NS query for “.” (the root).
Run the command:
View the Output:
; <<>> DiG 9.4.1-P1 <<>> mt-example.com ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25550 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;mt-example.com. IN A ;; ANSWER SECTION: mt-example.com. 28626 IN A 22.214.171.124 ;; Query time: 4 msec ;; SERVER: 126.96.36.199#53(188.8.131.52) ;; WHEN: Thu Aug 7 16:49:35 2008 ;; MSG SIZE rcvd: 48
Understanding the Results
The opening section of dig’s output tells us a little about itself (version 9.4.1) and the global options that are set (in this case,
; <<>> DiG 9.4.1-P1 <<>> mt-example.com ;; global options: printcmd
Here, dig tells us some technical details about the answer received from the DNS server. This section of the output can be toggled using the +[no]comments option—but beware that disabling the comments also turns off many section headers:
;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25550 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
In the question section, dig reminds us of our query. The default query is for an Internet address (A).
;; QUESTION SECTION: ;mt-example.com. IN A
Now we have our anwser, the address of mt-example.com is 184.108.40.206.
;; ANSWER SECTION: mt-example.com. 28626 IN A 220.127.116.11
The final section of the default output contains statistics about the query; it can be toggled with the +[no]stats option.
;; Query time: 272 msec ;; SERVER: 18.104.22.168#53(22.214.171.124) ;; WHEN: Thu Feb 13 09:35:55 PST 2014 ;; MSG SIZE rcvd: 48
A quick way to just get the answer only is to run the following command:
dig mt-example.com +short
What can I find using the dig command?
dig 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 mt-example.com.
dig mt-example.com A +noall +answer
Use the following command to get a list of all the mailservers for mt-example.com.
dig mt-example.com MX +noall +answer
Use the following command to get a list of authoritative DNS servers for mt-example.com.
dig mt-example.com NS +noall +answer
Use the following command to get a list of all the above in one set of results.
dig mt-example.com ANY +noall +answer
Use the following command to query using a specific nameserver.
dig @ns1.mediatemple.net mt-example.com
Use the following to trace the path taken.
dig mt-example.com +trace