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

; <<>> 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: 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]

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 returned.

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.


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.


Please enter your comment!
Please enter your name here

Latest Articles


Most Popular