dig command

dig (stands for domain information groper) is a tool used to perform DNS lookups in Linux. It is known for its flexibility, ease of use and the clarity of its output. dig performs more complex DNS lookups than the host command and displays more detailed information.

Here is an example of using dig to find out DNS information about linux-bible.com:

linux dig command

As you can see from the picture above, the dig output consists of the following sections:

  • Header – displays the dig command version number, the global options used by the dig command, and some additional information.
  • Question section – displays the question it asked the DNS. By default, when you pass a domain name to the dig command, it displays the A record (the IP address).
  • Answer section – displays the answer received from the DNS. In this case, the IP address of linux-bible.com is displayed.
  • Authority section (not shown) – displays the DNS name server that has the authority to respond to this query.
  • Additional section (not shown) – displays the IP addresses of the name servers listed in the Authority section.
  • Stats section – displays few dig command statistics.

To display only the Answer section, use the +noall and +answer options:

linux dig answer section

To display MX records (the mail servers responsible for accepting email messages on behalf of a recipient’s domain), use the -t mx option:

linux dig mx

To display NS records (the name servers), use the -t ns option:

linux dig ns

To display all DNS record types, use the -t any option:

linux dig any

To perform a DNS reverse look up, use the -x option:

linux dig reverse dns lookup

Although usually used with the command-line arguments, dig also has a batch mode of operation for reading lookup requests from a file.
Geek University 2022