ShoutMeTech

img

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 ShoutMeTech.com 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 file, 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 file, but if you are interested to learn these basics (you should), here are few articles for your reference:

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 file, 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.

Locked hosts file in Mac

This is the default location of hosts file 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 hosts file terminal editor

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 file 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 file 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.

Article by Harsh Agrawal

Harsh has written 159 articles.

If you like This post, you can follow shoutmetech on Twitter. Subscribe to shoutmetech feed via RSS or EMAIL to receive instant updates.


Comments on this entry are closed.

  • Rajjaiswal November 3, 2013, 2:55 pm

    I really appreciate this post thank you for sharing these type of posts. (:

  • Karolina January 31, 2016, 8:47 pm

    Great! I couldn’t to save any changes by pressing command key. I didn’t know what to do. Thank you so much!