How to Edit Hosts file in Mac OS X 10.10 Yosemite

The hosts file is used by your computer to map hostnames to IP addresses.

By adding or removing lines to your hosts file you can change where certain domains will point when you access them in a browser or using other software. You can block certain hosts names, like ad-serving/malicious hosts, or used for web development purposes, i.e. to redirect domains to local addresses.

This is an important file and one that is under the computer administrator’s control, so you’ll need an account with full privileges to make any changes.

Making a backup of the hosts file can be a good idea if you plan on making significant changes or just want to play around with modifications and see what happens.

Step 1: Launch Terminal, found in /Applications/Utilities/ or launched through Spotlight

Step 2: Type the following command at the prompt to backup hosts file to documents folder:

sudo cp /private/etc/hosts ~/Documents/hosts-backup

Step 3: Type the following command at the prompt to open hosts file:

sudo nano /private/etc/hosts

Step 4: Enter the administrator password when requested, you will not see it typed on screen as usual with the command line

Step 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

Step 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