pixel
loading...

How to edit the Windows hosts file to block or redirect websites

Back To Online Support

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.

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 the System32 folder, open drivers and then open etc. You’ll now see several files, one of which is hosts.

Hosts file

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 give you a Windows prompt, asking you which program you would like to use to open the file.

Notepad

From this prompt, you can choose to edit the hosts file with Notepad. Click to select Notepad and click the OK button. From there, Notepad will launch with the hosts file information.

Hosts file text in Notepad

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.

Step 1:

Click on Start and type in Notepad, right-click the Notepad listing to bring up the context menu. Select the option Run as Administrator.

Run Notepad 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.

Step 2:

Change Text Documents (*.txt) to All Files using the drop down menu. Now, you can select the hosts file and click Open.

Open hosts file

Step 3:

Adding files to the hosts file is very simple. The hosts file uses the format:

IP Address domainexample.co.za
Blocking a website in Windows is as simple as typing the following into the bottom of the hosts file:
127.0.0.1 www.domainexample.co.za
So, if you wanted to block a website like www.facebook.com, you could just add the following line and click save:
127.0.0.1 www.facebook.com

Hosts file block website

What we are telling Windows is that the website www.facebook.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.

The site can't be reached

You can also use the hosts file to create shortcuts to your own devices on the network.

For example, if you had a router with IP address 192.168.1.1 on your home network, you could add the following line to the hosts file and simply type in myrouter.co.za into your address bar.

Hosts file IP mapping

It doesn’t matter if myrouter.co.za is an actual website because the hosts file is read first and you are redirected to the IP address specified in the file.

Please note that not all web browsers use the hosts file, so if this is not working, that could be the issue. This has been tested it using IE, Microsoft Edge, Chrome and Firefox and it worked on all of these browsers.

Should you need assistance blocking websites through your hosts file, please feel free to call us on 010 555 0650.

Regards,
The iSAT Team


Back to top