The "hosts" file contains a list of IP addresses and host names. This list takes precedence over the values which are normally looked up using the Domain Name Service (DNS).
This can be handy if you want to:
- override DNS in order to test a development copy of a new web application, or
- need access to a new server when normal DNS records have not yet propagated.
This can also be a problem if you forget later that you have essentially hard-wired an IP address to a name. You may need to delete an entry if changes are made to your IP address due to network restructuring or if you move a server.
It is usually best to NOT use the hosts file and let DNS provide lookups.
A typical hosts file has the following structure. Note that you can assign more than one host name to an IP address. You can also have multiple line entries for the same IP address. Put a # at the beginning of a line to disable that entry.
184.108.40.206 www.mysite.com mysite.com secure.mysite.com
Since the hosts file is so powerful, you need elevated access permissions to edit it. See the instructions below.
Unlike DNS, changes made to your hosts file take effect immediately when the file is saved.
Changes to your hosts file affect only your own computer.
Microsoft Windows Users
The hosts file is located at:
You will need to run Notepad as Administrator so do the following.
1. In the Start menu, type "notepad" in the search box (don't hit enter)
2. RIGHT click on Notepad that appears in the search results and select "Run as administrator".
3. Select "Yes" in the popup dialogue to give Notepad permission to edit system files.
4. In the Notepad menu select File -> Open...
5. In the bottom right corner change "Text Documents" to "All Files"
6. Navigate beginning at "Local Disk C:" and work down through the directory structure:
Windows -> System32 -> drivers -> etc
7. Select the hosts file
8. Click "Open"
9. Make the desired changes to the file. Note that lines beginning with a # are comments or disabled entries.
10. In the Notepad menu select File -> Save to save your changes.
That's it, you're done. You can close Notepad.
The hosts file is located at /etc/hosts
To get root access and access the vi editor, from a terminal window type the command
sudo vi /etc/hosts
If you are totally new to vi, hit the "i" key to enter input mode.
Use the arrow keys to navigate around the file.
Enter, delete or modify your IP records in the file.
Type <ESC>:wq when you want to save the file and exit vi.
(Hint: <ESC> is the escape key)
That's it, you're done. You can close the terminal window.