dig

From RaySoft

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.[1]

Documentation

Syntax

dig [@DNS-SERVER] [PARAMETER ...] NAME [TYPE] [CLASS] [QUERY ...]

Parameters

-4
This parameter indicates that only IPv4 should be used.
-6
This parameter indicates that only IPv6 should be used.
-p PORT
This parameter sends the query to a non-standard port on the server, instead of the default port 53.
-x ADDRESS
This parameter sets simplified reverse lookups, for mapping addresses to names. The ADDRESS is an IPv4 address in dotted-decimal notation, or a colon-delimited IPv6 address. When the -x parameter is used, there is no need to provide the NAME, CLASS, and TYPE arguments.

Queries

dig provides a number of queries which affect the way in which lookups are made and the results displayed. Some of these set or reset flag bits in the query header, some determine which sections of the answer get printed, and others determine the timeout and retry strategies.

+[no]additional
This option displays [or does not display] the additional section of a reply. The default is to display it.
+[no]all
This option sets or clears all display flags.
+[no]answer
This option displays [or does not display] the answer section of a reply. The default is to display it.
+[no]short
This option toggles whether a terse answer is provided. The default is to print the answer in a verbose form.

Examples

Get the mail servers (MX records) of a domain
dig 'raysoft.ch' 'MX'
Get the DNS servers (NS records) of a domain
dig 'raysoft.ch' 'NS'
Reverse lookup
dig -x '192.168.1.1'
Get the whole zone information
NOTE:
This must not be permitted!
dig 'raysoft.ch' 'AXFR'
Get the root zone
dig '@a.root-servers.net' >'root.hint'
Get the weather forecast
NOTE:
See DNS Toys for more information.
dig '@dns.toys' 'zurich/ch.weather' +noall +answer +additional +short

Output:

"Zurich (CH)" "22.30C (72.14F)" "59.70% hu." "fair_day" "13:00, Tue"
"Zurich (CH)" "23.70C (74.66F)" "50.00% hu." "fair_day" "15:00, Tue"
"Zurich (CH)" "24.50C (76.10F)" "44.00% hu." "clearsky_day" "17:00, Tue"
"Zurich (CH)" "24.00C (75.20F)" "44.80% hu." "clearsky_day" "19:00, Tue"
"Zurich (CH)" "22.10C (71.78F)" "45.60% hu." "fair_night" "21:00, Tue"
Get your external IP addresses
NOTE:
See DNS Toys for more information.
for version in 4 6; do
  dig "-${version}" '@dns.toys' 'ip' +noall +answer +additional +short
done

Output:

"130.59.196.161"
"2001:620:0:300e::11f"

References

  1. man 1 'dig'