How to Use the Windows Hosts File

The Windows Hosts file is a plain text (txt) file that your computer uses to map hostnames to IP addresses. Often times, users edit this file or download or obtain a new hosts file in order to block some known ad sites or other problematic sites. There are times that websites bombard you with unnecessary advertisements and all you want is to view a page. Also, you may download software accidentally from a harmful site and you may need to block a certain webpage. This is where editing the hosts file can help you.

How DNS and the Hosts File Works

Windows uses the hosts file for maintaining a personal list of web addresses. At the time when a URL request is made, the hosts file is usually checked first. In the case where a corresponding address is found in the hosts file, the user is directed to the IP address without consulting the DNS (Domain Name System) server. The DNS is the standard domain name resolution service that is used over the internet. In order for you to connect to a certain website, your PC needs to find the IP address of the website your are trying to visit. For you to get the IP address, the DNS is used for resolving the domain name for the mapped address.

The process is done through your PC querying its DNS servers that are configured. It asks these servers about the IP address that is using that domain name. In this process, the DNS server queries other servers over the internet until it is able to find the IP address of the website you are trying to visit. After the IP address is found, your PC is able to make a direct connection to the IP address.

Knowing how to use the hosts file is another way that you can use to resolve the domain names while not using the DNS. In every operating system which communicates through TCP or through the IP, which is the common communication over the internet, it has a file that is known as the Hosts file. This is the file that creates mappings between the IP address and the domain names. This text file contains IP addresses that are separated by at one space or more and a domain name for every entry on the line.

Potentially Increase the Speed of Browsing

By adding the IP address mappings of the websites you visit often to the hosts file, you may be able to increase the speed that you browse the web. The reason is that your computer will not need to ask for a DNS server for the particular IP address and thus you will not be waiting for a response to be received. One thing to keep in mind is that the IP address for the domain name may change in the case where the website owner decides to change IP addresses. When this happens, you won’t be able to connect to the site until you edit your hosts file again.

Editing the Hosts File in Windows

hosts-file

To edit the hosts file, simply navigate to %systemroot%\system32\drivers\etc\. Now, open up the file in notepad and you can begin editing. If you want to map an address, all you need to add is the IP address followed by the website URL. For example,

102.54.94.97     rhino.acme.com

If you want to map multiple IPs to URLs, you can use 1 per line.

Blocking URLs with the Hosts Files

A quick tip to block a website using the hosts file is to put in a dummy IP address into the hosts file. For example, if I wanted to block yahoo.com, I could add the following line to the hosts file:

127.0.0.1 yahoo.com

You could use this method to block known ad URLs, potential security risks, and sites you don’t want your kids to visit. Know another way to use the hosts file? Let us know in the comments!

(Don't worry, we won't spam you)