How to Lookup DNS Records with dig CLI Tool

Updated on August 21, 2023
How to Lookup DNS Records with dig CLI Tool header image


Domain Information Groper (dig) is a Linux utility tool that queries Domain Name System (DNS) information for a particular hostname or IP Address. By usage, the dig utility allows you to:

  • Perform DNS lookup operations and verify available DNS settings. For example, check name servers (NS), A, and mail exchange records (MX) for a target domain name
  • Troubleshoot networking and record routing problems
  • Trace a server's DNS path

By functionality, dig checks IP addresses mapped to domain names and any additional records associated with the domain. This guide explains how to look up DNS records using the dig CLI Tool on a Linux server.


Before you start:

Install the dig CLI Tool

The dig utility works on all Linux distributions, but the installation process differs per system. It's part of a larger dnsutils package that additionally enables several DNS client utilities like nsupdate and nslookup. Install the dig CLI tool as described in the following steps

  1. Install the dnsutils package on your server

    On Ubuntu/Debian:

     $ sudo apt install dnsutils -y

    CentOS 7:

     $ sudo yum install bind-utils -y

    Fedora/Rocky Linux:

     $ sudo dnf install bind-utils -y

    Arch Linux:

     $ sudo pacman -Sy dnsutils
  2. When installed, verify the available dig version

     $ dig -v


     DiG 9.18.12...

The dig Usage Syntax

The dig utility uses the following command syntax to fetch DNS records


Below are the available command options:

  • @DNS_SERVER: Defines the name or IP address of the server that performs the query. In short, it sets the DNS database that responds when you submit a query. For example, a hostname, IPv4, or IPv6 address
  • NAME: Defines the resource you want to know more about. For instance, to perform a DNS lookup for the domain, define the domain name when running the dig utility
  • TYPE: The type of query to perform. For example, ANY, A, MX, or NS records. When the TYPE option is not used, the dig command performs a lookup for the A record. Below are the most common DNS record query types you can perform using the dig command:
    • A: Links a domain name to an IP address. This is the main query performed by the dig command
    • NS: Returns the domain name's authoritative nameserver. This record displays the nameserver hosting the domain's DNS records
    • MX: Returns a domain's mail server records
    • CNAME: Also known as Canonical Name, it maps one domain name to another and it's often used to resolve domain variations. By usage, it shows that one domain name is an alias for another domain. For example is a CNAME to
    • TXT: Returns the email server verification records
    • ANY: Returns all records of a query
  • QUERY_OPTIONS: Affects how dig performs and displays the DNS lookup results. Options are relevant when you want to limit the query answers, timeout, and retry strategies. Below are the sample query options:
    • +short: Displays short query outputs
    • +noall: Clears all default output flags
    • +trace: Traces the path a query takes in a hierarchical manner
    • +cmd: Removes comments from the output

Perform DNS Lookup using the dig Command

To test and verify how the dig utility tool works, perform sample DNS look-up operations as described below.

  1. Query the domain A record

     $ dig A


     ; <<>> DiG 9.18.12-0ubuntu0.22.04.2-Ubuntu <<>> A
     ;; global options: +cmd
     ;; Got answer:
     ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57779
     ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
     ; EDNS: version: 0, flags:; udp: 65494
     ;                   IN      A
     ;; ANSWER SECTION:            63083   IN      A
     ;; Query time: 0 msec
     ;; SERVER: (UDP)
     ;; WHEN: Wed Aug 02 10:02:59 UTC 2023
     ;; MSG SIZE  rcvd: 56
  2. Repeat the above query, but use the +short option to return only the most relevant information

     $ dig +short

  3. Query the domain nameserver (NS) records. Clear the default outputs using +noall, and display a short response

     $ dig NS +noall +short


    As displayed in the output, the query returns two nameserver records. This is because a domain name hosts at least two NS records for high availability and load balancing. The nameserver's redundancy setting ensures that DNS queries are successful even when some servers are offline.

  4. Query the domain's MX records

     $ dig MX +noall +short


     0 .

    As displayed in the above output, the domain does not have any MX records. When you query a domain with MX entries, the records display in your output

  5. Using the +trace option, find the DNS path

     $ dig +trace +noall +short


     NS from server in 0 ms.
     NS from server in 0 ms.
     NS from server in 0 ms.
     NS from server in 0 ms.
     NS from server in 0 ms.
     NS from server in 0 ms.
     NS from server in 0 ms.
     NS from server in 0 ms.
     NS from server in 0 ms.
     NS from server in 0 ms.
     NS from server in 0 ms.
     NS from server in 0 ms.
     NS from server in 0 ms.
     A from server 2001:500:8f::53 in 80 ms.
     RRSIG A 13 2 86400 20230811193456 20230721104039 2061 Ujxl1F4YCnUNlRD2kWfq1XeT59rSFtELq/yLZLzkfrfmWcj5xiPO4qRH k1KKO3k3kiKwO24nhR0AYuABZq/CeQ== from server 2001:500:8f::53 in 80 ms.
  6. To redirect a dig query to a specific DNS server and display a short answer with no comments, use the +nocmd, +noall, +answer options as below

     $ dig +nocmd +noall +answer

    Output:    86400   IN      A


In this guide, you installed and used the dig utility tool to look up domain DNS records. The dig utility offers multiple options you can use to enhance your DNS lookup operations. run the dig -h command to view all available options depending on your query needs. When used effectively, the dig command allows you to quickly detect and resolve major DNS issues when working with production cloud servers.

Next Steps

To use other utility tools on your Vultr Cloud Server. Visit the following resources: