We can use dig command to query various dns servers to fetch records like address record, CNAME, TXT, Mail exchange records etc… I also found an useful website showmydns.net to search dns records from multiple locations world wide. This guide explains you to how to use Linux dig command line utility with practical examples.

dig Command in Linux

The dig utility is available under default repositories on most of the Unix/Linux operating systems. On Debian based systems dig command is available under dnsutils package. The Redhat based systems dig command is available under bind-utils rpm package. Syntax: A basic and frequently used dig command syntax is like below: Dig Version: Use -v option with dig command to display version of dig on your system.

Dig Command Line Options and Examples

Here is the frequently used command line options and example’s of dig command.

1. Basic Dig Command

A basic dig command accept domain name as command line parameter and prints Address record. Output: In the result ANSWER SECTION: contains the main information you have requested. You can ignore other parts of the output which have other details about query you made.

2. Query With Specific DNS Server

The default dig command queries to dns server configured on your system. For example, the Linux systems keep default DNS entry in /etc/resolv.conf. You can overwrite the default DNS to query by passing the DNS server as an command line parameter. The DNS IP must be start with @ symbol.

3. Print Short Answer

Use +short command line option to print result in short form. This is basically useful with the shell scripting and other automation tasks.

4. Print Detailed but Specific Result

Use +noall with +answer to print detailed information but specific. This will print only answer section including few more details as a result. You can also specify +nocmd option after dig command to print more specific answer section only.

How to Search Specific Records with dig Command

Next, query the specific DNS records with dig command.

Set Options As Default

In the above tutorial, you have used multiple command line options to customize results like +nocmd, +noall, +answer etc. But you have to write options on command line every time. You can also create a .digrc file in home directory to auto apply each time your make dig query. The next time you run dig will default use above specified options. Output:

Conclusion

In this tutorial, you have learned the uses of dig command with various options and examples. You can also try web applications like showmydns.net to query dns records from multiple locations world wide. which is useful to check dns propagation while adding or updating dns records.