Edit the hosts file on the mac

Sometimes, you may need to edit the hosts file on the mac.

The hosts file is a file that controls the routing to websites, both localhost and other websites. For example, I can say that whenever I enter http://www.kensodev.com in the browser, the address is then traced back to 127.0.0.1 instead of going to the DNS server and lookup the address there.

This is a very efficient way to do testing to websites, so you don’t have to use localhost or everything. For example, I always use a local prefix to a website to identify it’s on my machine. http://local.kensodev.com will be the local version of this website and so on and so forth.

There are many cases where you might want to edit the hosts file. In mac it’s not that intuitive to find it like in windows so here’s a quick tip (I am using textmate bug you can use whatever you want).

To edit the file simply enter this command into the terminal:

sudo mate /private/etc/hosts

You will then be prompted to enter a password and after you edit the file and press save, you will have to enter the password again.

This is it, that is how you edit the hosts file on the mac.

<img src="http://feeds.feedburner.com/~r/KensoDev-en/~4/0zAHC3kD8aw" height="1" width="1"/>
Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com