Home is where the host file is in OS X.


Sometimes we web developers like to edit our websites locally, and then test them on our local machines before we push them out to the internet. On occasion, we use applications like MAMP Pro to help us do these sorts of things, but frequently we have a hiccup or two along the way. This happened to me today so I thought it would be beneficial to talk about the HOST file on our machines.

Essentially the file links the IP address of the internet server to the actual hostname (URL) we’re looking for. Modern browsers and internet connection use DNS to take care of this problem, but HOST files still have great value locally. Essentially we can override our DNS information and force a particular IP address to load a certain website locally instead of having to connect to the internet.

This works out well for web developers. For instance, when I want to do work on this website, I could do it on the fly and affect everyone’s experience, or I can have Macgasm.net redirect to a particular location on my desktop so that when I type the address into my url bar in a browser the files are being grabbed from my desktop instead of the web server on the internet.

MAMP Pro lets me do this without having to open the terminal, but it also choked on itself tonight and refused to remove the redirect when I told it to. This is where the terminal was a great help.

You host file is located at:


In order to edit it in the terminal I typed the following:
sudo nano /private/etc/hosts

This brings up the text editor in the terminal and lets you edit what you need. In my case I needed to delete a line, but you might want to add a line to have your information sent from a particular location. You can type on a new line at the end of the file. websitename.com

Followed by control+c then ‘y’ for yes to save the file. This will look on your system for websitename.com instead of jumping out onto the internet to get it. When you’re done with that, and you need to be able to get back to the site on the internet you simply remove that particular line of code and save the file again. Voila!

Comments are closed.