Cantech Knowledge Base

Your Go-To Hosting Resource

How to Lookup DNS Records with dig CLI Tool?

Domain Name System (DNS) is an integral part of the internet that converts user-friendly domain names, like example.com, into machine-readable IP addresses. Admins and developers use the dig command-line tool (Domain Information Groper) to query DNS records and troubleshoot problems with domains.

Dig is an exceptionally powerful utility used to pull information from DNS, such as A records (IPv4 address), MX records (mail servers), NS records (name server), and many others. Knowing how to utilize dig correctly can not only help diagnose DNS problems but can also assist in verifying domain configurations and ultimately improve overall network management.

Here is a guide on how to use the dig command syntax, common cases, and troubleshooting techniques!

How to Install Dig?

Most Linux distributions and macOS come with dig pre-installed as part of the dnsutils package.
To check if dig is installed, run:

dig -v

If it is not installed, you can install it accordingly:
Ubuntu and Debian: sudo apt install dnsutils
CentOS and RHEL: sudo yum install bind-utils
macOS (via Homebrew): brew install bind

Basic Syntax of dig

The syntax of dig is dig [options] [domain] [record type]

[options] – Additional options that modify the behavior of the command.
[domain] – The domain name you want to inquire about.
[record type] – The specific type of DNS records you want to obtain (for example A, MX, NS, TXT).

List of Commonly Used Dig Queries

Some of the most commonly used dig queries are listed below. Let’s have a glance at them!

1. Querying an A Record (an IPv4 Address)

For determining an IPv4 address of a domain.

dig example.com A

2. Querying an AAAA Record (an IPv6 Address)

To identify an IPv6 address, run the following command.

dig example.com AAAA

3. Querying NS Records (the Name Servers)

To get a list of authoritative name servers for a domain.

dig example.com NS

4. Querying MX Records (the Mail Exchange)

To find mail servers for a domain.

dig example.com MX

5. Querying TXT Records (the Text Records)

To obtain text records frequently used for SPF, DKIM, or verification purposes.

dig example.com TXT

6. Querying CNAME Records (the Canonical Name)

To determine if a domain is an alias for another domain.

dig www.example.com CNAME

7. Querying SOA Records (the Start of Authority)

To retrieve administrative details regarding a domain.

dig example.com SOA

8. Querying All DNS Records

To retrieve all known records for a domain.

dig example.com ANY

Perform DNS Lookup Using the Advanced Dig Usage

Ensure that the advanced dig commands are used to test and perform the DNS Lookup. Let’s explore them!

1. Reverse DNS Lookup

It will display the domain name that is associated with the required IP address.

dig -x 8.8.8.8

2. Specific DNS Server Query

To query a domain using a specific DNS server.

dig @8.8.8.8 example.com

3. Showcase Short Answer Only

To get a precise output, only the answer must be displayed.

dig example.com +short

4. Detailed Output

Verbose output with additional technical details.

dig example.com +noall +answer

5. Querying DNSSEC Information

To cross-verify, if a domain supports DNSSEC.

dig example.com DNSKEY

Troubleshooting DNS-related Issues

1. Domain name is not resolving.

Reason: Either the DNS settings are incorrect, or the domain might not exist.
Solution: Make sure the domain is correct and try to query a different DNS server.

2. High Response Time

Reason: Bad DNS will slow down resolution time, usually because of congested networks.
Solution: Use a fast DNS resolver like 1.1.1.1 or 8.8.8.8.

3. No answer in response

Reason: A couple of DNS servers actually restrict queries.
Solution: Try to query the authoritative name server using dig @ns1.example.com example.com.

Conclusion

The dig command is a great tool for querying DNS records and analyzing problems related to domains. Troubleshooting web outages, checking domain setups, or learning about how DNS really works, dig offers details that provide you insight into the DNS resolution process. With knowledge of customizable commands and the different options available, your efforts to manage and diagnose domain-related problems more effectively will increase.

To learn more commands, see Manual:

man dig

Thanks for reading!

Frequently Asked Questions

What is the Dig for?
A command-line tool for querying DNS records and troubleshooting domain-related problems.

How do I install dig on Linux?
You would do this either by sudo apt install dnsutils on Debian-based systems by sudo yum install bind-utils on RHEL-based systems.

How do I find mail servers for a domain?
Use dig example.com MX to get the mail exchange (MX) records for your domain.

What does the -x flag do in Dig?
It performs a reverse DNS lookup, mapping an IP address to a domain name.

How do I obtain a short answer from Dig?
By using the +short option: dig example.com +short.

March 17, 2025