Operations 10 min read

Mastering dig: Essential DNS Query Techniques and Options

This guide introduces the dig command, explains its basic usage, advanced options, query types, TCP mode, domain defaults, trace functionality, and output simplification, providing practical examples for effective DNS troubleshooting and analysis.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Mastering dig: Essential DNS Query Techniques and Options

Introduction

dig (Domain Information Groper) is a powerful DNS query tool favored by many network administrators for its flexible settings, clear output, and extensive functionality, offering an alternative to the more commonly used nslookup.

Basic Usage

The simplest way to use dig is to type dig and press Enter, which queries the root (".") for NS records using the default upstream DNS server.

Querying the Root Zone

Running dig without parameters returns the root zone’s NS records.

Adding a Dot

Appending a dot ( dig .) explicitly queries the root zone, producing similar output.

Specifying a DNS Server

To query a specific server, use the @dnsserver syntax, e.g., dig @8.8.8.8 www.baidu.com A, which requests the A record for www.baidu.com from Google’s DNS.

Command Format

The general syntax is: dig @dnsserver name querytype If @dnsserver is omitted, dig uses the servers listed in /etc/resolv.conf. The querytype can be A, AAAA, PTR, MX, ANY, etc., with A being the default.

Common Options

-c : Set the class (IN default, CH, HS).

-f : Read queries from a file for batch processing. Example:

cat querylist</code>
<code>www.baidu.com</code>
<code>www.sohu.com</code>
<code>dig -f querylist -c IN -t A

-4 and -6 : Force IPv4 or IPv6 transport.

-t : Specify query type (e.g., dig roclinux.cn -t MX).

-q : Explicitly set the query name, improving readability in complex commands.

-x : Perform a reverse lookup (IP to domain), e.g., dig -x 193.0.14.129.

Query Options (prefixed with +)

dig provides 42 query options that modify its behavior or output. Frequently used ones include:

+tcp : Use TCP instead of UDP, e.g., dig +tcp www.baidu.com.

+domain=somedomain : Append a default domain to queries.

+trace : Trace the resolution path from the root to the final answer, showing each step.

Concise Output

+nocmd : Suppress version and command info.

+short : Show only the essential answer (e.g., CNAME and A records).

+nocomment : Omit comment lines.

+nostat : Remove statistics at the end.

Combining these, e.g., dig +nocmd +nocomment +nostat www.baidu.com, yields a minimal result.

Next Steps

After mastering nslookup and dig, you can explore setting up your own internal DNS servers, configuring master/slave zones, adding forward and reverse zones, and tuning cache settings to deepen your DNS expertise.

Original article: http://roclinux.cn/?p=2449
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

network troubleshootingLinuxDNScommand-linedig
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.