Skip to content

/commands/dig/dig-query-specific-dns-server

dig @8.8.8.8 example.com: query a specific DNS server

The commands on this page have not been executed by our verification runner yet.updated
tool
dig / nslookup
versions
BIND 9.18, BIND 9.20
os
linux, macos, windows

dig @SERVER NAME TYPE sends the query to the name server you choose instead of the ones in /etc/resolv.conf. Use it to compare what different resolvers return, to ask a zone's authoritative server directly (bypassing caches), or to test a server you just configured. SERVER is an IPv4 or IPv6 address or a host name; the ;; SERVER: line near the end of the output confirms which server answered.

bash
dig @1.1.1.1 example.com            # public resolver, A record
dig @8.8.8.8 example.com MX         # another resolver, MX record
dig @ns1.example.net example.com    # authoritative server, no cache in between
dig @127.0.0.1 -p 5353 example.com  # local server on a non-standard port

How dig picks the server

Without @, dig reads the nameserver lines of /etc/resolv.conf and uses the first address that works; if none is usable it queries the local host. With @SERVER the file is ignored for the choice of server. When SERVER is a name, dig resolves it through the system resolver before sending the query, so a broken local resolver can make @ns1.example.net fail while @192.0.2.53 works.

Variants

CommandWhat it does
dig @1.1.1.1 example.comAsk a public recursive resolver; the answer may come from its cache.
dig @ns1.example.net example.com +norecurseAsk the authoritative server without requesting recursion; the reply carries the aa flag when it is authoritative.
dig -4 @dns.example.net example.comUse only IPv4 to reach the server (-6 for IPv6 only).
dig @127.0.0.1 -p 5353 example.comQuery a server listening on a port other than 53.
dig @1.1.1.1 example.com +tcpSend the query over TCP instead of UDP.
dig @1.1.1.1 example.com +tlsDNS over TLS (port 853 by default).
dig @1.1.1.1 example.com +short +identifyShort answer plus the address and port of the server that sent it.

Compare two servers

The common use is checking whether a change has reached every server. Ask the authoritative server first (it has the new data), then a public resolver (it may still serve the old record until the TTL in its cached copy runs out):

bash
dig @ns1.example.net www.example.com +noall +answer
dig @8.8.8.8 www.example.com +noall +answer

The second column of each answer line is the TTL. On the authoritative server it is the configured value; on a resolver it counts down, and the old record disappears when it reaches zero.

Errors you may see

FAQ

Can I give dig a host name after @ instead of an IP?

Yes. dig resolves that name with the system resolver first and then queries the address it gets. If the name cannot be resolved, dig stops with couldn't get address for ... not found, so an IP address is the safer choice when you troubleshoot DNS itself.

How do I query a DNS server on a port other than 53?

Add -p PORT, for example dig @127.0.0.1 -p 5353 example.com. With +tls the default port becomes 853, which is the DNS over TLS port.

Why does the authoritative server return no answer for another domain?

An authoritative-only server answers just for the zones it hosts. For any other name it refuses or returns a referral, and dig prints the warning that recursion was requested but is not available.

Sources