opened image

Linux dig command - usage and examples.

In today's technology world, networks play a critical role. Communication and access to resources on the Internet requires knowledge of how domain names work and the DNS resolution process. The `dig` command (Domain Information Groper) is an indispensable tool for working with DNS on the Linux platform. In this article, we will look at what the `dig` command is, how to use it, and give practical examples of its use.

An overview of the dig command.

 

The `dig` command is a command line utility for querying DNS servers. It can retrieve various information about domain names, such as IP addresses, MX records (for email), NS records (name server names), and more. It is a powerful tool for diagnosing network problems, checking DNS settings, and general analysis of domain names.

Using the `dig` command

 

The syntax for the `dig` command is as follows:

dig [key] [domain] [dns-record]

Where:

- `key` are additional options to customize the request.
- `domain` is the name of the domain for which the request will be made.
- `dns-record` is the type of DNS record you want to retrieve (A, MX, NS, etc.).

 

Examples of using the `dig` command.

 

1. Obtaining an IP address from a domain name:

dig google.com A

 

    This query will return the IP addresses for the google.com domain. Result of command execution:

 

 

2. Getting MX records for the mail domain:

  dig example.com MX

Where instead of example.com, specify the domain you need, for example google.com. The query will return information about the mail servers responsible for delivering mail on the specified domain.

 

 

    You can, for the convenience of reading the data output, use the additional key "+short". This will reduce the output of non-essential information, and make a short output with important data.

 

3. Getting the names of the name servers for the domain.

dig yahoo.com

  This query will return a list of nameservers responsible for the specified domain, such as yahoo.com.

 

4. Checking the availability and correctness of domain DNS records on DNS servers.

dig @8.8.8.8 google.com

    This query will send a query to the Google DNS server with the IP address 8.8.8.8 and return the IP address information for the google.com domain. For verification, you can use:

This command is useful when changing your domain's DNS records. In particular, after changing the A-record or MX-records in DNS hosting. Allows you to check whether the DNS records you specified have changed on the DNS server. And check how quickly these DNS records appear after updating on Google's DNS servers. Because DNS records are updated from an hour to 24 hours on other DNS servers (third-party companies or resources).

Results

The `dig` command is a powerful and interesting tool for manipulating DNS queries and diagnosing network problems. With it, you can get various DNS records, analyze DNS server settings, and check domain availability. Understanding the use of `dig` can greatly facilitate network administration and DNS-related problems.

​We also suggest you other useful articles: