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.

Join Dare To Code Email List

Get emails from me on full-stack PHP development by subscribing to the Dare To Code mailing list.