Twitter Feed

Sponsors

Related Links

Change your etc hosts file

I don't work in Windows or Mac often so I always forget where the hosts file is located. The windows etc hosts file and unix etc host file both work the same, so usage is easy.

Here is a list to the locations of the hosts file on all popular operating systems.

Windows

c:\windows\system32\drivers\etc\

Linux

/etc/hosts

Mac

/private/etc/hosts

How to use this file

I don't use a seperate development machine for building websites, I use my own personal computer. When you work on more than one project at a time, you need more than just http://localhost/ url. To accomodate multiple projects you can change your /etc/hosts file and point it to your local machine. Here is an example:

127.0.0.1 dev.nickyeoman.com
127.0.0.1 dev.torrenttutorials.com

I prepend the dev subdomain to my domain names so that I never confuse the live site with my development site.

I do all my development work on Ubuntu desktop so when it comes time to test in IE, I change the hosts file in windows to point to my development machine. This way you can work on IE bugs on your local network without changing your dev servers. Something like:

192.168.0.100 dev.nickyeoman.com
192.168.0.100 dev.torrenttutorials.com

Matching Shared Hosting environment

Hosts is also useful to emulate your shared hosting environment. For example if you host uses a seperate domain for their database server [internal.db.hostingco.com] you can emulate the host on your development machine.

ISP DNS is slow

If your ISP is slow to update it's DNS records, it could be a few days before you or your client can see the new website. Again /etc/hosts can overwrite your DNS server and deliver the site from the correct server.

The uses for etc hosts really are endless.