HomeLinuxDomainHow to Clear DNS Cache on Mac and Linux Systems

How to Clear DNS Cache on Mac and Linux Systems

Follow these comprehensive methods to clear the DNS cache on Mac and Linux devices, ensuring smoother network operations.

Method 1: Using Terminal

For Mac OS X:
  1. Access the Terminal: To start, locate the “Terminal” in your “Utilities” folder within “Applications” or use Spotlight (Cmd + Space) to search for it.
  2. Flush the DNS Cache: Open the Terminal and enter the following command, then press Enter:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

You’ll be asked for your admin password; input it and press Enter. Note that you won’t get a confirmation message, but rest assured, your cache is cleared. You may then exit the Terminal.

For Linux:

  1. Open a Terminal: Depending on your Linux distribution, access the Terminal through applications or by pressing Ctrl + Alt + T.
  2. Flush the DNS Cache: In the Terminal, use one of the following commands based on your Linux distribution:

For Ubuntu 18.04 and newer (with systemd-resolved)

sudo systemctl restart systemd-resolved

For older Ubuntu versions or those using nscd:

sudo /etc/init.d/nscd restart

For distributions with dnsmasq:

sudo service dnsmasq restart

If your distribution doesn’t have a specific DNS cache service, restart the networking service:

sudo service networking restart

Once executed, you may see notifications indicating service restarts, which means the cache has been flushed.

Method 2: Simply Restart Your Device

A straightforward way to ensure a cleared DNS cache for both Mac and Linux is to reboot your computer.

Method 3: Clean Your Browser Cache

Encounter DNS issues while online? Clearing your browser cache can alleviate website-specific challenges.

Method 4: Toggle Your Network Connection (Mac only)

  1. Click the network symbol in the menu bar.
  2. Choose “Turn Wi-Fi Off” or “Disconnect.”
  3. Wait a moment and then switch Wi-Fi back on or reconnect. This might help in refreshing the DNS cache.

Method 5: Opt for Alternative DNS Servers

Facing continuous DNS problems? Consider switching to other DNS servers, such as Google DNS or OpenDNS. This step might address your issues even if it doesn’t clear the cache.

“Final Note: According to industry best practices and expert consensus, clearing the DNS cache is usually diagnostic, not routine. For persistent network issues, consult a network specialist or your ISP for more guidance.”
~ Veeble Hosting
Scroll to Top