dig Command

The dig command is a flexible DNS lookup tool that queries DNS servers to resolve domain names and retrieve various types of DNS records. It's widely used for DNS troubleshooting and network diagnostics.

Syntax

dig [@server] [domain] [type] [options]

Description

The dig command performs DNS lookups and displays the results in a detailed format. It can query different types of DNS records and use specific DNS servers for queries.

Key features:

  • Query various DNS record types (A, AAAA, MX, NS, CNAME, etc.)
  • Perform reverse DNS lookups
  • Use specific DNS servers for queries
  • Trace DNS resolution path
  • Batch processing of multiple queries

Common Options

Option Description
+short Show only the answer section
+trace Trace the delegation path
+noall +answer Show only answer records
-x Reverse lookup (IP to domain)
-4 Use IPv4 only
-6 Use IPv6 only
-p port Use specific port number
-t type Query specific record type

Examples

Basic DNS lookup

dig google.com

Performs a basic DNS lookup for google.com

Short answer format

dig +short google.com

Shows only the IP address result

Query specific record type

dig google.com MX

Queries MX (mail exchange) records for google.com

Query NS records

dig google.com NS

Queries name server records

Query CNAME records

dig www.google.com CNAME

Queries canonical name records

Reverse DNS lookup

dig -x 8.8.8.8

Performs reverse lookup to find domain for IP address

Use specific DNS server

dig @8.8.8.8 google.com

Queries google.com using Google's DNS server

Trace DNS resolution

dig +trace google.com

Shows the complete DNS resolution path

Query all record types

dig google.com ANY

Attempts to retrieve all available record types

Query with clean output

dig +noall +answer google.com

Shows only the answer section without headers

See also