dig commands cheat sheet

This cheat sheet brings together the dig commands for checking DNS: queries for every record type, shorter output, querying a specific DNS server, checking whether a change has propagated, following the delegation, DNSSEC, and checking email records, along with how to read the response. You can search for a command, filter by topic, and copy it with one click.

Installation and version

  • sudo dnf install bind-utils

    Installs dig on RHEL-family distributions, such as AlmaLinux and Rocky Linux. The package also includes other DNS testing tools.

  • sudo apt install bind9-dnsutils

    Installs dig on Debian and Ubuntu, together with nslookup and nsupdate. The old package name dnsutils installs the same package.

  • dig -v

    Shows the dig version and exits. When the command isn't found, the tool isn't installed on the server.

  • dig -h

    Shows a summary of all the command's options and syntax.

Queries by record type

  • dig example.com

    A basic query. Without a record type, dig asks for an A record, and without a specified server, it queries the DNS servers listed in the /etc/resolv.conf file.

  • dig example.com AAAA

    Shows the domain's IPv6 address.

    Example: example.com. 3600 IN AAAA 2001:db8::10

  • dig example.com MX

    Shows the domain's mail servers. The number before the server name is the priority: the lower the value, the higher the priority.

    Example: example.com. 3600 IN MX 10 mail.example.com.

  • dig example.com TXT

    Shows the domain's TXT records, including the SPF record and ownership verification records.

  • dig example.com NS

    Shows the nameservers that manage the domain.

  • dig example.com SOA

    Shows the zone's SOA record: the primary nameserver, the administrator's email address, the serial number, and the refresh timers.

  • dig www.example.com CNAME

    Checks whether the name is set as an alias (CNAME) of another name, and shows the target name.

    Example: www.example.com. 3600 IN CNAME example.com.

  • dig example.com CAA

    Shows which certificate authorities are allowed to issue SSL certificates for the domain. When there is no CAA record, any certificate authority may issue them.

    Example: example.com. 3600 IN CAA 0 issue "letsencrypt.org"

  • dig -x 192.0.2.10

    Reverse lookup: shows the name (PTR record) set for an IP address. The -x option builds the name in the in-addr.arpa domain by itself.

    Example: 10.2.0.192.in-addr.arpa. 3600 IN PTR mail.example.com.

  • dig -x 2001:db8::10

    Reverse lookup for an IPv6 address. dig builds the name in the ip6.arpa domain automatically.

  • dig _imaps._tcp.example.com SRV

    Shows an SRV record, whose name combines the service and the protocol, each prefixed with an underscore. The response includes the priority, weight, port, and server name.

    Example: _imaps._tcp.example.com. 3600 IN SRV 0 1 993 mail.example.com.

  • dig -t MX example.com

    Another way to specify the record type, with the -t option. The result is the same as writing the type after the name.

  • dig example.com ANY

    Asks for all the records of the name. Many servers return only a partial response to this query, as RFC 8482 allows, so for a full check, query each record type separately.

  • dig +noall +answer example.com MX example.net MX

    Runs several queries in one command. Options written before the first query apply to all the queries.

Shorter output

  • dig example.com +short

    Shows only the values, without headers and sections. When the name is a CNAME, the target name appears first, followed by the addresses.

    Example: 192.0.2.10

  • dig example.com MX +short

    Shows the mail servers, one per line, with their priority.

    Example: 10 mail.example.com.

  • dig example.com +noall +answer

    Hides all the output and shows only the answer section, with the name, TTL, and type of each record. This is the convenient way to see the TTL too.

    Example: example.com. 3600 IN A 192.0.2.10

  • dig example.com +noall +answer +authority

    Shows the answer section and the AUTHORITY section, which lists the zone's nameservers or its SOA record.

  • dig example.com SOA +multiline

    Shows long records spread over several lines, with an explanation of each field. Especially convenient for SOA records and DNSSEC keys.

  • dig example.com +noall +answer +ttlunits

    Shows the TTL in readable time units, such as 1h or 5m, instead of seconds.

    Example: example.com. 1h IN A 192.0.2.10

  • dig example.com +nocmd +nostats

    Hides the opening line with the version and the statistics at the end of the output, and keeps the header and the sections.

