MacOS: Flush DNS Command
How to easily clear your DNS cache in MacOS
How to clear your DNS cache in MacOS
As a power user, I find myself trying out different hacks in order to optimize my webflow. Part of it is implementing DNS filtering in my local network to not only block ads but also to block malicious domain and other malware.
Thus, started my quest to find an easy way to clear my DNS cache, so I found this this command from an easy Google search. Easy enough, right?
However, this introduced another problem - I now have to either save this command as a snippet or remember to have it within my terminal history to autocomplete it. I was hoping there was a way to make this command more accessible to me.
Fortunately, there was a way to do this via my Spotlight replacement: Raycast. Creating a quick workflow using a custom extension (Script Command) was easy enough using the terminal command, and using that became a breeze and quickly became ingrained to my muscle memory.
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Flush DNS
# @raycast.mode compact
# Optional parameters:
# @raycast.icon 🌐
# Documentation:
# @raycast.description Flush DNS Cache
# @raycast.author reddiedev
# @raycast.authorURL https://raycast.com/reddiedev
osascript -e "do shell script \"sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder\""
echo "DNS Cache Flushed"
Unfortunately, it was much later that I found that there already was an extension for this feature in Raycast. Still, I enjoyed the process of making my own, as this allowed me to learn more about the scripting language and customizing my own developer environment to suit my needs. This, along with future commands that I will be making, will be added to my Github for easy access when I change devices whenever I need to.