Editing hosts file quickly using the command line or an app on macOS

For the longest time, I used the Hostbuddy for Mac app to edit my hosts file and flush my local DNS cache. I still recommend the app to anyone who wants to edit their hosts file on Apple’s operating system using a GUI. However, I have recently started using the command line in conjunction with VS Code.

To edit the hosts file on macOS I added the following commands to my .zshrc file:

alias hostsedit='sudo code /etc/hosts'
alias hostsflush='sudo killall -HUP mDNSResponder; echo DNS Cache Reset'

These two commands let me edit and flush my hosts file’s modifications to my local machines DNS without much effort.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.