Specific DNS server and propagation checks

  • dig @192.0.2.53 example.com

    Sends the query to a specific DNS server, by IP address or by name, instead of the servers set in the /etc/resolv.conf file.

  • dig @ns1.example.com example.com A +norecurse

    Queries the domain's authoritative nameserver directly, without requesting recursion. This shows the value currently set in the zone, without the cache of an intermediate server. An authoritative response includes the aa flag.

  • for r in 1.1.1.1 8.8.8.8 9.9.9.9; do echo "$r: $(dig @$r example.com +short)"; done

    Queries several well-known public DNS servers and shows the response of each one. When the responses differ, some servers still keep the previous value in their cache until its TTL expires.

  • for ns in $(dig example.com NS +short); do echo "$ns $(dig @$ns example.com SOA +short)"; done

    Shows the SOA record on each of the domain's nameservers. When the serial number is the same on all of them, the latest change has reached all the servers.

  • dig example.com +nssearch

    Finds the zone's authoritative nameservers and shows the SOA record each of them returns, so you can make sure the serial number is the same on all the servers.

  • watch -n 30 dig @1.1.1.1 example.com +short

    Runs the query again every 30 seconds, so you can see when the new value starts to appear. Press Ctrl+C to exit.

  • dig @192.0.2.53 -p 5353 example.com

    Sends the query to a port other than port 53, for example to a local DNS server used for testing.

  • dig -4 example.com

    Sends the query over IPv4 only. The -6 option sends it over IPv6 only, which is useful for testing a nameserver at an IPv6 address.

    Example: dig -6 @ns1.example.com example.com

  • dig example.com TXT +tcp

    Sends the query over TCP instead of UDP. Useful for checking that the nameserver also answers over TCP, which large responses require.

  • dig @1.1.1.1 example.com +tls

    Sends the query over an encrypted connection (DNS over TLS). The +https option sends it over DNS over HTTPS. Both options are available in recent versions of dig.

    Example: dig @1.1.1.1 example.com +https

  • dig example.com +timeout=2 +tries=1

    Shortens the wait for a response to 2 seconds and makes only one attempt. The default is 5 seconds and 3 attempts.

Following the delegation

  • dig example.com +trace

    Follows the delegation chain from the root servers, through the TLD servers, to the domain's nameservers, without the local DNS server's cache. Useful after changing nameservers. The output is long, and when the server's firewall blocks outgoing DNS queries, the command fails.

  • dig example.com +trace +nodnssec

    Follows the delegation without the DNSSEC signature records, which +trace shows by default. The output is shorter and easier to read.

  • dig com. NS +short

    Shows the nameservers of the com TLD. You can find the servers of any other TLD the same way.

  • dig @a.gtld-servers.net example.com NS +norecurse

    Asks the TLD server which nameservers are registered for the domain with the TLD registry. The response appears in the AUTHORITY section, and you can compare it with the nameservers set at the domain registrar.

DNSSEC

  • dig example.com +dnssec

    Also asks for the DNSSEC records, using the DO bit in the query. For a signed domain, RRSIG records appear next to the answer, and the ad flag appears when the DNS server has validated the signatures.

  • dig example.com DS +short

    Shows the DS record published in the TLD. When there is no DS record, DNS servers don't validate the domain's signatures, even if the zone itself is signed.

  • dig example.com DNSKEY +multiline

    Shows the zone's DNSSEC keys. In the multiline layout, each key shows its type (KSK or ZSK) and its key id, for comparison with the DS record.

  • dig example.com +cd

    Asks the DNS server not to validate signatures, using the CD bit in the query. When the regular query returns SERVFAIL and a query with +cd returns an answer, the problem is probably in the domain's DNSSEC signatures.

Checking email records

  • dig example.com TXT +short | grep spf1

    Shows the domain's SPF record. A domain should have only one SPF record, and two SPF records make the check fail.

    Example: "v=spf1 mx ip4:192.0.2.25 -all"

  • dig _dmarc.example.com TXT +short

    Shows the DMARC record, which is always published at the _dmarc name in front of the domain name.

    Example: "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com"

  • dig selector1._domainkey.example.com TXT +short

    Shows the DKIM public key. Instead of selector1, write the selector name, which appears in the s= tag of the DKIM-Signature header of a message sent from the domain.

  • dig -x 192.0.2.25 +short

    Shows the reverse name (PTR) of the mail server's address. Many mail servers check that the sending address has a reverse name, and that the name points back to the same address.

    Example: mail.example.com.

  • dig _mta-sts.example.com TXT +short

    Shows the MTA-STS record, which tells other mail servers that the domain publishes an MTA-STS policy for encrypted connections when they deliver mail to it.

