In our previous article, we have explained nslookup command examples and usage, which is a networking command-line tool used for querying and getting information of DNS (Domain Name System).
Here, in this article, we come up with another command line tool called dig, which is much similar to the Linux nslookup tool. We will see the usage of the dig command closely with their examples and usage.
[ You might also like: How to Install and Use dig and nslookup Commands in Linux ]
Dig stands for (Domain Information Groper) is a network administration command-line tool for querying Domain Name System (DNS) name servers.
It is useful for verifying and troubleshooting DNS problems and also to perform DNS lookups and displays the answers that are returned from the name server that was queried.
Dig is part of the BIND domain name server software suite. dig command replaces older tools such as nslookup and the host. dig tool is available in major Linux distributions.
1. Query Domain “A” Record
# <strong>dig yahoo.com</strong> ; > DiG 9.16.1-Ubuntu > yahoo.com ;; global options: cmd ;; Got answer: ;; ->>HEADER <p>The above command causes dig to look up the <code>"A"</code> record for the domain name <strong>yahoo.com</strong>. Dig command reads the <strong>/etc/resolv.conf</strong> file and querying the <strong>DNS</strong> servers listed there. The response from the<strong> DNS</strong> server is what dig displays.</p> <p>Let us understand the output of the commands:</p>
- Lines beginning with
;
are comments not part of the information. - The first line tells us the version of the dig (9.16.1) command.
- Next, dig shows the header of the response it received from the DNS server.
- Next comes the question section, which simply tells us the query, which in this case is a query for the
"A"
record of yahoo.com. TheIN
means this is an Internet lookup (in the Internet class). - The answer section tells us that yahoo.com has the IP address 98.137.11.163.
- Lastly, there are some stats about the query. You can turn off these stats using the
nostats
option.
2. Query Domain “A” Record with short
By default, dig is quite verbose. One way to cut down the output is to use the short
option. which will drastically cut the output as shown below.
<strong># dig yahoo.com short</strong> 98.137.11.164 74.6.231.21 74.6.231.20 74.6.143.25 74.6.143.26 98.137.11.163
Note: By default, dig looks for the "A"
record of the domain specified, but you can specify other records also. The MX
or Mail eXchange record tells mail servers how to route the email for the domain. Likewise TTL, SOA, etc.
3. Querying MX Record for Domain
Querying different types of DNS resource records only.
<strong># dig yahoo.com MX</strong> ; > DiG 9.16.1-Ubuntu > yahoo.com MX ;; global options: cmd ;; Got answer: ;; ->>HEADER <h4>4. Querying SOA Record for Domain</h4> <pre class="brush:php;toolbar:false"><strong># dig yahoo.com SOA</strong> ; > DiG 9.16.1-Ubuntu > yahoo.com SOA ;; global options: cmd ;; Got answer: ;; ->>HEADER <h4>5. Querying TTL Record for Domain</h4> <pre class="brush:php;toolbar:false"><strong># dig yahoo.com TTL</strong> ; > DiG 9.16.1-Ubuntu > yahoo.com TTL ;; global options: cmd ;; Got answer: ;; ->>HEADER>HEADER <h4>6. Querying Only Answer Section</h4> <pre class="brush:php;toolbar:false"><strong># dig yahoo.com nocomments noquestion noauthority noadditional nostats</strong> ; > DiG 9.16.1-Ubuntu > yahoo.com nocomments noquestion noauthority noadditional nostats ;; global options: cmd yahoo.com. 1556 IN A 74.6.231.20 yahoo.com. 1556 IN A 98.137.11.163 yahoo.com. 1556 IN A 98.137.11.164 yahoo.com. 1556 IN A 74.6.143.26 yahoo.com. 1556 IN A 74.6.231.21 yahoo.com. 1556 IN A 74.6.143.25
7. Querying ALL DNS Records Types
<strong># dig yahoo.com ANY noall answer</strong> ; > DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 > yahoo.com ANY noall answer ;; global options: cmd yahoo.com. 3509 IN A 72.30.38.140 yahoo.com. 3509 IN A 98.138.253.109 yahoo.com. 3509 IN A 98.139.183.24 yahoo.com. 1709 IN MX 1 mta5.am0.yahoodns.net. yahoo.com. 1709 IN MX 1 mta6.am0.yahoodns.net. yahoo.com. 1709 IN MX 1 mta7.am0.yahoodns.net. yahoo.com. 43109 IN NS ns2.yahoo.com. yahoo.com. 43109 IN NS ns8.yahoo.com. yahoo.com. 43109 IN NS ns3.yahoo.com. yahoo.com. 43109 IN NS ns1.yahoo.com. yahoo.com. 43109 IN NS ns4.yahoo.com. yahoo.com. 43109 IN NS ns5.yahoo.com. yahoo.com. 43109 IN NS ns6.yahoo.com.
8. DNS Reverse Look-up
Querying DNS Reverse Look-up. Only display answer section with using short.
<strong># dig -x 72.30.38.140 short</strong> ir1.fp.vip.sp2.yahoo.com.
9. Querying Multiple DNS Records
Query multiple website’s DNS specific query viz. MX, NS, etc. records.
<strong># dig yahoo.com mx noall answer redhat.com ns noall answer</strong> ; > DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 > yahoo.com mx noall answer redhat.com ns noall answer ;; global options: cmd yahoo.com. 1740 IN MX 1 mta6.am0.yahoodns.net. yahoo.com. 1740 IN MX 1 mta7.am0.yahoodns.net. yahoo.com. 1740 IN MX 1 mta5.am0.yahoodns.net. redhat.com. 132 IN NS ns1.redhat.com. redhat.com. 132 IN NS ns4.redhat.com. redhat.com. 132 IN NS ns3.redhat.com. redhat.com. 132 IN NS ns2.redhat.com.
10. Create .digrc file
Create .digrc file under $HOME/.digrc to store default dig options.
<strong># dig yahoo.com</strong> yahoo.com. 3427 IN A 72.30.38.140 yahoo.com. 3427 IN A 98.138.253.109 yahoo.com. 3427 IN A 98.139.183.24
We have store noall answer options permanently in the .digrc file under the user’s home directory. Now, whenever the dig command is executed it will show only answer section of the dig output. No Need to type every-time options like noall answer.
In this article, we tried to find out the dig command which may help you to search (DNS) Domain Name Service-related information. Share your thoughts through the comment box.
The above is the detailed content of 10 Dig (Domain Information Groper) Commands to Query DNS. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

While writing program files or normal text files, programmers and writers sometimes want to know the difference between two files or two versions of the same file. When you compare two computer files on Linux, the difference between their contents is

There are three ways to create empty files in the command line: First, the simplest and safest use of the touch command, which is suitable for debugging scripts or placeholder files; Second, it is quickly created through > redirection but will clear existing content, which is suitable for initializing log files; Third, use echo"> file name to create a file with an empty string, or use echo-n""> file name to avoid line breaks. These three methods have their own applicable scenarios, and choosing the right method can help you complete the task more efficiently.

Are you looking for good software to write mathematical equations? If so, this article provides the top 5 equation editors that you can easily install on your favorite Linux distribution.In addition to being compatible with different types of mathema

dutree is a free, open-source, fast command-line tool for analyzing disk usage, written in the Rust programming language. It was created by combining durep (disk usage reporter) and tree (list directory content in tree-like format) command-line tools

Eclipse is a free integrated development environment (IDE) that programmers around the world use to write software, primarily in Java, but also in other major programming languages using Eclipse plugins.The latest release of Eclipse IDE 2023?06 does

ifconfig in short “interface configuration” utility for system/network administration in Unix/Linux operating systems to configure, manage, and query network interface parameters via command-line interface or in a system configuration scripts

Linux administrators should be familiar with the command-line environment. Since GUI (Graphical User Interface) mode in Linux servers is not commonly installed.SSH may be the most popular protocol to enable Linux administrators to manage the servers

Linux has a rich collection of commands, and while many of them are powerful and useful for various tasks, there are also some funny and whimsical commands that you can try out for amusement. 1. sl Command (Steam Locomotive) You might be aware of the
