Casbay Knowledge Base

Search our articles or browse by category below

Basic Dig Command Guide in Linux Based VPS

Last modified: October 1, 2022
Estimated reading time: 2 min

Dig, which also stands for “Domain Information Groper”,  is a Linux command-line application that does DNS lookups by querying name servers and showing the results to you. Unless a specific name server is requested, dig delivers DNS queries to name servers listed in the resolver(/etc/resolv.conf) by default. In this tutorial, you will be able to learn all the basic uses of the dig command to assist you in managing your Linux based VPS.

Dig Command Syntax

Access your VPS before starting any of the commands in this guide. The following command is a basic dig command syntax.

dig <server> <record_name> <type>

The “<server>” in the command refers to the IP address or the hostname of the server for queries. The “<record_name>” refers to the name of the resource record that is being looked up. The “<type>” in the command refers to the type of query.

Basic Dig Command on Domain Name

Run the following command to perform a DNS lookup for a domain name.

dig casbay.com

The dig command will display the A record by default as no other options were added. It also shows more information regarding statistics of the query, the version of dig installed, and so on.

Short Option

To only display the result of the query, you may use the “+short” option, such as the following command.

dig casbay.com +short

This command above will only display the IP address of the domain.

Retrieving More Detailed Information

To be able to get detailed information, you may use the “+noall” option to stop displaying all the sections regarding the unrelated information of the domain and add the “+answer” option to query the answers section such as shown in the following command.

dig casbay.com +noall +answer

Specify Server Names

Dig commands will query the servers that are listed in the file “/etc/resolv.conf” by default to help you search for a DNS. You may change the default DNS query by adding the “@” symbol such as the following command.

dig @8.8.8.8 casbay.com

8.8.8.8 is Google’s server name and the command above sends the DNS query to the Google server.

Query All DNS Record

Use the “ANY” option to query for all available DNS records of a domain such as the following command.

dig casbay.com ANY

Specific Record

Add the record type at the end of the command for looking up a specific record type such as the following examples.

dig casbay.com MX
dig casbay.com txt
dig casbay.com A

“MX” refers to the mail exchange record, “txt” refers to text record, and “A” refers to A record.

DNS Path

You may also look at the DNS lookup path with the “+trace” option. It will make repetitive queries all the way to the server starting from the root. To trace the DNS path, run the following command.

dig casbay.com +trace

Reverse Search

Use the “-x”  to perform a reverse search with an IP address. The following command will make a reverse DNS lookup with a Google associated IP address

dig +answer -x 172.217.166.46

Multiple Queries

To run multiple queries for a list of domains, first, create a file using the following command.

nano domains.txt

Then add your list of domains into the following text file such as shown below.

domain1.com
domain2.com
domain3.com
domain4.com

Make save changes and exit the domains.txt file. To perform the queries for all the domains listed, run the following command.

dig -f domains.txt +short

Customize the Dig Option

You can customize the dig command options by setting them in the “`/.digrc” file. For example, to run the “+noall” and “+answer” options by default, specify them in the “~/.digrc” file as shown below.

echo "+noall +answer" > ~/.digrc

Now run a dig command without the options added in the file earlier, and you should still be able to see a similar output as the specified options.

Was this article helpful?
Dislike 0
Previous: Linux VPS Server Guide on Killing a Process