CAll Us: (855)11/12 98 98 45 | 81 25 25 18



dig is a command-line tool for querying DNS name servers for information about host addresses, mail exchanges, name servers, and related information. The dig(1) man page is somewhat lacking when it comes to examples, a shortcoming this article tries to remedy.

The source code for dig is part of the larger ISC BIND distribution. Compiling and installing BIND are topics outside the scope of this document, but on Linux systems dig is usually part of a common package: bind-tools (Gentoo), bind-utils (Red Hat, Fedora), or dnsutils (Debian).

Understanding the default output

The most typical, 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 annotated query.

$ dig

That’s the command-line invocation of dig I used.
; <<>> DiG 9.2.3 <<>>
;; global options:printcmd

The opening section of dig’s output tells us a little about itself (version 9.2.3) and the global options that are set (in this case, printcmd). This part of the output can be quelled by using the +nocmd option, but only if it’s the very first argument on the command line (even preceeding the host you’re querying).
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43071
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 3
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.



In the question section, dig reminds us of our query. The default query is for an Internet address (A). You can turn this output on or off using the +[no]question option.


Finally, we get our answer: the address of is I don’t know why you’d ever want to turn off the answer, but you can toggle this section of the output using the
+[no]answer option.


The authority section tells us what DNS servers can provide an authoritative answer to our query. In this example, has three name servers. You can toggle this section of the output using the +[no]authority option.

;; ADDITIONAL SECTION: 171551INA 2351INA 2351INAAAA2001:4f8:0:2::15

The additional section typically includes the IP addresses of the DNS servers listed in the authority section. This section of the output can be toggled with the +[no]additional option.

;; Query time: 2046 msec
;; WHEN: Fri Aug 27 08:22:26 2004
;; MSG SIZErcvd: 173

The final section of the default output contains statistics about the query; it can be toggled with the +[no]stats option.

What can I discover?
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), NS name servers, or the omnibus ANY.

# get the address(es) for
dig A +noall +answer
# get a list of yahoo’s mail servers
dig MX +noall +answer
# get a list of DNS servers authoritative for
dig NS +noall +answer
# get all of the above
dig ANY +noall +answer

More obscurely, for the present anyway, you can also poll for a host’s IPv6 address using the AAAA option.

dig AAAA +short

If the domain you want to query allows DNS transfers, you can get those, too. The reality of life on the Internet, however, is that very few domains allow unrestricted transfers these days.

dig AXFR How do I …
Get a short answer?

When all you want is a quick answer, the +short option is your friend:

$ dig +short


Get a not-quite-so-short answer?


Note that a short answer is different from only an answer. The way to get a detailed answer, but without any auxiliary information, is to turn off all the results (+noall) and then turn on only those sections you want.
Here’s a short answer followed by only an answer; the latter includes all the configuration information, including time-to-live (TTL) data, displayed in a format compatible with BIND configuration files.


$ dig mx +short


$ dig +nocmd mx +noall +answer

Get a long answer?


According to its man page, the +multiline option will give you an answer with “the SOA records in a verbose multi-line format with human-readable comments.” In general, the answers retrieved using the +multiline option will appear more like BIND config files than they will without it.

$ dig +nocmd any +multiline +noall +answer 14267 IN A 14267 IN MX 5 14267 IN MX 15 14267 IN SOA (
200408230; serial
14400; refresh (4 hours)
900; retry (15 minutes)
3600000; expire (5 weeks 6 days 16 hours)
14400; minimum (4 hours)
) 14267 IN NS 14267 IN NS 14267 IN NS


Do a reverse lookup?


Use the -x option to lookup the main hostname associated with an IP address.

$ dig -x +short

Query a different nameserver?

Just specify it on the command line:


Use the search list in /etc/resolv.conf?

The host utility will automatically use the search list in your /etc/resolv.conf file.

$ host www has address

By default, however, dig doesn’t—which may produce some unexpected results. If you want to use local hostnames instead of fully qualified domain names, use the +search option.