How To Edit Hosts File in Mac OS

The hosts file is one of the important network files of any operating system. We all know about DNS, which maps I.P. address to a domain address. For example, when you type dollarmind.com.ng in your browser URL, your internet connection queries DNS system of your I.S.P. to find the I.P. address and thus serve website in your browser.

This also brought the concept of Public DNS, which I have already discussed in detailed earlier (Using Google DNS to speed up The internet). Similarly, Hosts file is for your local computer.

You can add custom detail in your Hosts file, and before checking DNS, your system will check operating system hosts file for any reference. For example, if you add Google.com I.P. address for Facebook.com domain in your OS Hosts files, when ever someone will type Facebook.com in the browser URL, Google.com will be open in the browser. (A great idea for prank too). Anyways, I will not get into detailed explanation of DNS and Hosts files, but if you are interested to learn these basics (you should)

Editing Hosts file in Mac using Nano:

At the time of writing this article, I’m using Mac 10.8.4, and whenever I try to edit the hosts file using Text editor, I see the Locked error. I couldn’t find any option to unlock the Hosts files, and edit it using Mac Text Editor. Here is the error that I got, while trying to edit hosts file:

You don’t own the file “hosts” and don’t have permission to write to it.

This is the default location of hosts files in Mac OS X:

/private/etc/hosts

And, here is the way to edit the file. Open terminal and type this command:

sudo nano /private/etc/hosts

And it will ask your system password once you enter the password, you will see a screen like this:

Nano is the terminal editor, and if you wish to learn all the commands of this editor, here is a handy reference. Now, use your cursor to move, and edit the hosts files according to your requirement. Once you are done making changes, click on

  • Ctrl+ 0 : Click Enter after that. (This will save your output)
  • Ctrl + X: This will exit the Nano editor.

Update: You can download this Mac app call Gasmasks to edit hosts file quickly.

It took me 15 minutes to find the solution to locked hosts files issue in Mac, and I hope this article will save your precious time. If you are still stuck or have any question, feel free to ask me via comments. Do check out our other articles on general-tech, and you will learn something new today.

Remember to make use of your share button. Ask your questions through the comments section and please follow us on our Official instagram and Facebook page.

Leave a Comment Cancel Reply