Changing the Hosts File

There are several steps that occur when you go to a website. One of the first things that happens is a DNS query to the websites Nameservers. This works much like looking up a phone number for a business in a phone book. What many people don’t know is that each computer has it’s own “Nameserver” that it queries before looking to the websites Nameservers. This is called your computers “Hosts File”. This allows you to define your own IP addresses for domain names and view them from your computer. This is helpful when you are developing websites and need to view the new site by using the domain name. It may sound complicated at first – but after completing this tutorial things should become more clear.

Steps to Change the Hosts File

  1. Locate your hosts file.
    • The location of the hosts file depends on the Operating System that you are using.
      • On Linux and Unix systems, like Mac OSX, the hosts file is located at the following path: /etc/hosts
      • On Windows XP the hosts file is located at: \WINDOWS\system32\drivers\etc\hosts
  2. Open your hosts file with a text editor
    1. On Linux and Unix systems, like Mac OSX, you can use this command to open the hosts file: sudo vi /etc/hosts
      • You will need to enter your root access information to edit this file.
      • See this tutorial for help using VI: http://www.unix-manuals.com/tutorials/vi/vi-in-10-1.html
    2. On Windows XP simply open the file with Notepad.
  3. Insert the following line:
    • IP Address www.yourdomain.com
      1. For example to set the domain: www.hostfiletestdomain.com to go to Googles IP we can insert this line: 74.125.127.106 www.hostfiletestdomain.com
      2. Now when we go to www.hostfiletestdomain.com we should see the Google homepage.
  4. Save the file.

You may have to wait a little while before the changes take affect – however in most cases the changes are pretty much instantaneous.

NOTE: Always remember to remove the entries from your host file after you are done using them.