How-to

The dig Command for DNS Lookups

dig asks DNS servers exactly what you tell it and shows exactly what they answer. It is the tool to reach for when a domain does not point where you expect.

How do I get dig?

It ships with the BIND utilities. Install bind9-dnsutils on Debian 13, Debian 12 and Ubuntu (the older name dnsutils still pulls it in), and bind-utils on Rocky Linux, AlmaLinux and CentOS Stream, covered in Install dig on CentOS, Rocky, Alma. FreeBSD offers it through the bind-tools package. The same packages provide nslookup and host.

What does a basic query show?

dig shop.example.net

The output has sections. The header shows the status, where NOERROR means the name exists and NXDOMAIN means it does not. The ANSWER section holds the records with their TTL in seconds. The footer names the server that answered and how long it took. For scripts and quick checks, ask for just the data:

dig +short shop.example.net
dig +noall +answer shop.example.net A

How do I query other record types?

CommandAnswers
dig example.net MX +shortMail servers with priorities
dig example.net TXT +shortSPF, verification strings, DMARC at _dmarc
dig example.net NS +shortAuthoritative name servers
dig example.net CAA +shortWhich certificate authorities may issue
dig _sip._udp.example.net SRVService records, such as VoIP or game servers
dig example.net SOA +multilineZone serial and timers

The AAAA type returns IPv6 addresses for names that have them; our machines are IPv4 only, so records you publish for them are A records.

How do I point dig at one particular server?

Put the server after an @. Comparing answers from different servers is how you diagnose most DNS changes that "have not taken effect":

dig @ns1.dns-host.example shop.example.net +short     # the authoritative answer
dig @1.1.1.1 shop.example.net +short                  # a public resolver's cached view
dig @127.0.0.53 shop.example.net +short               # the local systemd-resolved stub

If the authoritative server already returns the new address but a resolver returns the old one, the resolver is serving a cached record until its TTL runs out. The TTL column in the full answer shows how many seconds remain.

How do I follow delegation from the root?

dig +trace shop.example.net

+trace starts at the root servers, follows the referral to the top-level domain servers, then to your domain's name servers, and shows each step. It answers "which name servers does the world think my domain uses?", which is the first question after moving DNS hosting. A trace that ends at the old provider means the registrar still lists old name servers.

How do I look up a reverse record?

dig -x 203.0.113.25 +short

Reverse lookups map an address back to a name through a PTR record. Mail servers often check them. For our machines, reverse DNS edits are not part of the offer, so the PTR stays as the network sets it; send outbound mail through a relay or a provider whose reputation tools you control, and keep SPF and DKIM correct for your domain.

How do I check DNSSEC?

dig +dnssec example.net SOA
dig example.net DS @a.gtld-servers.example +short

An ad flag in the header, when asking a validating resolver, means the answer was verified. RRSIG records in the answer show the zone is signed. A domain with a DS record at the parent but broken signatures fails resolution entirely on validating resolvers, a common outcome of moving DNS hosts without updating DNSSEC first.

Which extra options help?

  • +tcp forces TCP, useful when large answers or firewalls interfere with UDP.
  • -4 keeps the query on IPv4, matching how our machines reach the internet.
  • +norecurse asks a server only what it knows itself, handy against authoritative servers.
  • -f names.txt +short runs a batch of queries from a file.

For the classic alternative with an interactive mode, see The nslookup command.

Keep Reading

The nslookup command

Look up DNS records with nslookup on any system, use its interactive mode, switch servers and record types, and know when dig is better.

Open

Install dig on CentOS, Rocky, Alma

Add dig, nslookup and host to CentOS Stream 9, Rocky Linux 9 or AlmaLinux 9 with one package, and confirm the resolver they use.

Open

IPv4 on a /31

Why each machine gets one public IPv4 on a /31 network, how the two addresses split between gateway and server, and how to configure it.

Open

Headers with curl

Show response headers, send or remove request headers, pick single header values and test caching, compression and virtual hosts with curl.

Open

FAQ

Quick Answers

Install bind9-dnsutils on Debian and Ubuntu or bind-utils on Rocky Linux and AlmaLinux.

Add +short, for example dig +short example.net.

Put the server after an @ sign, such as dig @1.1.1.1 example.net.

It follows delegation from the root servers down to your domain's name servers, showing each step.

Reverse DNS edits are not offered. Use a mail relay for outbound email that needs a custom PTR.