Complete and step-by-step guide to flushing DNS
Easily clear your DNS cache on Windows, macOS, Linux, and various browsers with this comprehensive guide.

راهنمای کامل و قدم‌به‌قدم پاک‌سازی کش DNS

In this article, we will explore different ways to flush DNS cache on Windows, macOS, and Linux operating systems. With step-by-step instructions, you can easily resolve DNS connectivity and security issues.
0 Shares
0
0
0
0

 

Why is it necessary to clear the DNS cache?

Flushing the DNS cache is a simple but important operation to resolve domain naming issues. Here are the main reasons:

  • DNS record change propagation: After changing A, CNAME or other records, the local client may still point to the old IP.
  • Fix DNS hijacking or cache poisoning: Clearing the cache can thwart simple attacks.
  • Instant connection problems: After a server migration or infrastructure change, it is sometimes necessary to clear the local cache.
  • Troubleshooting latency and routing: For traders and gamers, incorrect DNS may cause a connection to the wrong server or CDN.

 

Windows: Step-by-step and practical commands

Windows 10 / 11 (fastest method)

  1. Open Command Prompt with admin access:
    • Start → cmd → right-click → Run as administrator
  2. Run the flush command:
ipconfig /flushdns

To check the contents of the cache (optional):

ipconfig /displaydns

Explanation: Order ipconfig /flushdns Clears the DNS Client service cache. If you are using a local resolver like unbound or dnsmasq, you will need to restart the relevant service.

Restart the DNS Client service (in certain circumstances)

If the problem persists, you can restart the DNS Client service. In most cases, stopping this service is safe, but be careful on production servers.

net stop dnscache
net start dnscache

 

macOS: Commands by version

Different versions of macOS have different ways to clear the cache. Running the following two commands will suffice in most versions:

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

Note: In some older versions (OS X 10.10.4 to 10.10.10) of discoveryutil used; but running both commands above is the safest method.

 

Linux: Different distributions and resolvers

Linux has several possible resolvers and caches: systemd-resolved, nscd, dnsmasq, unbound etc. You should act based on the service.

systemd-resolved (common in new Ubuntu)

sudo systemd-resolve --flush-caches

In new versions, you can also use the following command:

sudo resolvectl flush-caches

To display statistics:

systemd-resolve --statistics

nscd

sudo systemctl restart nscd

Or in some distributions:

sudo /etc/init.d/nscd restart

dnsmasq

sudo systemctl restart dnsmasq

unbound

To clear the cache of a specific zone or restart the service:

sudo unbound-control flush_zone example.com
sudo systemctl restart unbound

Containers and Docker

If the resolver is running inside a container, restart that container:

docker restart <container_id>

In Kubernetes with CoreDNS:

kubectl -n kube-system rollout restart deployment coredns

 

Browsers: Internal DNS and socket flushing

Many browsers have their own internal DNS cache; even after a system flush, the browser may still hold onto the old record.

Google Chrome / Brave / Edge (Chromium)

  • In the address bar, enter: chrome://net-internals/#dns And on "“Clear host cache”Click.
  • To close sockets: open chrome://net-internals/#socketsClose idle socketsFlush socket pools.

Note: In new versions of Chrome, net-internals sometimes changes; in this case, close the browser completely or clear the app cache.

Mozilla Firefox

  • Enter in the address bar: about:networking#dns And on "“Clear DNS Cache”Click.
  • Or in about:config Amount network.dnsCacheExpiration Temporarily set to zero and then return to the original value.

Safari

Safari uses the system DNS cache, so just restart Safari after running the macOS commands.

 

Routers and ISPs: When the problem goes beyond the client

  • Physically restart the router or modem: The easiest way to clear your router's DNS cache.
  • Check the router's DNS resolver: In the admin panel, there is sometimes an option to Flush DNS or Restart DNS.
  • Using public DNS for testing: 1.1.1.1 (Cloudflare), 8.8.8.8 (Google), or 9.9.9.9 (Quad9).
  • In case of routing or CDN issues, it may be necessary to check the BGP route and CDN settings.

 

Verification

nslookup and dig

To check if your resolver has returned the new record, use the following commands:

nslookup example.com
dig +trace example.com
dig example.com @8.8.8.8

Ping and traceroute

To see the destination IP and network route:

ping example.com
traceroute example.com
tracert example.com

To check propagation in global locations, you can use online tools like whatsmydns.net Use.

 

Use Cases and Scenarios: Special Tips for Different Audiences

WordPress and website administrators

  • Before changing IP or migrating site, reduce TTL (e.g. to 300 seconds) to make propagation faster.
  • After applying the changes, clear the cache on servers, CDN, and browsers.
  • If you are using DNSSEC, check that the signatures are set up correctly to avoid errors.

DevOps and Network Administrators

  • In cloud infrastructures with load balancers and CDNs, immediately after a record is changed from dig Use to check TTL.
  • For latency-sensitive services, use resolvers close to the server location or take advantage of internal DNS with a high SLA.
  • In Kubernetes, after changing services, check CoreDNS and restart if necessary.

Traders and gamers

  • If your trading or gaming VPS is pointing to an old IP, first flush the DNS of the client and browser.
  • Choosing a nearby location and using dedicated trading/gaming VPS servers can improve ping and connection stability.

Artificial Intelligence and GPU Cloud/Rendering

  • After changing infrastructure (e.g. migration), flush the client DNS cache and any local resolvers to connect to the correct node.
  • Using internal DNS in private cloud networks (private DNS zones) and managing TTL helps you have more controlled propagation.

 

Security and professional tips

Additional security tips:

  • Activation DNS over HTTPS (DoH) Or DNS over TLS (DoT) It can prevent simple eavesdropping and hijacking.
  • Use of DNSSEC Recommended to ensure the authenticity of records.

 

Best practices and recommendations

  • Before changing the DNS record: Reduce the TTL to a short time (e.g. to 300 seconds) and then increase the TTL after confirmation.
  • Use high-SLA, multi-resolver DNS for critical services.
  • For enterprise users, provide internal guidance for flushing DNS on common systems.
  • In cloud infrastructure, use internal DNS and private zones for internal services and leverage CDN and BGP for traffic distribution.

 

Technical services and support

We are with more than 85 global locations, Dedicated Servers, VPS for trading and gaming, GPU for AI and rendering, Anti-DDoS servers, CDN, and BGP solutions are ready to provide a low-latency and stable experience.

The technical team can assist in the following cases:

  • Checking propagation from different locations
  • Suggest the best resolver and TTL settings
  • Help setting up private DNS or managed DNS
  • Providing CDN/BGP solutions to reduce latency and increase availability

 

Summary and Conclusion

Flushing the DNS cache is a simple but crucial task in network troubleshooting and management. On Windows, macOS, Linux, and browsers, a quick run of the following commands will usually fix the problem.

If you need to check propagation from multiple locations or help with setting up DNS for sensitive servers, the technical team is ready to provide assistance and advice.

 

Frequently Asked Questions

You May Also Like