Hosts file is a local file available as part of an operating system and used to map IP addresses corresponding to domain names. The browser then resolves the entered domain name into an IP address found in the hosts file before using browser’s DNS settings.
Why to Edit Hosts File?
There are two major need for users to modify hosts file.
- Eliminate the resolving host time through normal DNS resolution.
- Block certain domains by pointing it to local host IP address.
In both cases you need to create additional entries in hosts file and this article explains how to edit hosts file in Windows PC.
Step1 – Open Notepad in Administrator Mode
Click on the “Start” button located at lower left corner.
Right click on “Notepad” app and click on “Run as administrator” option.
Note: You can also use a shortcut “Windows Key + F” to “Search” for “Notepad” app. Right click on the “Notepad” and select “Run as administrator” option.
Step2 – Opening Hosts File
Once Notepad is opened in administrator mode click on “File > Open” from the menu.
Hosts file in Windows 8 is stored in the location “C:/Windows/System32/drivers/etc/”. Go to this path and open the hosts file in Notepad.
Note: Select “All Files” in the file name dropdown to view the files in the folder. By default hosts file may not be visible under file name as text documents.
Step3 – Modifying Hosts File in Windows 8
Add required entries in the hosts file and save the file.
Basics Rules in Modifying Hosts File:
- Though tab is used to separate IP and domain, a single space is sufficient between IP and domain name.
- Add each set of IP and domain in a separate line.
- Add domain and subdomains separately. For example, webnots.com, webnots.com and blog.webnots.com needs to be added as three separate lines though IP address could be same or different.
- Use # to add comments in the hosts file.
- Hosts file does not have any extensions, hence ensure to save the file as “All Files” type and not as a text document with .txt extension.
- After editing the hosts file, restart the computer for the changes to take effect.
Step4 – Blocking Sites Using Hosts File
Besides resolving the host name, you can also use the hosts file to block sites by pointing the domain to the localhost IP address. For example, add the following entry to block facebook.com from your computer:
Here, 127.0.0.1 is the IP address of the localhost for IPv4, in case of IPv6 it should be ::1.