Skip to content

dns.computer

Tech Blog

  • Home
  • About me
  • Articles
  • Home
  • DNS records
  • Dig Command Explained for Beginners
Dig command

Dig Command Explained for Beginners

Posted on August 11, 2026September 1, 2026 By Beloslava Petrova No Comments on Dig Command Explained for Beginners
Commands, DNS, DNS records

The Dig command is a powerful DNS lookup tool that helps you find information about domain names, DNS records, nameservers, mail servers, and IP addresses. System administrators, developers, and network engineers often use it to troubleshoot DNS problems and verify that a domain is configured correctly.

If you are new to DNS, the output may look complicated at first. The good news is that the dig command becomes easy to understand once you know what each section means.

In this guide, you will learn what it is, how it works, and how to use it with practical examples.

What Is the Dig Command?

The dig command, short for Domain Information Groper, is a command-line tool used to query DNS servers.

When you enter a domain name such as example.com, dig sends a DNS query and displays the response returned by the DNS server.

You can use dig to check:

  • IP addresses
  • A records
  • AAAA records
  • MX records
  • TXT records
  • CNAME records
  • NS records
  • SOA records
  • Reverse DNS
  • DNS propagation
  • Specific DNS servers

Because dig shows detailed DNS information, it is especially useful when diagnosing domain and network problems.

How Does the Dig Command Work?

DNS (Domain Name System) translates human-readable domain names into information computers can use.

For example, when you visit a website, your device needs to discover the IP address associated with the domain.

The dig command lets you perform this lookup manually.

A basic query looks like this:

dig example.com

Your computer sends the request to the configured DNS resolver. The resolver looks up the domain and returns the DNS records it finds.

Dig then displays the response directly in your terminal.

How to Install Dig

Dig is available on most Linux and Unix-based systems, but some distributions do not install it by default.

On Ubuntu or Debian, you can install it with:

sudo apt install dnsutils

On CentOS, RHEL, or similar distributions, the package may be available through:

sudo yum install bind-utils

or:

sudo dnf install bind-utils

On macOS, dig usually comes preinstalled.

You can check whether it is available by running:

dig -v

If the command returns version information, dig is ready to use.

Basic Dig Command Syntax

The basic syntax is:

dig [domain] [record type]

For example:

dig example.com

By default, dig usually requests the domain’s A record, which points a hostname to an IPv4 address.

You can also specify the DNS record you want to query.

For example:

dig example.com MX

This requests the domain’s mail exchange records.

How to Check an A Record With Dig

An A record connects a domain name to an IPv4 address.

Run:

dig example.com A

Look for the ANSWER SECTION in the output.

You may see something similar to:

example.com. 300 IN A 93.184.216.34

The important part is the IP address at the end.

This tells you which IPv4 address the domain currently points to.

How to Check an AAAA Record

An AAAA record works like an A record but points to an IPv6 address.

Use:

dig example.com AAAA

If the domain has IPv6 configured, the response will contain an IPv6 address.

If the Answer section is empty, the domain may not have an AAAA record.

How to Check MX Records

MX records tell email systems where to deliver messages for a domain.

Run:

dig example.com MX

You may see several mail servers in the Answer section.

Each MX record also includes a priority value.

For example:

10 mail.example.com.

Lower numbers generally indicate higher priority.

MX lookups are useful when troubleshooting email delivery problems.

How to Check TXT Records

TXT records store text-based information in DNS.

They are commonly used for:

  • SPF
  • DKIM
  • DMARC
  • Domain verification
  • Email authentication
  • Security policies

To query TXT records, run:

dig example.com TXT

The returned values may contain verification strings or email security policies.

How to Check Nameservers

NS records identify the authoritative DNS servers for a domain.

Use:

dig example.com NS

The result shows which nameservers are responsible for answering DNS queries for that domain.

Checking NS records can help you verify whether a domain uses the correct DNS provider.

How to Check a CNAME Record

A CNAME record points one hostname to another hostname.

For example:

www.example.com

might point to:

example.com

To check it, run:

dig www.example.com CNAME

If a CNAME exists, dig displays the target hostname.

How to Get a Shorter Dig Response

The standard dig output includes a lot of technical information.

If you only want the result, add:

+short

For example:

dig example.com +short

This may return only the IP address.

You can combine +short with specific record types:

dig example.com MX +short

or:

dig example.com NS +short

This option is especially useful in scripts or when you need a quick DNS check.

How to Query a Specific DNS Server

