- slide 1 of 5
The goal of this article is to help you edit the hosts file. In order to effectively do this, you must know what you are doing and why. To achieve this goal, we will cover the following topics:
- What and where is the hosts file
- Editing the hosts in Windows 2000 and XP
- Editing the hosts file in Windows Vista and Windows 7
- slide 2 of 5
What and where is the hosts file
The hosts file is an IP address-name mapping text file that your computer uses to resolve computer names to network IP addresses before using DNS (Domain Name System). At the very minimum, a name-IP address mapping is simply a line in the hosts file that specifies the IP address of a machine, followed by at least one space, then followed by the name of the machine. You can have one or more IP address-name mappings.
In mosts cases, the hosts file just contains an IP address-name mapping for the computer's loopback address--127.0.0.1 which is mapped to "localhost". In Windows Vista and Windows 7, an additional IPv6 loopback address is added ("::1" followed by a space, then "localhost"). Specifically, the hosts file contains these lines:
::1 localhost #this only shows up in Windows Vista and Windows 7
Notice that you can add comments immediately one space after the host name specification by preceding it with the "#" character.
Say for example you have a media server at home, and you've set it to statically use the IP address 192.168.0.15. In the hosts file, you will need to simply add another line, and in it put:
192.168.0.15 mediaserver #this is my home media server
Once you save the hosts file with this new entry, you can access your media server by name--mediaserver. For example, if it has a web interface and you manage it using Internet Explorer, you simply browse to it using http://mediaserver in the address field of the browser--whereas before, you would use http://192.168.0.15.
Starting from Windows 2000 and all the way to Windows 7, the default location of the hosts file is c:\windows\system32\drivers\etc.
- slide 3 of 5
Editing the Hosts file in Windows 2000 and XP
The hosts file in Windows 2000 and XP can easily be accessed by any account that has local administrative rights. Using Windows explorer, navigate yourself to c:\windows\system32\drivers\etc. Once you are there, right click on the hosts file and select Open With from the menu. When the list of programs show up, select the Notepad program.
With the hosts file open, you can begin making changes to it. As soon as you are done, you simply save the changes, close Notepad, and you are done!
- slide 4 of 5
Editing the Hosts file in Windows Vista and Windows 7
Since the release of Windows Vista, access or changes to certain key system resources cannot be done without first confirming that it is what you want to do, nor can you modify configuration files without explicitly running an application as administrator. With this in mind, in order to modify or edit the hosts file in Windows Vista or Windows 7, you will need to run Notepad as administrator. To do so, you need only find the notepad shortcut in the Accessories folder and right click on it, then select Run as administrator.
Once Notepad launches, select File, then Open. Navigate to the hosts file path (typically at c:\windows\system32\drivers\etc), then select the hosts file. Make your changes, then save your changes. After you save your changes, you may close Notepad. Changes you make take effect immediately.
- slide 5 of 5
If you wish to reference your home computers by name in your home network, then simply locate the hosts file, open it with Notepad, add your IP address-name mappings (one per line), and save the file.
On Windows Vista and Windows 7, you will need to first launch Notepad as administrator, then and only then will you be able to modify and save changes to the hosts file.