dns,

How to flush the DNS cache from the CLI

Feb 25, 2022 · 1 min read · Post a comment

Clearing the DNS cache usually fixes issues related to not resolving new or updated existing domain records. Let’s see how it’s done from the command line though.

Prerequisites

  • Shell environment
  • sudo privileges

Linux

sudo systemd-resolve --flush-caches

sudo resolvectl flush-caches

Note(s): The commands above are related to Ubuntu-based distros, and for the rest try with one the following alternate commands:

sudo /etc/init.d/dns-clean start
sudo /etc/init.d/nscd restart
sudo /etc/init.d/dnsmasq restart

macOS (Monterey)

Open Terminal and run the following command:

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

Note(s): If you are not using the latest version of macOS (Monterey) as of the writing, just execute the second one.

Windows

Open CMD or PowerShell and run the following command:

ipconfig /flushdns

Conclusion

Nothing much to add to be honest, but if you got something please leave a comment below. On a side note, follow our official channel on Telegram.