Normally, dig uses the DNS resolver configured on your system.

You can query another DNS server by adding its address after the @ symbol.

For example:

dig @8.8.8.8 example.com

This sends the query to Google’s public DNS resolver.

Checking several DNS resolvers can help when investigating DNS propagation or caching problems.

How to Use Dig +trace

The +trace option shows the DNS resolution process step by step.

Run:

dig example.com +trace

Instead of asking a recursive DNS resolver for the final answer, dig follows the DNS hierarchy.

It starts with the root DNS servers, then queries the relevant top-level domain servers, and finally reaches the authoritative nameservers for the domain.

This makes +trace useful when you need to understand where DNS resolution is failing.

How to Perform a Reverse DNS Lookup

Reverse DNS performs the opposite of a normal lookup.

Instead of finding the IP address for a domain, it tries to find the hostname associated with an IP address.

Use:

dig -x 192.0.2.1

Dig queries the corresponding PTR record and displays the hostname if one exists.

Suggested to read: Differences between an A record and a PTR record

Reverse DNS checks are particularly useful for mail servers and network troubleshooting.

Understanding Dig Output

A typical dig response contains several sections.

Header

The header contains information about the DNS query and its status.

One important value is:

status: NOERROR

This means the DNS server successfully processed the request.

Other statuses can indicate problems.

Question Section

The Question section shows what dig asked the DNS server.

For example, it may show that you requested the A record for a particular domain.

Answer Section

The Answer section contains the actual DNS records returned by the server.

This is usually the most important part of the response.

Query Time

Dig also shows how long the DNS query took.

For example:

Query time: 20 msec

This can help when investigating slow DNS resolution.

Server

The Server line tells you which DNS resolver answered the query.

Dig command vs Nslookup command

Dig and nslookup both perform DNS queries, but dig generally provides more detailed output and more control over the request.

Nslookup can be easier for quick checks, especially for beginners. Dig is often more useful for advanced DNS troubleshooting because it clearly displays record types, response flags, TTL values, nameservers, and query details.

Both tools are useful, and learning how to use each one can make DNS troubleshooting much easier.

Why Use the Dig Command?

The dig command gives you direct insight into how DNS responds to a query.

You can use it to confirm DNS changes, check whether records exist, investigate incorrect nameservers, troubleshoot email problems, and verify DNS configuration.

It is especially useful when a website stops resolving after a DNS change or when different users receive different DNS results.

Instead of guessing what is wrong, dig lets you inspect the DNS response directly.

Conclusion

The dig command is one of the most useful tools for checking and troubleshooting DNS.

You can use it to inspect A, AAAA, MX, TXT, NS, CNAME, and other DNS records, query specific DNS servers, perform reverse lookups, and trace the DNS resolution process.

You do not need to memorize every option immediately. Start with simple commands.

Once you understand the basic output, dig becomes a fast and reliable way to investigate DNS problems and understand how a domain is configured.

Related posts:

What Is a DNS Resolver and How Does It Work?

September 10, 2026

How Split-Horizon DNS Works and When to Use It

September 10, 2026

What Is DNS TTL and Why Does It Matter?

September 1, 2026
author photo
Beloslava Petrova

Hi, I’m Bella, a technology enthusiast who enjoys making complex tech topics clear, practical, and easy to understand. Outside of writing, I love trail running, biking, traveling, and photography.

Tags: A record CNAME record command line dig command DNS DNS lookup DNS records DNS troubleshooting Linux commands MX record nameserver NS record Reverse DNS TXT record

Post navigation

❮ Previous Post: Why Use a VPN? Benefits, Risks, and Use Cases
Next Post: What Is VoIP? How It Works, Benefits and Key Features ❯

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • What Is a DNS Resolver and How Does It Work?
  • How Split-Horizon DNS Works and When to Use It
  • What Is DNS TTL and Why Does It Matter?
  • SS Command Guide for Beginners
  • DNS and AI: How Artificial Intelligence Is Changing Domain Name Systems

Recent Comments

No comments to show.

Categories

  • Cloud
  • Commands
  • DNS
  • DNS records
  • DNS services
  • Network
  • Security

Archives

  • September 2026
  • August 2026
  • July 2026
  • June 2022
  • March 2022
  • December 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • April 2021
  • March 2021
  • February 2021
dns.computer
Tech Blog about DNS, networking and cloud
  • Home
  • Articles
  • About me

Copyright © 2026 dns.computer.

Theme: Oceanly by ScriptsTown