Home > Network Management > dig

dig: DNS Information Lookup Tool

dig (Domain Information Groper) is a command-line tool used to query Domain Name System (DNS) related information. It queries various DNS records, such as the IP address and MX records of a specific domain, and displays detailed response results. It is an essential tool for DNS troubleshooting and network management.

Overview

dig is a flexible and powerful tool that allows users to send direct queries to DNS servers to obtain information about domains. Unlike `nslookup` or `host`, dig provides very detailed response results, separated into sections. This allows for clear verification of various types of DNS information, such as a domain's A records, MX records, and CNAME records. It is primarily used to test the behavior of DNS servers or diagnose domain configuration errors.

Key Features

The main features of the `dig` command are as follows:

  • Can query specific DNS servers.
  • Can query various types of DNS records (A, AAAA, MX, CNAME, etc.).
  • Outputs detailed response results, divided into QUESTION, ANSWER, and AUTHORITY sections.
  • Provides performance-related information, such as DNS server latency.

Sections of dig Output

dig's output is composed of several sections, which helps in clearly understanding the information.

  • HEADER: Indicates basic information about the DNS query and response (ID, flags, etc.).
  • QUESTION SECTION: Shows the domain and record type queried by the user.
  • ANSWER SECTION: Contains the response information received from the DNS server. This includes the queried domain's IP address, etc.
  • AUTHORITY SECTION: Shows the name server (NS) information that has authority over the query.
  • ADDITIONAL SECTION: Provides additional information, such as the IP addresses of the name servers in the AUTHORITY SECTION.

Key Options

The main options of the `dig` command are grouped by purpose.

1) Query Options

2) Specify Record Type

3) Output Control

Generated command:

Try combining the commands.

Description:

`dig` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Learn the functionalities of the `dig` command through various usage examples.

Basic A Record Query

dig google.com

Queries the A record for `google.com`. By default, it outputs the most detailed information.

Query A Record with Specific DNS Server

dig @8.8.8.8 google.com

Queries the A record for `google.com` using Google's DNS server (`8.8.8.8`).

Concise A Record Query

dig +short google.com

Suppresses all additional information and outputs only the IP address concisely. Good for scripting.

Query Mail Server (MX) Record

dig gmail.com MX

Queries the mail server information for `gmail.com`.

Reverse IP Address Lookup

dig -x 8.8.8.8

Performs a reverse lookup to convert the IP address `8.8.8.8` to a domain name.

Installation

dig is part of the `bind-utils` or `dnsutils` package. It is typically pre-installed on most systems, but if not, you can install it using the following commands.

Debian/Ubuntu

sudo apt update
sudo apt install -y dnsutils

RHEL/CentOS/Fedora

sudo dnf install -y bind-utils

Arch Linux

sudo pacman -S --needed bind

Tips & Precautions

Here are some points to keep in mind when using the `dig` command.

Tips

  • The default output of dig is very detailed; if you only need simple information, it's best to use the `+short` option.
  • `nslookup` is no longer a recommended tool; it's better to use `dig` or `host` for DNS troubleshooting.
  • When specifying a DNS server, use the `@` symbol, and you can use either an IP address or a hostname (e.g., `ns1.google.com`).

Related commands

These are commands that are functionally similar or are commonly used together.


Same category commands