In this article, we want to teach you How To Work with the Dig Command on Linux.
Dig command stands for Domain Information Groper. It is represented by the BIND and used for recognizing the records and searching between DNS and Name servers.
This powerful tool is like the Nslookup command but with more facilities and features.
Dig tool can be used in Linux and Mac, you only need to install the BIND package and use it. Also, you can install and use it on Windows.
How To Install Dig on Linux
By default, the Dig tool is not available on Linux.
You can follow these steps to install it on the Linux distribution.
To install Dig on Centos / RHELL you can use the following command:
yum install -y bind-utils
You can use the following command to install Dig on Ubuntu / Debian:
apt install -y dnsutils
Work with the Dig Command on Linux
First of all, you need to know how to read the output of the dig command on Linux.
For example, run the following command with no parameters to get familiar with its output:
Output ; <<>> DiG 9.16.15-Debian <<>> microsoft.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- ;microsoft.com. IN A ;; ANSWER SECTION: microsoft.com. 1018 IN A 188.8.131.52 microsoft.com. 1018 IN A 184.108.40.206 microsoft.com. 1018 IN A 220.127.116.11 microsoft.com. 1018 IN A 18.104.22.168 microsoft.com. 1018 IN A 22.214.171.124 ;; Query time: 4 msec ;; SERVER: 126.96.36.199#53(188.8.131.52) ;; WHEN: Sun Oct 31 09:13:22 EDT 2021 ;; MSG SIZE rcvd: 122
Note: For a better understanding of the dig command output, we have changed the expressions to our liking in different colors.
The first two lines that are in orange color, represent the Dig version and output type.
In the Got answer section that is in the green color, you will see the information about the type of answer received from DNS. If you don’t need this you can use the no comment parameter at the end of the command.
In the third section which is in the purple color, the Dig command will show you the type of query that you have sent.
In the Answer section that is in the red color, you will see the desired output which is the domain IP address. Note that these lines are different for each domain.
Finally, in the last part which is in the blue color, you will receive some information about the amount of server response time and etc.
Let’s get familiar with the Dig parameters.
Parameters of the Dig Command on Linux
To get the answer from a specific record, you do not need to use a parameter and just follow the structure as shown below.
dig [hostname] [record type]
dig microsoft.com MX
With this command, Microsoft.com domain MX records will be displayed.
To remove the comments from the Dig command you can use the +short parameter:
dig microsoft.com +short
After entering the above command, only the IP or the answer of record A will be returned.
To request a query to a specific NS and get a response from it you can use the following command in this form:
dig @ns1.orcacore.com microsoft.com
In this way, dig will ask the DNS server ns1.orcacore.com about Microsoft.com.
After entering the +trace parameter, the Dig tool will show you the response with a diagram.
dig microsoft.com +trace
To return IP to the domain address you should use the -x parameter:
dig -x 192.168.1.10
With the above dig command, the name of the configured domain will display on this IP address.
If you need to receive the whole data about a domain and its number and types of records, you should use any parameter:
dig microsoft.com any
After entering this command, all the records that are registered in the DNS server for the Microdoft.com domain will be shown.
At this point, you learn to install the Dig tool on Linux. Also, you learn to read Dig’s output and get familiar with its parameters in this guide on the Linux Tutorials.
Hope you enjoy it.