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 tr Command: Translate and Delete Characters

Linux tr Command: Translate and Delete Characters

Learn how to translate and Delete Characters with the Linux tr command, including practical examples, key options, and important precautions.

Linux blkid Command: Find Block-Device UUIDs and Filesystem Types

Linux blkid Command: Find Block-Device UUIDs and Filesystem Types

Learn how to find Block-Device UUIDs and Filesystem Types with the Linux blkid command, including practical examples, key options, and important precautions.

Linux bzip2 Command: Compress a File in bzip2 Format

Linux bzip2 Command: Compress a File in bzip2 Format

Learn how to compress a File in bzip2 Format with the Linux bzip2 command, including practical examples, key options, and important precautions.

Linux shutdown Command: Schedule a Shutdown or Restart

Linux shutdown Command: Schedule a Shutdown or Restart

Learn how to schedule a Shutdown or Restart with the Linux shutdown command, including practical examples, key options, and important precautions.

Linux tmux Command: Detach and Reattach Terminal Sessions

Linux tmux Command: Detach and Reattach Terminal Sessions

Learn how to detach and Reattach Terminal Sessions with the Linux tmux command, including practical examples, key options, and important precautions.

Linux dirname Command: Extract the Directory Part of a Path

Linux dirname Command: Extract the Directory Part of a Path

Learn how to use the Linux dirname command to remove the final component of a path and return its directory portion, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux apropos Command: Search Commands by Description

Linux apropos Command: Search Commands by Description

Learn how to use the Linux apropos command to find relevant manual pages by searching description keywords, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux diff Command: Compare Text Files and Directories

Linux diff Command: Compare Text Files and Directories

Learn how Linux diff compares text files and directories, produces unified patches, ignores selected whitespace changes, and reports differences through exit status.

Linux mkfs Command: Create a New Filesystem

Linux mkfs Command: Create a New Filesystem

Learn how to create a New Filesystem with the Linux mkfs command, including practical examples, key options, and important precautions.

Linux mv Command: Move and Rename Files and Directories

Linux mv Command: Move and Rename Files and Directories

Learn how to move and rename files or directories with Linux mv, avoid unwanted overwrites, clarify destination paths, and handle cross-filesystem moves.