Dig is a DNS lookup utility. If it’s not installed on your system, you can find it as part of dnsutils on Debian-based package managers and bind-utils on Fedora, CentOS, and Arch.
The dig command is used to query DNS servers; it is more flexible than the deprecated nslookup command. When invoked with just the -h option, it displays a list of options for the command. If you use it without any options or arguments, it will search for the root server.
The standard arguments are:
- server: The server to query. If no server is supplied, dig will check thenameservers listed in /etc/resolv.conf. The address may be anIPv4 dotted address or an IPv6 colon-delimited address. It mayalso be a hostname, which dig will resolve (through thenameservers in /etc/resolv.conf).
- name: The domain name to look up.
- type: The type of query to perform, such as A, ANY, MX, SIG, andso forth. The default is A, but you may use any valid BIND9 query type.
The format of the command is demonstrated here:
# dig google.com ; <<>> DiG 9.9.4-RedHat-9.9.4-38.el7_3 <<>> google.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER
To query a specific DNS server, rather than the default DNS servers for your host, use the following syntax:
# dig @server host_to_lookup
dig Command Examples
1. To dig into any domain name server:
# dig centos.com
2. To hide any particular section from the output:
# dig centos.com +noanswer # dig centos.com +noadditional # dig centos.com +nostats # dig centos.com +noauthority # dig centos.com +nocomments
3. To query all types of records:
# dig centos.com -t ANY
4. To query MX records (Mail Exchanger records):
# dig centos.com MX # dig centos.com -t MX
5. To query SIG records (Signature Records):
# dig centos.com -t SIG
6. To query NS records (Name server records):
# dig centos.com -t NS
7. To query TXT records (Text records):
# dig centos.com -t TXT
8. To see the summarized output:
# dig centos.com +short
9. To do the reverse DNS lookup of the server:
# dig -x centos.com
10. Perform iterative queries and display the entire trace path to resolve a domain name:
# dig +trace example.com
11. Find authoritative name servers for the zone and display SOA records:
# dig +nssearch example.com
12. Query a specific DNS record type associated with a given domain name:
# dig +short example.com A|MX|TXT|CNAME|NS
13. Lookup the IP(s) associated with a hostname (A records):
# dig +short example.com
14. Get a detailed answer for a given domain (A records):
# dig +noall +answer example.com