Log inSign up

Query and troubleshoot DNS with dig

Install dig with sudo apt install bind9-dnsutils on Ubuntu or Debian, or sudo dnf install bind-utils on Rocky and Alma. Then dig example.net A +short returns the address, dig @1.1.1.1 example.net asks a specific resolver, and dig +trace example.net follows the delegation from the root, which shows exactly where a wrong or missing record comes from.

Topic: Networking and diagnostics · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

How do you install dig?

dig is part of the BIND utilities, packaged separately from the BIND server itself. Install the client tools with the command for your system:

# Ubuntu 24.04 / 22.04, Debian 12 / 13
sudo apt update && sudo apt install -y bind9-dnsutils

# Rocky Linux 9, AlmaLinux 9
sudo dnf install -y bind-utils

dig -v

The older package name dnsutils still works on Debian and Ubuntu as a transitional package that pulls in bind9-dnsutils. The same package also gives you host and nslookup, but dig shows the most detail and is the tool used in the rest of this page.

How do you read a basic dig answer?

Run dig with a name and, optionally, a record type. Without a type it asks for A records:

dig example.net
dig example.net AAAA
dig example.net A +short

The full output has several parts. The header line shows status: NOERROR when the name exists, NXDOMAIN when it does not, and SERVFAIL when the resolver could not get a valid answer (often a DNSSEC or nameserver problem). The flags include aa when the reply came straight from an authoritative server. The ANSWER SECTION lists records with their TTL in seconds, which tells you how long caches will keep the value. The footer names the server that answered and the query time. Add +short when you only need the values, or +noall +answer to keep the answer lines with their TTLs.

Which record types will you check most?

Each service depends on a few record types, and dig queries all of them the same way:

dig example.net A +short          # IPv4 address
dig example.net AAAA +short       # IPv6 address
dig www.example.net CNAME +short  # alias target
dig example.net MX +short         # mail servers and priority
dig example.net TXT +short        # SPF, verification tokens
dig _dmarc.example.net TXT +short # DMARC policy
dig example.net CAA +short        # which CAs may issue certificates
dig example.net NS +short         # delegated nameservers
dig example.net SOA +short        # zone serial and timers

After pointing a domain at your server, the A and AAAA answers should show 198.51.100.24 and 2001:db8:4f2a::24, the addresses of your instance. The DNS records tutorial explains how to create them at your registrar or DNS host. A CAA record that names a different certificate authority is a frequent reason why Let's Encrypt refuses to issue a certificate, so check it when a TLS setup fails.

How do you ask a specific DNS server?

Put the server after an @ sign. This lets you compare what different resolvers return and query the authoritative servers directly, bypassing every cache:

dig @1.1.1.1 example.net A +short
dig @9.9.9.9 example.net A +short
dig example.net NS +short
dig @ns1.example.net example.net A +norecurse

When the authoritative server already returns the new address but a public resolver still gives the old one, the record is correct and you are waiting for the cached copy to expire; the TTL in the resolver answer shows how many seconds remain. When the authoritative server itself returns the old value, the change was never saved at your DNS host. The resolver your own server uses is listed by resolvectl status on Ubuntu or in /etc/resolv.conf elsewhere.

How do you trace delegation from the root?

Use +trace. dig then starts at the root servers, follows the referral to the top level domain servers and finally to your nameservers, printing each step:

dig +trace example.net A

Read the output from top to bottom. The second block shows which nameservers the registry (for example the .net servers) has on record for your domain. If those are not the nameservers you configured, the delegation at the registrar is wrong or still pending, and no change inside your zone will help. The last block shows the final answer from your own nameservers. Trace mode does its own iterative lookups and ignores your local resolver, which makes it a clean test when you suspect caching.

How do you look up reverse DNS?

Use -x with an IP address. dig builds the special reverse name for you and asks for the PTR record:

dig -x 198.51.100.24 +short
dig -x 2001:db8:4f2a::24 +short

Mail servers in particular check that the PTR name of a sending address resolves back to the same address. Reverse DNS for your server addresses is not set in the console; open a support ticket with the address and the hostname, and create the forward A or AAAA record first so the pair matches.

How do you check DNSSEC with dig?

Ask for DNSSEC records with +dnssec and look for the ad (authenticated data) flag in the reply from a validating resolver:

dig @1.1.1.1 example.net A +dnssec
dig example.net DNSKEY +short
dig example.net DS +short

A signed and correctly chained zone shows ad in the flags and RRSIG records next to the answer. If a validating resolver returns SERVFAIL while dig +cd (checking disabled) returns an answer, the signatures or the DS record at the registry are broken. This happens most often after moving a domain to new nameservers without removing the old DS record first.

What else helps when troubleshooting DNS?

A few extra options cover the remaining cases:

  • +tcp forces TCP, useful when a firewall blocks large UDP replies.
  • -4 or -6 sends the query over that address family only, which helps confirm IPv6 connectivity to a nameserver.
  • +time=2 +tries=1 shortens waits when a server does not answer.
  • -f names.txt +short runs a batch of queries from a file.

If dig gets no answer at all from your server, check that outgoing UDP and TCP port 53 are not blocked by your own firewall rules. When you run your own resolver or authoritative server, the guides on Unbound and BIND 9 go further.

Questions about DNS lookups with dig

What is the difference between dig, host and nslookup?

All three query DNS. host prints short readable answers, nslookup has an interactive mode, and dig shows the full reply including flags and TTLs, which is what you need for troubleshooting.

Why do I get different answers from different resolvers?

Each resolver caches records for the TTL it received. Right after a change some resolvers still hold the old value. Query the authoritative server with @ to see the current truth.

How long does DNS propagation take?

There is no fixed delay: a cached record expires after its TTL. Lower the TTL a day before planned changes, for example to 300 seconds, so the switch completes quickly.

Can dig check if port 53 is open on my own DNS server?

Yes. Run dig @198.51.100.24 example.net from another machine. A timeout means the port is blocked or the service is not listening; REFUSED means it answered but will not serve that query.

Is dig available on FreeBSD?

FreeBSD has drill in the base system with similar options, and dig is available from the bind-tools package.