This tutorial is about the How to Use dig Command on Linux. We will try our best so that you understand this guide. I hope you like this blog How to Use dig Command on Linux. If your answer is yes then please do share after reading this.
Check How to Use dig Command on Linux
Dig (Domain Information Groper) is a command line utility that performs DNS lookups by querying name servers and showing you the result. This tutorial covers all the basic uses of the command that you should know in the Linux operating system. By default, dig sends the DNS request to the nameservers listed in the resolver (/etc/resolv.conf), unless a specific nameserver is requested.
Dig is part of the DNS utility package that is often installed with BIND name servers. You can also separately install the utility package that includes dig by accessing your VPS via SSH and using the following commands on the command line: The dig command in Linux is used to collect DNS information. It stands for Domain Information Groper and collects data through domain name servers. The dig command is useful for troubleshooting DNS problems, but it is also used to view DNS information.
Install dig on Linux (Optional)
Most modern Linux systems include the dig command. Verify that it is installed by checking the software version. To do this, open a command line and enter the following:
The system must respond with a numeric code. If the system cannot find the specified command, install dig by entering the following:
- sudo apt-get install dnsutils
Debian / Ubuntu:
- sudo apt-get install dnsutils
CentOS / RedHat:
- sudo yum install bind-utils
After the installation is complete, verify the installation with the following command:
dig syntax
The dig command is used as follows:
- dig
- – The hostname or IP address to which the query is directed
- – The DNS (Domain Name Server) of the server to consult
- – The type of DNS record to retrieve. By default (or if left blank), dig uses record type A
How to use the dig command with examples
Let’s look at the basic usage of the dig command.
DNS lookup
The dig command allows you to search for a domain name. To perform a DNS lookup, open terminal and type:
The most important section is the ANSWERS section:
- The first column lists the name of the server that was queried
- The second column is the time to live, a set period of time after which the record is updated
- The third column shows the query class; in this case, “IN” means Internet
- The fourth column shows the type of query; in this case, “A” represents an A (address) record.
- The final column shows the IP address associated with the domain name
The PSEUDOSECTION OPT displays advanced data:
- EDNS – Extension system for DNS, if used
- Flags: blank because flags were not specified
- UDP: UDP packet size
The QUESTION section shows the data of the query that was submitted:
- The first column is the domain name queried
- The second column is the type (IN = Internet) of query
- The third column specifies the record (A = Address), unless otherwise specified
The STATISTICS section shows metadata about the query:
- Query time: the amount of time it took for a response
- SERVER: the IP address and port of the responding DNS server. You might notice a loopback direction on this line: this
- refers to a locale that translates DNS addresses
- WHEN: timestamp when the command was executed
- MSG SIZE rcvd: the size of the DNS server response
Specify DNS server
By default, dig uses local settings to decide which nameserver to query. Use the following command to specify the Google domain server:
ANY option
To return all the results of the query, use the following:
Short answer option
To display only the IP address associated with the domain name, enter the following:
Detailed answer option
Run + noall + answer with the dig command to access detailed information in the answer section
- dig google.com + noall + answer
Tracking option
The + trace option lists each different server that the query passes through to its final destination. Use this command option to identify the IP address where the traffic falls.
DNS reverse lookup
To search for a domain name by its IP address, type the following:
Final words: How to Use dig Command on Linux
I hope you understand this article How to Use dig Command on Linux, if your answer is no then you can ask anything via contact forum section related to this article. And if your answer is yes then please share this article with your family and friends.