The dig command in Linux (domain information groper) is a powerful and flexible tool for searching information on DNS name resolution servers. It is usually used to diagnose server configuration problems.
To install dig
On Debian and Ubuntu:
On CentOS 7:
When installing, check the version to ensure that the setup was successfully completed:
DIG syntax
In a simple way, the dig syntax will be:
[server] — the IP address or hostname of the DNS server to query. If the server argument is not provided, dig will use the address listed in /etc/resolv.conf.
[name] — the name of the resource record that should be searched. It can be a host or a domain.
[type] — the type of search requested by dig. For example: A, MX, or SOA record (see the list of DNS records), etc. By default, dig searches for an A record.
Examples of using dig
In this example, the dig returns the IP address corresponding to the certificacaolinux.com.br site, as well as which DNS server was responsible (authority) to answer the query:
Get record MX from a domain
The dig command can also be used to ask questions about specific records on the name server. In the example below, it will return only the MX type records from the domain certificacaolinux.com.br:
Get the most information from a domain with dig
The “any” option causes dig to try to obtain all the information for a given domain:
Specify the query server in dig
To specify the query server, you can also use the “@” option followed by the address of a DNS server:
To obtain summary information
The “+noall +answer +multiline” option can be used to obtain a summary version usable in for a DNS zone configuration file:
To obtain a registry address only:
The “+short” option summarizes the output of the dig command well:
You can specify the record type along with the +short option: