The easiest way to edit a Hosts file on a Mac is to drop to the command line and enter the following command:
sudo nano /private/etc/hosts
First Open Terminal.app which is located under the Applications\Utilities folder in Finder.
Type the command as it appears above, and when prompted re-enter in your password. See Fig. 1 Note: You’ll need to be logged in with an account that has Administrator access.
Once you’ve opened the hosts file use the arrow keys to start a new line under your loopback adapters. You’ll enter hosts by typing in their IP Addresses, pressing tab, and then typing in their host names. Press enter to go to a new line after every IP address and host name combination. In Fig 2. you’ll see that I’ve added two hosts, host1 and host2.
When you’re done adding hosts and you’ve double checked the spelling and IP Addresses press Control and O at the same to to write-out, or save, the file. You’ll be prompted for a name and location for the file, keep the defaults and press enter. You’ll also be able to see this at the bottom of Fig. 2.
When you’re done saving the file press Control and X to exit the nano application and return to the terminal.
Now try a ping or some other method to make sure that you’re hosts file is working as expected.