Linux dig Command: Query DNS Records in Detail

dig queries DNS servers and shows detailed information about records such as A, AAAA, MX, TXT, and response status. It is used to diagnose name resolution issues or compare answers from specific DNS servers.

What is the dig command?

The default query is usually an A record, and the results are read separately in the ANSWER SECTION and status. +short shows only a simplified result, which may lose context such as status, authority, and TTL. DNS responses may vary depending on caching and the server used.

Basic syntax

dig [@DNS server] name [record type] [option]

The installed implementation and options may vary depending on the distribution. Check the description for the current system with man dig.

Examples

Checking A records

Look at the domain's IPv4 address and response status.

dig example.com A

Checking mail server records

Check the priority and host of MX records.

dig example.com MX

View only brief answers

Can be used for scripts or quick checks, but diagnostic information is reduced.

dig +short example.com A

Reading Each Field of a DNS Response

dig shows DNS (Domain Name System) queries in detail. +noall +answer keeps only the answer section, making it easier to see the record name, TTL, class, type, and value.

dig +noall +answer example.com A

Example output format (IP and TTL may differ from the actual response):

example.com. 300 IN A 192.0.2.10

300 is the TTL in seconds, IN is the Internet class, and A is the IPv4 address record. If there is no answer, check the query status (such as NXDOMAIN), the queried server, and the record type. When comparing responses from multiple DNS servers, specify @server_address.

Main Options and Format

Options/Format Description
@server Specifies the DNS server to query.
A / AAAA / MX / TXT Specifies the type of record to query.
+short Outputs only short answers.
+noall +answer Outputs centered on the answer section.
-x address Performs a reverse DNS query.
+trace Queries along the delegation path.

Precautions when using

Even if the +short result is empty, you cannot distinguish between NXDOMAIN, NODATA, server errors, or timeouts, so check the status of the full response. dig queries DNS directly and may differ from the application's full name resolution path. Check /etc/hosts or local cache issues separately.

Frequently Asked Questions

Why are dig results different from browser access results?

dig shows the record response from the selected DNS server, but browsers may use local cache, proxies, /etc/hosts, or other resolution paths.

Official Documentation

For the exact behavior of options and implementation differences, refer to the official dig documentation.

More in This Category
Linux timedatectl Command: Check Time Zone and Time Synchronization

Linux timedatectl Command: Check Time Zone and Time Synchronization

Learn how to check Time Zone and Time Synchronization with the Linux timedatectl command, including practical examples, key options, and important precautions.

Linux printf Command: Print Values with a Defined Format

Linux printf Command: Print Values with a Defined Format

Learn how to print Values with a Defined Format with the Linux printf command, including practical examples, key options, and important precautions.

Bash Command Operators Explained: ;, &&, ||, &, and |

Bash Command Operators Explained: ;, &&, ||, &, and |

Understand how Bash operators run commands sequentially, conditionally, in the background, or through pipelines, with practical examples and precedence guidance.

Linux help Command: Read Help for Bash Built-in Commands

Linux help Command: Read Help for Bash Built-in Commands

Learn how to use the Linux help command to read usage information for Bash built-in commands, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux chmod Command: Change File and Directory Permissions

Linux chmod Command: Change File and Directory Permissions

Learn how to change File and Directory Permissions with the Linux chmod command, including practical examples, key options, and important precautions.

Linux nslookup Command: Query DNS Names and Records

Linux nslookup Command: Query DNS Names and Records

Learn how to query DNS Names and Records with the Linux nslookup command, including practical examples, key options, and important precautions.

Linux dnf Command: Manage RPM Distribution Packages

Linux dnf Command: Manage RPM Distribution Packages

Learn how to manage RPM Distribution Packages with the Linux dnf command, including practical examples, key options, and important precautions.

Linux mount Command: Inspect and Mount Filesystems

Linux mount Command: Inspect and Mount Filesystems

Learn how to inspect and Mount Filesystems with the Linux mount command, including practical examples, key options, and important precautions.

Linux unzip Command: List and Extract ZIP Archives

Linux unzip Command: List and Extract ZIP Archives

Learn how to list and Extract ZIP Archives with the Linux unzip command, including practical examples, key options, and important precautions.

Linux umount Command: Unmount a Filesystem Safely

Linux umount Command: Unmount a Filesystem Safely

Learn how to unmount a Filesystem Safely with the Linux umount command, including practical examples, key options, and important precautions.