How to Use the Dig Command in Linux
The dig command is a command that is used for querying DNS name servers for information about host addresses, mail exchanges, name servers, and related information.
Dig is included in most Linux and Mac OS X installations by default via the Terminal. If you are using Windows you will need to install the BIND utilities package or any of the dig replacements that can be found by searching Google for Dig Windows.
Typically, the simplest query is for a single host. By default, however, dig is pretty verbose. You probably don’t need all the information in the default output, but it’s probably worth knowing what it is. Below is an example of the default output from a ‘dig liquidweb.com‘:
$ dig liquidweb.com
; <<>> DiG 9.5.1-P2-RedHat-9.5.1-2.P2.fc10 <<>> liquidweb.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3752
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;liquidweb.com. IN A
;; ANSWER SECTION:
liquidweb.com. 197 IN A 209.59.139.21
;; AUTHORITY SECTION:
liquidweb.com. 857 IN NS ns.liquidweb.com.
liquidweb.com. 857 IN NS ns1.liquidweb.com.
;; ADDITIONAL SECTION:
ns.liquidweb.com. 671 IN A 209.59.139.20
ns1.liquidweb.com. 806 IN A 64.91.251.155
;; Query time: 6 msec
;; SERVER: 69.16.222.254#53(69.16.222.254)
;; WHEN: Wed Jun 10 10:35:44 2009
;; MSG SIZE rcvd: 114
This result shows the 4 main sub-sections: Question, Answer, Authority, Additional.
Question Section
;; QUESTION SECTION:
;liquidweb.com. IN A
This section shows the query that is being made. In this case we are just looking for the host IP(or A record if you prefer) for liquidweb.com.
***For more information on the various types of DNS records please read this article***
Answer Section
;; ANSWER SECTION:
liquidweb.com. 197 IN A 209.59.139.21
This section shows the answer or result of the query that was made(provided one can be provided). In this case the answer is the IP address that liquidweb.com resides on.
Authority Section
;;AUTHORITY SECTION:
liquidweb.com. 857 IN NS ns.liquidweb.com.
liquidweb.com. 857 IN NS ns1.liquidweb.com.
This section shows the nameservers that provided dig with the answer to its query. For liquidweb.com the authoritative name servers are ns.liquidweb.com and ns1.liquidweb.com.
Additional Section
;; ADDITIONAL SECTION:
ns.liquidweb.com. 671 IN A 209.59.139.20
ns1.liquidweb.com. 806 IN A 64.91.251.155
The Additional Section provides any extra information that may be wanted but not specifically requested by dig. In this example, the Additional Section displays the IP addresses of the authoritative nameservers.
Another example of a common lookup using dig would be to look up the mx, mail exchange, record for a domain. Below is an example of a mx lookup for liquidweb.com.
$ dig mx liquidweb.com
; <<>> DiG 9.5.1-P2-RedHat-9.5.1-2.P2.fc10 <<>> mx liquidweb.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43051
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 4
;; QUESTION SECTION:
;liquidweb.com. IN MX
;; ANSWER SECTION:
liquidweb.com. 900 IN MX 5 mxgate-03.liquidweb.com.
liquidweb.com. 900 IN MX 10 backupmx.liquidweb.com.
;; AUTHORITY SECTION:
liquidweb.com. 396 IN NS ns.liquidweb.com.
liquidweb.com. 396 IN NS ns1.liquidweb.com.
both
;; ADDITIONAL SECTION:
mxgate-03.liquidweb.com. 900 IN A 209.59.139.131
backupmx.liquidweb.com. 900 IN A 209.59.139.28
ns.liquidweb.com. 363 IN A 209.59.139.20
ns1.liquidweb.com. 346 IN A 64.91.251.155</code
;; Query time: 3 msec
;; SERVER: 69.16.222.254#53(69.16.222.254)
;; WHEN: Wed Jun 10 10:58:25 2009
;; MSG SIZE rcvd: 181
The result of an MX query is fairly close to the same as the result of a standard dig. The only difference is how to interrupt the Answer Section.
;; ANSWER SECTION:
liquidweb.com. 900 IN MX 5 mxgate-03.liquidweb.com.
liquidweb.com. 900 IN MX 10 backupmx.liquidweb.com.
For MX, mail records, the answer will also include the priority of the mail server. The lower the number the higher the priority. In this example when a domain attempts to send mail to liquidweb.com it will attempt to send mail to mxgate-03.liquidweb.com first and if that attempt fails it will try to send to backupmx.liquidweb.com next.
===
Liquid Web’s Heroic Support is always available to assist customers with this or any other issue. If you need our assistance please contact us:
Toll Free 1.800.580.4985
International 517.322.0434
support@liquidweb.com
https://my.liquidweb.com/
Related Articles:

About the Author: J. Mays
As a previous contributor, JMays shares his insight with our Knowledge Base center. In our Knowledge Base, you'll be able to find how-to articles on Ubuntu, CentOS, Fedora and much more!
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
Best authentication practices for email senders
Read ArticleWhat is SDDC VMware?
Read Article2024 cPanel and Plesk pricing breakdown
Read ArticleCentOS Linux 7 EOL — everything you need to know
Read ArticleHow to install Node.js on Linux (AlmaLinux)
Read Article