In this tutorial, we will go through the process of how to properly use the DIG command in Linux.

What is Dig Command

The full form of DIG is Domain Information Groper, which is a fantastic command-line tool. Dig is used for querying the DNS name server to display complete details on mail exchanges, host addresses, and other related information. You can use this tool on different operating systems such as Linux and macOS. 

Many people use this tool to troubleshoot DNS-related issues due to its flexibility. This article will cover complete information on dig command with appropriate examples and every meticulous detail. 

How to install DIG on your system?

First, install a dig in your system or your Linux VPS by using the specific commands in the Linux terminal. 

If you want to install dig on Debian and Ubuntu, then use the below command: 

sudo apt update && sudo apt install dnsutils

For installing dig on Fedora and CentOS, then use the below command:

sudo yum install bind-utils

For installing dig on Arch Linux, then use the below command:

sudo pacman -S bind-tools 

How to check for the DIG command in Linux:

In case you want to check that the DNS dig command is available in your system, then use this command: 

dig -v 

Once you execute the command, the system will show the output like this: 

DiG 9.11.3-1ubuntu1.1-Ubuntu

What is the Dig Syntax?

So here is the simplest form of dig syntax: 

dig [server] [name] [type] 

In this syntax, [server] shows the IP address of a name server for querying. In case the server argument is a hostname, then you can solve the hostname before processing by querying a name server.  [name] consists of a name of a resource record that has to be looked up. [type] represents the type of query requested by the dig.

How to Use Dig Command

There are various ways to use the dg Linux command on any platform so we will cover all of the dig command's required details.

How to Perform Dig a Domain Name

If you want to use the DNS lookup for your domain name, use the following command:

dig 1gbits.com 

Dig command will get displayed as a record when there are no other options available by default. The output of this command will also show other details such as the dig version, statistics of the query, technical information of answers, and the question with other ones. 

To learn about how to flush DNS have a look here. Read more

This +short command will include some useful information about multiple sections but only use it when a result of a query is required. 

dig 1gbits.com +short 

You can use the command below in case you want to view a detailed answer section. This command line has +noall (stop displaying all of the sections) and +answer (used for querying answer sections). 

dig 1gbits.com +noall +answer

How to Specify Nameservers

Dig commands can query all of the name servers by default, and these nameservers are listed in /etc/resolv.conf for performing a DNS lookup for the user. If you want to change it, use @ symbol with the name server's IP address or hostname. 

dig @8.8.8.8 xyzdomaine.com 

This command will send a DNS query to the name server of Google (8.8.8.8) through the @8.8.8.8 option. 

How to Use Reverse DNS Lookup

Reverse DNS lookup is beneficial for looking up the domain as well as hostname related to the  IP address. If you want to use the reverse DNS lookup, put the –x option with the selected IP address as a dig command. For example, we are using an IP address 123.453.232.66, so the command will look like this: 

dig +answer -x 172.217.166.46

Note: If the IP address doesn't have a PTR record, you can't perform a DNS lookup. 

How to use Batch Queries

You can perform the DNS lookup for the domain’s list instead of performing the same for every domain individually. You have to give the dig with the domain name’s list in the dig command like this:

vi domain_name.txt

xyzdomaine.com

google.com

ubuntu.com

dig -f domain_name.txt +short

Conclusion

This article has complete information on the dig command tool covering the installation process and different ways how to use it. So as we have explained previously, the word DIG stands for domain Information Groper, and it is a fantastic command-line tool.  

To learn more about Linux commands, you can visit our previous blog. So we hope that our article will give you every single detail about dig commands for better understanding. 

People are also reading: