WEB HOSTING What is a HOSTS file and how do you edit it?
What is a HOSTS file and how do you edit it? Article ID:213

The HOSTS file on your Windows PC is used by Windows as a place to lookup hostnames for IP addresses before checking DNS.  Let's explain:

When you need to go to www.somedomain.com, your computer needs to actually "resolve" that name to an IP address... i.e., what is the IP address of the server that is hosting www.somedomain.com.    To resolve that IP address, your system will FIRST look in your HOSTS file, which is simply a text file with a list of hostnames mapped to IP addresses.  Typically, it's empty, as it's just there for specific purposes.  When www.somedomain.com isn't found there, then your computer will check with your ISP's DNS servers (ISP = Internet Service Provider).

As you can see, because your computer checks in this order, hosts file first, then DNS servers, if you put an entry in your hosts file, you can effectively override what is in DNS.  A neat trick that's helpful sometimes in troubleshooting, or publishing a site with FrontPage before DNS is actually pointing to the right IP address.

To edit your hosts file, follow these steps:

  1. Open Windows Explorer on your system
  2. Navigate to c:\windows\system32\drivers\etc
  3. Find the file named "hosts" (it has no file extension), and double click it.
  4. Windows will ask you if you want to open it and what to open it with, choose to open it with Notepad (notepad.exe).
  5. Once the file is open, you can add the necessary lines.  If our support team is asking you to modify your hosts file, they will provide you the exact line to enter.  The line will be in the format of:
    • 1.1.1.1 somedomain.com
    • 1.1.1.1 somedomain.com ftp.somedomain.com www.somedomain.com
    • where "1.1.1.1" equals the ip address you need to point to and "somedomain.com" is the hostname you need to map/resolve the IP to.
  6. Important notes when editing a hosts file:
    • make a backup copy first, so you can quickly restore if you need to.
    • the IP address and the first hostname should be seperated by at least one space... it can be more than one, but should be at least one.
    • you can list multiple hostnames on the same line for a single IP address.
    • make sure there's at least one blank line at the end of the hosts file.
    • remember to either remove the entry or restore your orignal hosts file once you're done with whatever your testing.
    • your browser will cache DNS information and needs to be cleared by closing your browser, so the process would really go like this:

      • close all instances of your browser
      • edit your hosts file to point the domain to the new/test server
      • open your browser, go to your domain (you should be accesssing the site at the IP in your hosts file entry)
      • finish testing, close all isntances of your browser 
      • edit your hosts file to remove the entry (or comment it out). 
      • open your browser, go to your domain (you should be accessing the site at the original IP active in DNS)
      • You can switch back and forth like this as much as you need.
Downloads associated with this article:
  No downloads associated with this article
Back to Search or Browse