Sometimes you may need to modify your hosts file, especially if you are trying to preview a name based site before dns propagation occurs. This entry details the steps you need to take to make the changes you need.
The hosts file is basically a shortcut for bypassing the standard DNS lookup that your computer would normally do to see where a website is hosted. For example, If you want to access a development version of your website to test it before going live, you can modify your hosts file to redirect only your computer to the delopment server.
The hosts file is a simple text file, and this contains IP addresses separated by whitespace (space, tab, etc) in UNIX/Linux or a single space (Windows) and then the domain name.
Here's an example:
The location of your host file depends upon your operating system. Here is a list of common operating systems and the location of the host file in each:
- Windows NT/2000/XP/Vista/Windows 7: c:\Windows\System32\drivers\etc\hosts
- Unix/Linux: /etc/hosts
- Apple: System Folder: Preferences
You will need administrator privileges to edit the hosts file in Windows, and root under most UNIX-like systems. Once you are logged in with administrator access, follow these steps to modify your hosts file:
1. Windows Start - find/search notepad. Right click on notepad and choose "run as administrator"
2. From within notepad choose "File - Open" and then browse to c:\Windows\System32\drivers\etc\hosts, click open.
3. You'll enter your IP and then domain name in the format like in the example above. There is a space in-between the IP number and domain name, and this is very important.
4. Save the file and then close, and re-open your internet browser.
To revert back how your host file was setup previously, simply remove your newly created lines/changes from the host file and then close and open your internet browsers.
The above steps are the same under UNIX/Linux using your text editor of choice and adjusting the path as mentioned earlier.
Please be careful not to change the following entries in hosts
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost