← All writing
 ·  1 min read

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

Quick command line aliases for editing the hosts file and flushing DNS cache on macOS.

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:

bash
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.