Reading the response

  • status: NOERROR

    The query succeeded. When the ANSWER count is 0, the name exists but has no records of the queried type (a state called NODATA).

  • status: NXDOMAIN

    The name doesn't exist in the zone at all. In this case, check the name for typos and make sure the record was added to the correct zone.

  • status: SERVFAIL

    The DNS server couldn't process the query. Common causes are authoritative nameservers that don't respond, or a DNSSEC validation failure.

  • status: REFUSED

    The server refused to answer for policy reasons, for example a nameserver that doesn't manage the domain, or a DNS server that doesn't accept queries from external addresses.

  • flags: qr aa

    qr marks a response. aa marks an authoritative answer, which came from one of the domain's nameservers and not from a cache.

  • flags: rd ra

    rd marks that the query requested recursion, and ra marks that the responding server supports recursion. In a query with +norecurse, the rd flag doesn't appear.

  • flags: ad

    The responding DNS server has validated the DNSSEC signatures of the answer.

  • flags: tc

    The response was truncated because it exceeded the size allowed over UDP. In this case, dig automatically sends the query again over TCP.

  • ANSWER SECTION

    The records that answer the query. Each line includes a name, TTL, class (IN), type, and value.

    Example: example.com. 3600 IN A 192.0.2.10

  • AUTHORITY SECTION

    Records that point to the zone's authoritative nameservers, or an SOA record when the answer is empty or the name doesn't exist.

  • TTL

    The number after the name. In a response from a caching DNS server, it shows the number of seconds left until the record is checked again, and it goes down with each repeated query. In a query to the authoritative server, the full value set in the record appears.

  • ;; SERVER:

    Appears at the end of the output, together with the query time and the response size, and shows which DNS server answered and on which port.

    Example: ;; SERVER: 192.0.2.53#53(192.0.2.53) (UDP)

Automation and defaults

  • dig -f domains.txt +noall +answer

    Batch mode: dig reads the queries from a file, one query per line, such as example.com MX.

  • echo "+noall +answer" > ~/.digrc

    Sets personal defaults for every dig run, applied before the command-line options. The command overwrites an existing ~/.digrc file.

  • dig -r example.com

    Runs the query without the settings in the ~/.digrc file.

  • dig -q example.com

    Specifies the query name explicitly. Useful when the name could be read as a record type or an option.

Names and addresses in the examples

The examples on this page use the example.com domain and IP addresses reserved for documentation, such as 192.0.2.10 and 2001:db8::10, so replace them with your own domain name and addresses. The addresses 1.1.1.1, 8.8.8.8, and 9.9.9.9 are well-known public DNS servers, and they are a good way to check the response the rest of the world gets.

Why different servers return different answers

DNS servers keep every response in their cache for the length of its TTL. After a record changes, the authoritative server returns the new value right away, and other servers keep returning the previous value until it expires in their cache. That is why you check the authoritative server first with +norecurse, and only then the public servers. When the authoritative server still returns the old value, the change wasn't saved in the zone, or it was made at a DNS provider that doesn't manage the domain.

Did you know?

With our Cloudflare services, we connect your domain to Cloudflare and copy all your existing DNS records, including your email records. After the move, you can use the dig example.com NS +short command to confirm that the new nameservers are already published.

Cloudflare services

dig commands FAQ

How do I check whether a DNS change has propagated?

First, query the domain's authoritative nameserver, for example dig @ns1.example.com example.com A +norecurse. When it returns the new value, the change is saved in the zone. Then query public DNS servers, such as dig @1.1.1.1 example.com +short and dig @8.8.8.8 example.com +short. A server that still returns the previous value is keeping it in its cache, and it will pick up the new value once the TTL of the previous record expires, at the latest.

How do I find a domain's nameservers?

The dig example.com NS +short command shows the nameservers set in the domain's zone. To see the nameservers registered with the TLD registry, run dig example.com +trace +nodnssec and look at the step where the TLD server refers to the domain's servers. After changing nameservers, both checks should show the same servers.

How do I check that a domain's SPF, DKIM, and DMARC records are set up?

The SPF record is checked with the dig example.com TXT +short command, and it is the line that starts with v=spf1. The DMARC record is checked with the dig _dmarc.example.com TXT +short command. The DKIM record is located at a name that includes the selector, for example dig selector1._domainkey.example.com TXT +short, and you can find the selector name in the s= tag of the DKIM-Signature header of a message sent from the domain. For a detailed syntax check, our website has dedicated SPF and DMARC checkers.

What is the difference between NXDOMAIN and an empty answer?

NXDOMAIN means the name doesn't exist in the zone at all. A response with status: NOERROR and ANSWER: 0 means the name exists, but it has no records of the queried type. For example, for a name that has only an A record, an MX query returns an empty answer and not NXDOMAIN.

What is the difference between dig and nslookup?

Both tools send DNS queries, and on most Linux distributions they are installed together from the same package. dig shows the server's full response, including the flags, the sections, and the TTL, and lets you control every detail of the query, which is why it is the standard tool for diagnosing DNS problems. nslookup shows a condensed response, and it is also available on Windows.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement