Need to edit or modify the hosts file on a Mac? You’ll find hosts in Mac OS X is stored at /private/etc/hosts but it can also be accessed at the more traditional location of /etc/hosts. That said, if you’re looking to edit hosts, you’ll want to target the file located in /private/etc/ though. We’ll walk through how to manually edit the hosts file in OS X Lion, OS X Mountain Lion, and OS X Mavericks, this will be done with the command line using the simple text editor called nano. Don’t let the command line or Terminal sound intimidating though because it’s not, we’ll make the entire process super easy.
- Let’s get started making some edits to /etc/hosts!
- Launch Terminal, found in /Applications/Utilities/ or launched through Spotlight
- Type the following command at the prompt:
sudo nano /private/etc/hosts
- Enter the administrator password when requested, you will not see it typed on screen as usual with the command line
- Once the hosts file is loaded within nano, use the arrow keys to navigate to the bottom of the hosts file to make your modifications
- When finished, hit Control+O followed by ENTER/RETURN to save changes to /private/etc/hosts, then hit Control+X to exit out of nano
- Quit out of Terminal when finished
You can verify your hosts modifications immediately with ping, Safari, or any other network app. Changes take effect immediately though some adjustments may need to be accompanied by aDNS flush which can be done with the following command in OS X 10.9:
dscacheutil -flushcache;sudo killall -HUP mDNSResponder