Every DNS administrator has faced this frustration: you've updated a DNS record, but your dig
queries keep returning cached results. This happens because:
- Your local resolver caches responses (like systemd-resolved or dnsmasq)
- The recursive resolver (like Google's 8.8.8.8) maintains its own cache
- Even authoritative servers may cache negative responses
Here are the most effective methods to bypass caching:
# Basic query bypassing resolver cache
dig @ns1.example.com example.com +norecurse
# Full authoritative trace (bypasses all caching)
dig example.com +trace
# Force TCP connection (some caching resolvers only cache UDP queries)
dig example.com +tcp
# Disable the RESOLVER cache specifically
dig example.com +nocookie
For complex scenarios, combine multiple flags:
# Query specific nameserver directly via TCP with recursion disabled
dig @ns1.example.com example.com A +tcp +norecurse +nocookie
# Bypass local resolver completely
dig @1.1.1.1 example.com +short
When debugging a new MX record that won't propagate:
# Step 1: Check authoritative servers
dig NS example.com +short
# Step 2: Query each authoritative server directly
for ns in $(dig NS example.com +short); do
dig @$ns example.com MX +norecurse;
done
# Step 3: Verify TTL values
dig example.com MX +ttlunits
- Some public DNS resolvers (like Cloudflare) may ignore +norecurse
- Root hints may still be cached in your local resolver
- DNSSEC validation can add additional caching layers
When making DNS changes, we often need immediate verification without waiting for TTL expiration. The default behavior of dig
(and DNS systems in general) is to return cached responses when available, which can be frustrating during DNS troubleshooting or zone updates.
The most effective way to force fresh DNS resolution is by using these dig
options:
dig +nocache +norecurse example.com
Or alternatively:
dig +trace @8.8.8.8 example.com
The +nocache
flag prevents dig from using its own cache, while +norecurse
tells the DNS server to answer authoritatively without querying other servers. For the most authoritative response:
dig @ns1.example.com +norecurse example.com
When testing a new A record:
dig +nocache +norecurse @ns1.mydomain.com newsubdomain.mydomain.com A
For checking immediate MX record changes:
dig +nocache mydomain.com MX
If you're still seeing cached results, try these approaches:
# Using TCP instead of UDP
dig +tcp example.com
# Querying different public DNS servers
dig @1.1.1.1 example.com
dig @9.9.9.9 example.com
For scripting purposes, you might want to combine these flags:
#!/bin/bash
FRESH_RESULT=$(dig +nocache +norecurse +short $1)
echo "Fresh DNS result: $FRESH_RESULT"