How to edit OSX host file

The hosts file in Mac OS X is stored at /private/etc/hosts but can also be accessed at the more traditional location of /etc/hosts. 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 and OS X Mountain Lion with the command line using the simple text editor called nano. If you’d prefer to avoid the Terminal, you could try the easier method of using a preference pane.
1. Launch Terminal , found in /Applications/Utilities/ or launched through Spotlight
2. Type the following command at the prompt:
3. sudo nano /private/etc/hosts
4. Enter the administrator password when requested, you will not see it typed on screen as usual with the command line
5. 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
6. 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
7. Quit out of Terminal when finished