---
title: "Linux Dig for Network Admins: Practical Guide with Examples"
description: "Become a network troubleshooting expert! This comprehensive Linux Dig guide empowers you with essential DNS query commands for immediate results."
canonical: "https://adamtheautomator.com/linux-dig/"
---

# Linux Dig for Network Admins: Practical Guide with Examples

> Become a network troubleshooting expert! This comprehensive Linux Dig guide empowers you with essential DNS query commands for immediate results.

Source: https://adamtheautomator.com/linux-dig/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Linux Dig for Network Admins: Practical Guide with Examples](https://adamtheautomator.com/wp-content/uploads/2022/09/Useful-Linux-Dig-Examples-for-the-Network-Admin.jpg)

# Linux Dig for Network Admins: Practical Guide with Examples

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)22 February 20247 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Command Line](/tag/command-line/)[Linux](/tag/linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Installing the Linux dig Command](#installing-the-linux-dig-command)
*   [Trying Linux Dig for a Basic DNS Query](#trying-linux-dig-for-a-basic-dns-query)
*   [Understanding the Output of a Basic DNS Query](#understanding-the-output-of-a-basic-dns-query)
*   [Fetching Short and Detailed Answers](#fetching-short-and-detailed-answers)
*   [Specifying Nameservers to Resolve Domain Names](#specifying-nameservers-to-resolve-domain-names)
*   [Querying Specific Record Types](#querying-specific-record-types)
*   [Performing Queries in Batch Mode](#performing-queries-in-batch-mode)
*   [Controlling DiG’s Behavior Using the .digrc File](#controlling-digs-behavior-using-the-digrc-file)
*   [Conclusion](#conclusion)

As a Linux network administrator, you are likely to come across various problems that can be solved with the Linux `dig` (Domain Information Groper) command. Not sure how the `dig` command works? No worries! You’re in for a treat!

In this tutorial, you’ll learn a few useful examples of how to use dig to solve real-world problems.

Dig in, and befriend this powerful tool!

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have a Linux system. This tutorial uses Ubuntu 20.04, but any modern Linux distribution will work.

Related:[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)

## Installing the Linux `dig` Command

The Linux `dig` command lets you gather [DNS](https://adamtheautomator.com/wireshark-dns-filter/) information that can be helpful with troubleshooting DNS problems. But before digging name servers, you first have to install `dig` on your machine.

Related:[Snooping on DNS Queries with a Wireshark DNS Filter](https://adamtheautomator.com/wireshark-dns-filter/)

1\. Run the [apt update](https://linuxize.com/post/how-to-use-apt-command/#updating-package-index-apt-update) command below to update your system’s package index.

```bash
apt update -y
```

![](https://s3.us-west-2.amazonaws.com/secure.notion-static.com/059bb8d9-ff69-4bd0-9716-15ddecb5e4b6/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220908%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220908T152049Z&X-Amz-Expires=86400&X-Amz-Signature=f3f7c1adfa8219131abc8640bfcb40953856f9adddb2cad216c1e099843dd774&X-Amz-SignedHeaders=host&response-content-disposition=filename%20%3D%22Untitled.png%22&x-id=GetObject)

Update the system’s package index

Related:[Learning Ubuntu Apt Get Through Examples](https://adamtheautomator.com/ubuntu-apt-get/)

2\. Next, run the following [apt install](https://linuxize.com/post/how-to-use-apt-command/#installing-packages-apt-install) command to install dnsutils on your machine. DiG is part of a DNS utility package (dnsutils) installed with BIND name servers.

dnsutils is a set of tools the Ubuntu team provides that contains various client-side DNS utilities, like dig.

Related:[Getting Started with the BIND DNS Server](https://adamtheautomator.com/bind-dns-server/)

```bash
apt install dnsutils -y
```

![Installing the dig command](https://adamtheautomator.com/wp-content/uploads/2022/09/image-179.png)

Installing the dig command

3\. Lastly, run the dig command below to verify your DiG installation.

```bash
dig -v
```

Below, DiG’s version shows 9.16.1, but yours may be different.

![Verifying DiG installation](https://adamtheautomator.com/wp-content/uploads/2022/09/image-180.png)

Verifying DiG installation

## Trying Linux Dig for a Basic DNS Query

Now that you have dig installed, you can try out the `dig` command for a basic DNS query. The dig command lets you query DNS servers to gather a handful of information you can use to troubleshoot and fix DNS problems.

The syntax for a basic DNS query is as follows where:

*   `server` – The DNS server to query an IP address or a domain name. DiG will use your computer’s pre-configured DNS if you don’t specify a server.
*   `name` – The domain name or IP address to look up.
*   `type` – The [type of DNS record](https://www.namecheap.com/guru-guides/dns-records/) you are looking for.

```bash
dig [server] [name] [type]
```

Now, run the following command to query the DNS records for `google.com`.

When you run the `dig` command without any flags or arguments, `dig` performs a DNS query as an argument and returns the A record for the specified hostname.

```bash
dig [google.com](<http://google.com/>)
```

A basic DNS query using `dig` is useful for a few different tasks, such as:

*   Checking the DNS records for a domain.
*   Finding out which DNS server is used for a domain.
*   Check if your computer is using the correct DNS server.

![Querying google.com](https://adamtheautomator.com/wp-content/uploads/2022/09/image-181.png)

Querying google.com

Querying [google.com](http://google.com)

## Understanding the Output of a Basic DNS Query

Considering DiG returned lots of information about the domain name you queried, you can already see what’s happening with that domain. Or no? Probably not. But don’t worry. You’ll walk through a breakdown of each section you’ll see on a basic DNS query output.

Below, the first line shows the version of DiG and the queried domain name (**[google.com](http://google.com)**). At the same time, the second line shows the global options used to run the query.

In this case, the only option used was **+cmd**, which tells DiG to print the commands that were run as DiG executes them.

![Viewing global option](https://adamtheautomator.com/wp-content/uploads/2022/09/image-182.png)

Viewing global option

The following section (**HEADER**) shows you the technical details of the query:

*   The first line specifies the **opcode** used for the query (in this case, **QUERY**), followed by the **status: NOERROR** of the query and the **id** number(**47244**). The **NOERROR** status indicates that the DNS server processed the query and successfully returned an answer. If you get a **SERVFAIL** status, there was some DNS server error, resulting in a failed query.
*   The **flags** section shows you which flags were set for the query. In this case, **qr** (query response), **rd** (recursion was not desired), and **ra** (recursion is available).
*   The last line tells you how many queries (**QUERY**) were made (**1**). You’ll also see how many **ANSWER**s (**1**), **AUTHORITY** records (**0**), and **ADDITIONAL** records(**1**) DiG returned.

![Viewing the technical details of the query](https://adamtheautomator.com/wp-content/uploads/2022/09/image-183.png)

Viewing the technical details of the query

The **OPT PSEUDOSECTION** below indicates that the DNS message has been [extended](https://en.wikipedia.org/wiki/Extension_Mechanisms_for_DNS) using the EDNS0 protocol. The **flags** field is empty because no options have been set, while the **udp** field specifies the maximum size of the DNS message, which is **65,494** bytes.

![Viewing the OPT PSEUDOSECTION](https://adamtheautomator.com/wp-content/uploads/2022/09/image-184.png)

Viewing the OPT PSEUDOSECTION

Now, the **ANSWER** section below shows you the answer returned for the query. In this case, you queried for the A record of _[google.com](http://google.com)_, and the DNS server returned an IP address of **142.250.80.110**. You can see _[google.com](http://google.com)’s_ A record points to that IP address.

![Viewing the ANSWER section](https://adamtheautomator.com/wp-content/uploads/2022/09/image-185.png)

Viewing the ANSWER section

Finally, the last section contains information about the query time and the server used to process the query. Below, you can see the query took four milliseconds (**4 msec**) to complete, and the **SERVER** used had an IP address of **127.0.0.53**.

The less time the DNS server takes to process a query and return an answer, the better. You don’t want your users to wait long for DNS queries to resolve. The long wait can lead to a bad user experience.

![Viewing the query process information](https://adamtheautomator.com/wp-content/uploads/2022/09/image-186.png)

Viewing the query process information

## Fetching Short and Detailed Answers

You’ve just queried a DNS that returned a handful of information. But can you control which output you get? Yes, by appending flags (`+short`, `+noall`, and `+answer`) to the `dig` command.

Suppose you’re querying for an A record. The DNS server returns both an A and an AAAA record. But with the `+short` flag, the DNS only returns the A record. The `+short` flag can be useful for getting a quick answer from DNS servers without sifting through all the extra information.

Run the below command to query `google.com` again. But this time, append the `+short` flag to get a short answer only.

```bash
dig +short google.com
```

Below, you’ll see that DiG only returned a short answer, which is Google’s server address.

![Getting short answers with the +short flag](https://adamtheautomator.com/wp-content/uploads/2022/09/image-187.png)

Getting short answers with the +short flag

Now, run the following command to query `google.com`, returning a detailed answer. The `+noall` flag omits all the default information displayed when running the `dig` command, except for the answer section (`+answer`).

```bash
dig google.com +noall +answer
```

![Getting detailed answers with the +noall, and +answer flags](https://adamtheautomator.com/wp-content/uploads/2022/09/image-188.png)

Getting detailed answers with the +noall, and +answer flags

## **Specifying Nameservers to Resolve Domain Names**

So far, you’ve seen how to use the `dig` command with its default settings. But suppose you want to test if a specific nameserver can resolve a domain name or not. In such cases, specifying which DNS server DiG uses when running the `dig` command can help.

By default, the `dig` command uses the DNS servers specified in the _/etc/resolv.conf_ file, as shown below.

![Viewing the /etc/resolv.conf file](https://adamtheautomator.com/wp-content/uploads/2022/09/image-189.png)

Viewing the /etc/resolv.conf file

To override which DNS server DiG uses when resolving a domain name, you’ll append the `@` symbol followed by the DNS server or IP.

Run the below command to query a domain name (`server`) using your preferred DNS server(`dns-or-ip`). Be sure to replace `dns-or-ip` with your DNS server, but this tutorial uses **8.8.8.8**.

```bash
dig server +noall +answer @dns-or-ip
```

You can see below that the DNS server resolved the domain name successfully and returned answers in detail.

![Specifying nameservers](https://adamtheautomator.com/wp-content/uploads/2022/09/image-190.png)

Specifying nameservers

## Querying Specific Record Types

By default, the `dig` command queries for an A record if you don’t specify any record type. But DiG also lets you query other types of DNS records, such as MX, NS, TXT, and so on.

To specify a record type, you append the record type right after the domain name you’re looking up, like in the following example.

Run the command below to query `google.com` for MX records.

```bash
dig +noall +answer google.com mx
```

You can see below that the MX record for **[google.com](http://google.com)** is **[smtp.google.com](http://smtp.google.com)**.

![Querying for MX records](https://adamtheautomator.com/wp-content/uploads/2022/09/image-191.png)

Querying for MX records

Now, run the following command to query `google.com` for TXT records

```bash
dig +noall +answer google.com txt
```

The output below shows all TXT records for _[google.com](http://google.com)_, as shown below.

![Querying for TXT records](https://adamtheautomator.com/wp-content/uploads/2022/09/image-192.png)

Querying for TXT records

## Performing Queries in Batch Mode

Suppose you want to look up DNS information for multiple domain names. Querying information one by one for each domain name can be tedious and time-consuming.

Fortunately, the `dig` command supports a batch mode, where you can specify a file containing a list of domain names. DiG will perform DNS queries for all domain names listed in that file in batch mode.

Open a new text file named _dns-batch-file.txt_ in your preferred text editor, and add the domain names (one per line), as shown below. Once you’re happy with the list, save the file and close the editor.

![](https://adamtheautomator.com/wp-content/uploads/2022/09/image-193.png)

Listing domain names in the _dns-batch-file.txt_ file

Related:[How to Edit Files with a Real PowerShell Text Editor](https://adamtheautomator.com/powershell-text-editor/)

Now, run the following command to query all domains listed in the specified (`-f`) `dns-batch-file.txt` file in batch mode.

```bash
dig -f dns-batch-file.txt +noall +answer
```

As you can see below, the DNS information for all domains has been queried and displayed in a tabular format.

![Performing queries in batch mode](https://adamtheautomator.com/wp-content/uploads/2022/09/image-194.png)

Performing queries in batch mode

## Controlling DiG’s Behavior Using the ._digrc_ File

DiG reads various settings from the ~/.digrc file when you run the dig command. This file contains various settings that let you control how the `dig` command behaves. With the \_~/.digrc file\_, you can set the default DNS server that the `dig` command should query or set the default record type to query if you don’t specify any.

Perhaps you aim to get a detailed answer and ignore all other sections most of the time when running the `dig` command. In such cases, you can use the _~./digrc_ file to set the default output style for the `dig` command, like in the following example.

Run the `echo` command below, which doesn’t provide output, but adds the `+noall +answer` line to the _~/.digrc_ file.

```bash
echo "+noall +answer" > ~/.digrc
```

Now, run the `dig` command to query a domain name without arguments. Replace `domain` with your preferred domain name.

```bash
dig domain
```

You can see that the output now only contains the answer section, as shown below. DiG would use the `+noall +answer` flags from the _~/.digrc_ file even if you didn’t append any flags when you ran the dig command.

![Controlling DiG’s behavior using the ~/.digrc File](https://adamtheautomator.com/wp-content/uploads/2022/09/image-195.png)

Controlling DiG’s behavior using the _~/.digrc_ File

## Conclusion

In this article, you’ve learned various features of the Linux `dig` command to query DNS servers effectively. You’ve also touched on customizing your desired `dig` command output using multiple flags.

At this point, you already know how to take advantage of the Linux `dig` command in your day-to-day work, especially when troubleshooting network problems.

Don’t stop here, though. There is more to what you can accomplish with the Linux `dig` command. Why not use the `dig` command to [perform a reverse DNS loo](https://linuxhint.com/reverse-dns-lookup-in-linux/)[kup](https://linuxhint.com/reverse-dns-lookup-in-linux/) to find a domain name associated with an IP address?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Flinux-dig%2F&text=Linux%20Dig%20for%20Network%20Admins%3A%20Practical%20Guide%20with%20Examples)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Flinux-dig%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Flinux-dig%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Practical-Linux-Unix-Tee-Commands-for-the-Linux-Admin.jpg)

### [Master Unix tee Commands for Real-World Linux Admin Tasks](/unix-tee/)

Simplify Linux output management and streamline your workflow with the “Unix tee” command. This tutorial guides you through its practical applications.

![](https://adamtheautomator.com/wp-content/uploads/2021/12/install-phpmyadmin.jpg)

### [Step-by-Step Tutorial to Install phpMyAdmin Securely on Linux](/install-phpmyadmin/)

Discover how to securely install phpMyAdmin on Linux with our concise guide. Learn essential steps for a safe and efficient setup, tailored for Linux users.

![](https://adamtheautomator.com/wp-content/uploads/2023/08/timedatectl.jpg)

### [Learning the timedatectl Command Though Examples](/timedatectl/)

Learn how to use the Linux timedatctl command-line tool to configure and set your systems time and date in this ATA Learning tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
