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 used for recognizing the records and searching between DNS and Name servers. Dig is a powerful tool like Nslookup, but it has more features.
You only need to install the BIND package and use the Dig command.
How To Work with the Dig Command on Linux?
To start working with the Dig command, you must have access to your server as a root or non-root user with sudo privileges and install Dig on your server.
Step 1 – How To Install Dig on Linux?
By default, the Dig tool is not available on Linux distros.
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
Step 2 – How To Use Dig Command with Examples?
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:
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 18.104.22.168 microsoft.com. 1018 IN A 22.214.171.124 microsoft.com. 1018 IN A 126.96.36.199 microsoft.com. 1018 IN A 188.8.131.52 microsoft.com. 1018 IN A 184.108.40.206 ;; Query time: 4 msec ;; SERVER: 220.127.116.11#53(18.104.22.168) ;; WHEN: Sun Oct 31 09:13:22 EDT 2021 ;; MSG SIZE rcvd: 122
Note: To understand better the results, we change the colors.
The first two lines which are in orange color, display the Dig version and output type.
In the Got Answer section which 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 which 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.
Now you can proceed to the next step to understand the Dig parameters.
Step 3 – Dig Command Usage 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 shown.
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.
That’s it you are done. If you learn these useful parameters, you can easily work with the Dig tool on your Linux system.
At this point, you have learned to install the Dig tool on Linux. Also, you have learned to read Dig’s output and get familiar with its parameters in this guide on Linux Tutorials.
Hope you enjoy it. You may be interested in these articles: