Introduction
The dig
(Domain Information Groper) command is a DNS lookup utility. It’s often used by system and network administrators to collect Domain Name Server information. Apart from collecting data, the dig
command is a useful tool for network troubleshooting and solving DNS issues.
You can use this DNS testing tool on Linux, Mac OS, and Windows. While most newer distros have dig pre-installed, you could find yourself needing to do this.
In this tutorial, learn how to install dig on your CentOS and some basic dig commands.
Prerequisites
- A Linux system with CentOS
- A user account with sudo or root privileges
- Access to a terminal window/command line
Note: If you are looking for instructions for Windows, refer to our post How to Install Dig on Windows.
How to Install dig on CentOS
If dig is unavailable on your RHEL/CentOS Linux system, you can install it using one simple command:
sudo yum install bind-utils
Or:
sudo dnf install bind-utils
The command installs the bind-utils package, a collection of utilities that include dig and other DNS querying.
Note: Want to learn more about Domain Name Systems? Take a look at what DNS is, how it works, and why it is important to flush DNS cache.
Check dig Version
To verify you have successfully installed dig, prompt the system to display the version of dig on the system:
dig -v
If dig is available, it shows the utility’s version number, as in the image below.
If you don’t have dig, the output responds with the message: dig command not found
.
Basic dig Command CentOS Examples
Below you can find some of the most common dig
commands and examples showing how they work.
Check DNS Record for a Specific Domain
To check the DNS record for a specific domain, run the command:
dig [domain_name]
For example:
dig phoenixnap.com
The output should display the following information:
- the version of the
dig
command - technical information provided by the DNS nameserver
- the QUESTION section
- and the ANSWER section (the IP address)
By default, you are requesting the A record (the record that points your hostname to an IP address).
Check IP Address
If you want to see just the IP address (the answer section), run:
dig [domain_name] +short
The output gives you the IP address for the specified domain, without the additional information.
Check MX Record
You can use the dig
command to find the domain’s MX (Mail Exchange) records. To display the MX records, use:
dig [domain_name] MX
To display just the mail server, without the additional information, add the +short
option:
dig [domain_name] MX +short
Check SOA Record
To find the authoritative DNS server, use the dig
command to display the SOA (Start of Authority) record. This information tells you core information and parameters for your DNS zone.
Use the utility to display the detailed SOA record by running:
dig [domain_name] SOA
Alternatively, add the +short
option for the concise output:
dig [domain_name] SOA
Note: For more dig
commands, refer to the article How to Use the Linux dig Command.
Conclusion
After reading this tutorial, you should have dig installed on CentOS. Additionally, you should know some basic dig
commands and how to use them.