The Windows Hosts file is a file that Windows uses to control and map IP addresses. By editing the Hosts file, Windows can be customized to block or redirect specific websites and even protocols that are used by programs and applications.
To get started editing the Windows Hosts file, you first need to locate it. Open Windows Explorer and click on This PC or My Computer. Double-click on C:\, then the Windows folder and scroll down the page until you reach the System32 folder. Inside of that folder, open drivers and then open etc. You’ll now see several files, one of which is hosts.
Now, notice that the file type for the hosts file is listed as File. Because there is no default program set to open a file type like this, double clicking the hosts file will simply give you a Windows prompt, asking you which program you would like to use to open the file.
From this prompt, you can choose to edit the hosts file with Notepad. So, simply click to select Notepad and click the OK button. From there, Notepad will launch with the hosts file information.
This way of opening the hosts file was demonstrated to show where the hosts file is actually located within Windows, but you won’t be able to edit it because it’s a system file. In order to edit the file, you have to open Notepad first, running as an Administrator.
Click on Start and type in Notepad, but don’t click on Notepad to open it. Rather, right-click the Notepad listing to bring up the context menu. Select the option Run as Administrator.
With Notepad open, select File > Open. Navigate to C:\Windows\System32\drivers\etc. You will get a blank screen that displays the prompt No items match your search. Change Text Documents (*.txt) to All Files using the drop down menu. Now, you can select the hosts file and click Open.
Adding files to the hosts file is very simple. The hosts file uses the format:
IP Address exampledomain.com
Blocking a website in Windows is as simple as typing the following into the bottom of the hosts file:
So, if I wanted to block a website like www.nytimes.com, I could just add the following line:
What we are actually telling Windows is that the website www.nytimes.com should redirect to the IP address 127.0.0.1, which is just the loopback address on our local system. If you don’t have a local website setup on your computer, you’ll just get an error page in your web browser.
Pretty cool, huh!? Obviously, you can see how this can be used in several different ways: a prank, parental control, etc. If you didn’t want to block the website in that way, you could also redirect it to another website. In order to do this, you have to find the IP address of the other site first.
To do that, just open a command prompt (click on Start and type in CMD) and type in the following command:
In my example, I pinged Adobe.com. The IP address is 18.104.22.168. Now I can simply plug that number into my hosts file in front of www.nytimes.com.
Now when I visit www.nytimes.com, I get redirect to Adobe.com! Nice! Note that if this doesn’t work for the websites you are entering, it could be because of the URL you are using. For example, it makes a difference if you use www.nytimes.com as opposed to nytimes.com without the www. Visit the website and see exactly what the URL is for the website you want to redirect. You should always try without the www first to see if that works.
If the website uses HTTPS like Google.com or something, it should still redirect if you use the host name. There is no way to specify the HTTPS version of a website in the HOSTS file, but it should redirect the HTTPS and non-HTTPS versions of the website if you use just the host name (i.e. google.com).
Lastly, you can use the hosts file to create simple shortcuts to your own devices on the network. For example, my router is at 192.168.1.3 on my home network, but I could add the following line to my hosts file and simply type in myrouter.com into my address bar.
It doesn’t really matter if myrouter.com is actually a website or not because the hosts file is read first and you are redirected to the IP address specified in the file. It’s worth noting that not all browsers may use the hosts file, so if it’s not working, that could be the issue. I tested it using IE, Microsoft Edge, Chrome and Firefox and it worked on all of the browsers.
Overall, the hosts file is still useful, even in Windows 10. It also still works just fine in Windows 8, 7, Vista, etc. If you have any questions, feel free to comment. Enjoy!