The HOSTS file on your Windows PC or MAC is used by the operating system 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 on a Mac:
Please refer to this article: http://knowledge.3essentials.com/web-hosting/article/1313/How-To-Edit-HOSTS-file-on-Mac-OS-X.html
To edit your hosts file on Windows, follow these steps (VIDEO BELOW):
Open Windows Explorer on your system
Navigate to c:windowssystem32driversetc
Find the file named "hosts" (it has no file extension), and double click it.
Windows will ask you if you want to open it and what to open it with, choose to open it with Notepad (notepad.exe).
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:
188.8.131.52 somedomain.com ftp.somedomain.com www.somedomain.com
where "184.108.40.206" equals the ip address you need to point to and "somedomain.com" is the hostname you need to map/resolve the IP to.
- 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.
- NOTE for Windows Vista and Windows 7 users:
By default, if you try to modify your host file in Vista, it will not let you save it. It tells you that you don't have permission. To successfully modify the hosts file, run notepad.exe as an administrator and open the file.
- Browse to Start -> All Programs -> Accessories
- Right click "Notepad" and select "Run as administrator"
- Click "Continue" on the UAC prompt
- Click File -> Open
- Browse to "C:WindowsSystem32Driversetc"
- Change the file filter drop down box from "Text Documents (*.txt)" to "All Files (*.*)"
- Select "hosts" and click "Open"
- Make the needed changes and close Notepad. Save when prompted.
- NOTE for MAC users:
- The following may or may not work on all versions of the MAC OS... if it does not, please consult your MAC OS documentation for how to edit the HOSTS file.
- Open Finder.
- In the Go menu, select "Go to Folder"
- Type /etc for the folder name.
- In the list of files that appears, you should find hosts. Make a backup copy of the hosts file first. Then, double it to open it in a text editor (the hosts file, not your backup copy) .
- add the hosts file entry provided by the support team as a new line to the file and save it.