If the internet connectivity on your Macintosh computer has been creating trouble lately, it just might be something with the ‘Hosts’ file. Not many people are familiar with, especially the non-techie ones wouldn’t know what this file is and what it does. Well basically the Hosts file is a text file keeping track of hostnames to specific IP addresses.

edit hosts file on mac

How to Edit Hosts file on Mac OS X?

This file contains necessary data to map the specific hostnames to their respective IP addresses – consists of both public and private DNS servers. Editing a Host file on Mac OS X would allow users to point the user towards a specific web site while a web address is put on the address box, or block the website from being accesses on a certain Apple Mac computer. This little text file actually holds a major control over internet access.

DNS is the most widely used system to fetch an IP address for the website address a user requests. On every other computer, Macintosh computers also work the similar way and the associated cache helps fetching the DNS data when an address is requested. However, there’s an alternate way that can tweak the way an Apple computer running Mac OS X would approach DNS servers. The information are written on a text filed, this text file is named Hosts file and it’s usually opened and edited in TextEdit.

How to Edit Hosts File With TextEdit

Step 1: Open Finder and select Go -> Go to Folder.

Step 2: Enter /private/etc/hosts

edit hosts file mac textedit

Host File location on Mac OS

Step 3: Copy the hosts file to your desktop.

Edit Hosts Mac

Find and edit hosts file Mac OS

Step 4: Double click to edit the hosts file from your desktop.

Step 5: Enter the IP address and the website you want to block.
For example: www.facebook.com

Edit Hosts Mac OS X

Edit hosts file on Mac using Text Editor

Step 6: Save the file. Now replace it with the original file located in /private/etc/hosts

Now you can start your browser to test the changes.

There are few very practical uses of the Hosts file. Especially for website developers who would need to access publicly unavailable websites for testing purpose, could just utilize the Hosts file. Before the website’s DNS goes online, the developer could just use the domain name and associate it with the Hosts file by editing it.

Edit the Hosts File using Terminal & Nano Editor

Another useful purpose is to block annoying adwares or a specific domain name without using any third party apps.

To edit a text file of this category, the best app on Mac OS platform is Terminal. However you can edit the hosts file thanks to the Nano editor. The app is already provided inside the Utilities folder, hence no additional download or purchase from app store would be required. However, in case you want to edit the Hosts file to be using with unpublished web sites or blocking a domain, you need to know the respective IP addresses and/or the domain names.

This is how you could edit a Hosts file on Mac OS X using terminal:

Step 1: Find your way towards Terminal. Open Utilities folder and it should be chronologically ordered.

Step 2: To open the Hosts file, type the following command:

sudo nano /etc/hosts

Notice the spacing in between the words. Hit Return.

Edit Hosts File Mac

Edit hosts file on Mac using Nano Editor

Step 3: If the command line above is typed in correctly, Terminal would ask for the Admin password.

Step 4: Hosts file is now open on the Nano text editor. Now you can edit the Hosts file as you wish.

Step 5: When done, save the file. However, it’s wise to keep a backup of the file before you make any changes, in case anything goes wrong.


Even though it’s sort of an in-depth task to do, we hope this guide will seem easy to our readers.

Last Updated:
Previous article5 Ways To Increase Battery Life on Apple Watch
Next articleHow to Remotely Erase your iPhone or iPad via iCloud
Stephan Popov
When iDevice users experience problems with the iOS software or unlocking, it is not uncommon for their lives to unravel. My passion is providing answers to your problems. I help iPhone, iPad and iPod Touch users by recommending fixes for common iOS bugs and tools that improves your experience. I conduct in-depth research for every topic i cover on this blog, to ensure that I cover everything Apple users need to troubleshoot their issues. When not writing for UnlockBoot, i enjoy swimming in my backyard pool. P.S. i prefers the Maldives for holidays. Connect with me on Facebook, Google Plus and Twitter.