How To Work with the Dig Command on Linux

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:

; <<>> DiG 9.16.15-Debian <<>>
;; global options: +cmd

;; Got answer:
;; ->>HEADER<<-

; IN A

;; ANSWER SECTION: 1018 IN A 1018 IN A 1018 IN A 1018 IN A 1018 IN A

;; Query time: 4 msec
;; 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]

For example:

dig MX

With this command, domain MX records will be displayed.

To remove the comments from the Dig command you can use the +short parameter:

dig +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:


In this way, dig will ask the DNS server about

After entering the +trace parameter, the Dig tool will show you the response with a diagram.

dig +trace

To return IP to the domain address you should use the -x parameter:

dig -x

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 any

After entering this command, all the records that are registered in the DNS server for the 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:

How To Manually Install Driver Module in Linux

Install and Use Traceroute Command in Linux

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!