The dig(1) (domain information groper) utility is a flexible
command-line tool that can be used to gather information from
Domain Name System (DNS) servers. The dig(1) utility has two
modes: simple interactive mode for a single query, and batch mode,
which executes a query for each in a list of several query lines.
All query options are accessible from the command line.
The usual simple use of dig(1) will take the form:
dig server domain query-type query-class
Can be either a domain name or a dot-notation Internet address.
If this optional field is omitted, dig(1) will attempt to
use the default name server for your computer.
If a domain name is specified, this will be resolved using the
DNS resolver (that is, BIND). If your system does not support DNS,
you may be required to specify a dot-notation address.
Alternatively, if there is a server at your disposal somewhere, you
need only ensure that /etc/resolv.conf be present and
indicate where the default name servers reside, so that
server itself can be resolved. See resolver(1)(5) for
information on /etc/resolv.conf.
Changing /etc/resolv.conf will affect both the standard
resolver library and possibly several programs that use it. As an
option, you can set the environment variable LOCALRES to name a
file which is to be used instead of /etc/resolv.conf.
(LOCALRES is specific to the dig(1) resolver and is not
referenced by the standard resolver.) If the LOCALRES variable is
not set, or the specified file is not readable,
/etc/resolv.conf will be used.
The domain name for which you are requesting information. See
the -x option (documented in the OTHER OPTIONS subsection of
this topic) for a convenient way to specify inverse address
The type of information (DNS query type) that you are
requesting. If omitted, the default is a (T_A = address.)
The following types are recognized:
All/any information about specified domain
Mail exchanger for the domain
Zone of authority record
Zone transfer (must ask an authoritative server)
Arbitrary number of strings
See RFC 1035 for the complete list.
The network class requested in the query. If omitted, the
default is in (C_IN = Internet.) The following classes are
Internet class domain
All/any class information
See RFC 1035 for the complete list.
Note that "Any" can be used to specify a class, a
type of query, or both. The dig(1) utility will parse
the first occurrence of "any" to mean query-type=T_ANY. To
specify query-class=C_ANY, either specify "any" twice, or
set query-class using the -c option (as described
The percent sign (%) includes an argument that is simply
not parsed. This may be useful if you are running dig(1) in
batch mode. Instead of resolving every @server-domain-name
in a list of queries, you can avoid the difficulties of doing so,
and still have the domain name on the command line as a reference.
An example follows:
dig @220.127.116.11 %venera.isi.edu mx isi.edu
The hyphen (-) specifies an option that affects the
operation of dig(1). The following options are currently
available (although they are not guaranteed to be useful):
Convenient form to specify inverse address mapping. Instead of
you can use:
dig -x 18.104.22.168
File for dig(1) batch mode. The file contains a list of
query specifications (dig(1) command lines) that are to be
executed successively. Lines beginning with ;, #, or
\n are ignored. Other options can still appear on the
command line, and will be in effect for each batch query.
Time, in seconds, between the start of successive queries when
running in batch mode. Use it to keep two or more batch
dig(1) commands running more or less synchronously. Default
Port number. Query a name server listening to a nonstandard
port number. Default is 53.
After query returns, execute a ping(1) command for
response-time comparison. This rather unelegantly makes a call to
the shell. The last three lines of statistics are printed for the
ping -s server_name 56 3
If the optional ping_string is present, it replaces
ping-s in the shell command.
Specify type of query. Can specify either an integer value to
be included in the type field, or use the abbreviated mnemonic as
discussed previously (that is, mx = T_MX).
Specify class of query. Can specify either an integer value to
be included in the class field, or use the abbreviated mnemonic as
discussed previously (that is, in = C_IN).
This flag specifies that the dig(1) environment
(defaults, print options, and so on), after all of the arguments
are parsed, should be saved to a file to become the default
environment. Useful if you do not like the standard set of defaults
and do not want to include a large number of options each time
dig(1) is used. The environment consists of resolver state
variable flags, time-out, and retries, as well as the flags
detailing dig(1) output (described later). If the shell
environment variable LOCALDEF is set to the name of a file, this is
where the default dig(1) environment is saved. If not, the
file DiG.env is created in the current working directory.
LOCALDEF is specific to the dig(1) resolver and will not
affect operation of the standard resolver library.
Each time dig(1) is executed, it looks for
./DiG.env or the file specified by the shell environment
variable LOCALDEF. If such a file exists and is readable, the
environment is restored from this file before any arguments are
This flag only affects batch-query runs. When -envset is
specified on a line in a dig(1) batch file, the
dig(1) environment after the arguments are parsed becomes
the default environment for the duration of the batch file, or
until the next line which specifies -envset.
-stick | -nostick
This flag only affects batch query runs. It specifies that the
dig(1) environment (as read initially or set by
-envset switch) is to be restored before each query (line)
in a dig(1) batch file. The default -nostick means
that the dig(1) environment does not stick, hence options
specified on a single line in a dig(1) batch file will
remain in effect for subsequent lines (that is, they are not
restored to the sticky default).
The plus sign (+) is used to specify an option to be
changed in the query packet, or to change dig(1) output
specifics. Many of these are the same parameters accepted by
nslookup(1). If an option requires a parameter, the form is
Most keywords can be abbreviated. Parsing of the + options is
very simplistic a value must not be separated from its keyword by
white space. The following keywords are currently available:
Turn on/off debugging mode [deb]
Use/do not use default domain name [def]
Authoritative query only flag [noaa]
Print TTLs [tt]
Print authoritative section [au]
The retry(1) and time(1) options affect the
retransmission strategy used by the resolver library when sending
datagram queries. The algorithm is as follows:
for i = 0 to retry - 1
g for j = 1 to num_servers
wait((time * (2**i)) / num_servers)
Note that dig(1) always uses a value of 1 for
The dig(1) utility once required a slightly modified version
of the BIND resolver(1) library. As of BIND 4.9, BIND's
resolver has been augmented to work properly with dig.(1)
Essentially, dig(1) is a straight-forward (albeit not
pretty) effort to parse arguments and set appropriate parameters.
The dig(1) utility uses resolver(1) routines as well
as accessing the _res structure.
The dig(1) utility has a serious case of "creeping
featurism" -- the result of considering several potential uses
during it's development. It would probably benefit from a rigorous
review. Similarly, the print flags and granularity of the items
they specify make evident their rather ad hoc genesis.
The dig(1) utility does not consistently exit nicely
(with appropriate status) when a problem occurs somewhere in the
resolver (Most of the common exit cases are handled.) This is
particularly annoying when running in batch mode. If it exits
abnormally (and this is not detected), the entire batch aborts;
when such an event is trapped, dig(1) simply continues with
the next query.