Support >
  About cybersecurity >
  Common methods for resolving DNS caching issues
Common methods for resolving DNS caching issues
Time : 2026-01-12 16:30:04
Edit : DNS.COM

DNS caching is designed to speed up and reduce server load, but it can cause problems when it "remembers too well" or "remembers wrong information." Don't rush to restart the server; try the following methods, which often resolve the issue more quickly.

First, confirm if the problem is indeed caused by DNS caching. A quick way to check is to use the `nslookup` or `dig` command on the server to directly look up the problematic domain name. For example, to look up "www.example.com", type `nslookup www.example.com` in the terminal. Carefully examine the returned results, especially the IP address after "Address". Then, immediately use an online, authoritative DNS lookup tool (such as Google's 8.8.8.8 or Cloudflare's 1.1.1.1) to look up the same domain name. Compare the two results; if the IP addresses are different, it's almost certain that your server's local DNS cache is storing outdated or incorrect records.

Once the problem is confirmed, it's time to clear the cache. Where to start clearing depends on your operating system and server environment. The most direct approach is to refresh the local operating system cache.

On Linux servers: Most Linux distributions now use systemd-resolved or NSCD to manage DNS caches. Refreshing them typically involves these two commands:

# If using systemd-resolved

sudo systemctl restart systemd-resolved.service

# If using nscd

sudo systemctl restart nscd.service

After execution, use `nslookup` to check if the IP address is now correct.

On Windows Server: The operation is also simple. Open a command prompt as administrator and type:

ipconfig /flushdns

If you see the message "DNS resolution cache successfully refreshed," you're done.

Often, clearing the local cache solves the problem. However, if you find that the problem recurs quickly after refreshing, or it doesn't work at all, you need to look further upstream.

Modern servers, especially cloud servers, rarely directly contact public root DNS servers. They typically first query their configured upstream DNS resolver, which might be provided by the cloud provider by default (e.g., Alibaba Cloud's 100.100.2.136) or a public DNS you manually configured (e.g., 8.8.8.8). These upstream resolvers also have large caches. If their caches have problems, simply clearing your local cache won't help. In this case, you can consider temporarily switching to a reliable upstream DNS in the server's network configuration. For example, on Linux, modify the `/etc/resolv.conf` file, temporarily changing the `nameserver` line to `8.8.8.8` or `1.1.1.1`, save, and then test. If the switch solves the problem, then the issue lies with the original upstream DNS service.

Another common scenario in enterprise or complex networks is caching by intermediate devices. Some firewalls, load balancers, or transparent proxy devices also cache DNS records to optimize traffic. If they cache incorrect records, it can affect an entire network of servers behind them. Troubleshooting this requires certain network privileges. You can log in to the management interface of these devices, check the DNS cache or proxy settings, and perform a refresh operation. If the device does not support refreshing, restarting the relevant service modules may be the fastest method.

If the above methods have been tried and the domain name resolution is still unstable, intermittently working, then more in-depth troubleshooting is needed. At this time, some diagnostic commands can be used to obtain more detailed information. For example, in Linux, using the `dig` command with the `+trace` parameter can display the complete iteration process of domain name resolution, helping you see at which layer the resolution has deviated or timed out.

`dig +trace www.example.com`

The output of this command will list the complete query chain from the root name server to the top-level domain (.com), and then to the authoritative name server, which is very helpful in locating where the resolution has been tampered with or interrupted.

When you suspect that some malware or network attack (such as DNS hijacking or cache poisoning) is causing cache abnormalities, checking the integrity of the server and network is important. Check if the server's hosts file (Linux: `/etc/hosts`, Windows: `C:\Windows\System32\drivers\etc\hosts`) has been maliciously modified. Also, check firewall rules such as iptables or firewalld for any unauthorized DNS port (port 53) redirection rules.

In the long run, to reduce the problems caused by DNS caching anomalies, you can proactively take the following measures:

1. Set a reasonable TTL: If you manage your own domains, setting a reasonable TTL (Time To Live) value in your DNS records is crucial. TTL tells the global DNS cache how long this record can be stored. For services that require frequent changes, don't set the TTL too long, such as 300 seconds (5 minutes), so that changes take effect globally faster. For very stable services, you can set a longer TTL to reduce query pressure.

2. Proactive refresh: Before planning any important domain migration or IP change, if possible, proactively contact or use the API to notify large public DNS service providers upstream to refresh the old records of your domain in their caches in advance.

3. Implement monitoring: Establish monitoring for domain name resolution of core business processes. A simple script can be used to periodically resolve domain names and verify the returned IP address; if incorrect, an alert should be issued immediately.

python

#!/usr/bin/env python3

import dns.resolver

import time

def monitor_dns(domain, expected_ip):

resolver = dns.resolver.Resolver()

# Multiple upstream DNS can be configured; here, we use Google and Cloudflare's public DNS.

resolver.nameservers = ['8.8.8.8', '1.1.1.1']

while True:

try:

answers = resolver.resolve(domain, 'A')

current_ips = [answer.to_text() for answer in answers]

if expected_ip not in current_ips:

print(f"[Warning] {domain} resolution error! Current IP: {current_ips}, Expected IP: {expected_ip} - {time.strftime('%Y-%m-%d %H:%M:%S')}")

else:

print(f"[Normal] {domain} resolved correctly - {time.strftime('%Y-%m-%d %H:%M:%S')}")

except Exception as e:

print(f"[Error] Error resolving {domain}: {e} - {time.strftime('%Y-%m-%d %H:%M:%S')}")

time.sleep(60) # Check every minute

if __name__ == "__main__":

# Monitor your own domain name and expected IP

monitor_dns('www.your-important-site.com', '203.0.113.10')

In short, don't panic when facing DNS cache anomalies. Start by clearing the local cache, and gradually check upstream DNS and network intermediate devices. Most problems can be located and resolved.

 

DNS Becky
DNS Luna
DNS Amy
Title
Email Address
Type
Information
Code
Submit