How to edit the hosts file on Mac OS X

Your Mac’s hosts file is a small, but important text document that has the ability to map hostnames to specified IP addresses. Although the modern internet uses a variety of public and private DNS servers to map IP addresses, the hosts file is a handy way to override those DNS servers, allowing you to manually point a website address to a any IP address.

Edit Your Mac Hosts File with Textedit application:

You need to copy the file to an unprotected location, like the desktop, edit it, and then copy it back.

To find the hosts file, open Finder and, in Finder’s menu bar, select Go > Go to Folder. In the box, type the following location and press Return.


To edit the file, you’ll add your own lines after broadcasthost.

If you want to block Facebook you can add which, as an invalid IP address, will result in an error.

Then, drag and drop the hosts file from your desktop back to its original location at /private/etc and replace.

If you need to flush your DNS cache because the site isn’t loading.

sudo killall -HUP mDNSResponder

For OS X Mavericks, use this command instead:

dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Edit Your Mac Hosts File In Terminal With Nano:

To get started, launch Terminal, type the following command, and press Return. Which will ask for the admin password

sudo nano /private/etc/hosts

You’ll now see the hosts file open in the Nano editor. To navigate and edit the file, use the arrow keys on your keyboard.

When you’re done making changes, press Control-X to exit the editor, Y to save, and Return to overwrite the existing hosts file. Flush DNS cache if needed as above.

If you haven’t made a backup of your hosts file the default is something like this:

# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##                                    localhost                        broadcasthost

::1                                                  localhost
fe80::1%lo0                                localhost


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s