
How to Clear DNS Cache on Linux (Easy Steps)
If you’re using Linux and some websites are not loading properly or showing old pages, it might be time to clear your DNS cache. Think of the DNS cache like a mini phonebook on your computer. It remembers websites you’ve visited and connects names like www.google.com to their real addresses like 142.250.183.78.
But sometimes this memory gets old or broken, and that can cause problems. Clearing the DNS cache helps your computer get fresh information from the internet.
What is DNS Cache?
When you visit a website, Linux stores the address in a DNS cache to help load it faster next time. But if a website changes its IP address or moves, the stored data becomes wrong. That’s why clearing the cache helps fix loading or connection issues.
Do All Linux Systems Use the Same DNS Cache?
No, different Linux systems use different services to store DNS data. The most common ones are:
- systemd-resolved
- dnsmasq
- nscd (Name Service Cache Daemon)
- BIND (named)
How to Clear DNS Cache (Step-by-Step)
1. If your system uses systemd-resolved (most modern Ubuntu versions):
Steps:
- Open the Terminal.
- Type this command and press Enter: sudo systemd-resolve –flush-caches
- (Optional) To check if it’s cleared, type: sudo systemd-resolve –statistics
2. If your system uses dnsmasq:
Steps:
- Open the Terminal.
- Type: sudo systemctl restart dnsmasq
This will restart the service, which automatically clears the DNS cache.
3. If your system uses nscd:
Steps
- Open the Terminal.
- Use this command: sudo /etc/init.d/nscd restart OR sudo service nscd restart
It will clear and restart the cache service.
4. If you’re usingBIND (named):
Steps:
- Open Terminal.
- Enter: sudo rndc flush
If you want to flush a specific domain, use:
sudo rndc flushname yourdomain.com
How to Know Which DNS Service You Use?
Use this command:ps aux | grep -E ‘dnsmasq|nscd|systemd-resolved|named’
This will show which service is running.
Bonus Tip: Clear Your Browser DNS Too
In some cases, your browser also saves DNS data, and you may need to clear major browser caches like Chrome, Firefox, or Safari to fully fix the issue.
For Chrome:
- Open Chrome.
- Go to this link: chrome://net-internals/#dns
- Click “Clear host cache”.
Related Guides You Might Need:
Final Thoughts
Clearing the DNS cache on Linux is a simple fix that can solve many internet problems. Whether a site is not loading or showing an outdated version, this quick trick can help.
It’s a safe process and doesn’t harm your system. If the problem continues, try restarting your browser or router too.
FAQs
Q. Is clearing DNS cache safe?
Yes, it’s completely safe and just removes old records.
Q. How often should I clear the DNS cache?
Only when you face internet issues like wrong website loading or connection errors.
news via inbox
Subscribe for Weekly Update





