Flush DNS cache in macOS using the Terminal


Run these three commands to flush your DNS cache from your macOS Terminal

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Make it easier by putting a shell script in your $PATH

  • Create a file flushdns somewhere in your $PATH (in my case ~/bin was added to my path)

  • Add the following and save the file

#!/bin/bash
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
  • Make it executable with chmod +x flushdns

Now you can just execute flushdns anywhere in your Terminal