How to block access to specific websites from the Windows hosts file

Last update: 18/08/2025

Blocking access to specific web pages is an effective measure to strengthen your security while browsingA simple way to do this on your Windows computer is through the hosts file. What exactly is the hosts file, and how can you use it to control access to specific websites? Find all the details below.

What is the Windows hosts file?

Before we look at how to block access to specific websites using the hosts file, let's talk a little about this tool. What is the hosts file? Basically, it's a plain text file (the most basic form of digital text) that is part of the Windows operating system (it's also found in macOS and Linux). It works as a contact list in which domain names are associated (like www.facebook.com) to specific IP addresses.

Typically, the task of mapping domain names and IP addresses is performed automatically by DNS servers. We don't even notice! Now, before we look at the DNS servers to resolve a domain, The system first checks the hosts fileAnd if it finds an entry there with the same domain name, it will use the associated IP address instead of searching the Internet for it.

All of the above means that the user can redirect any domain to an IP address of their choice. So, If you associate a domain name with an invalid or local IP, the browser will not be able to load the site.Every login attempt will be redirected to the invalid IP address, making access impossible. This is how the Windows hosts file works to block access to specific websites!

Exclusive content - Click Here  How to use Winget to automatically install and update programs in Windows

How to access the hosts file in Windows?

If you want to use the hosts file to block access to specific websites, you'll need to know where to find it on your Windows computer. To go directly to its location, follow the path: C:/Windows/System32/drivers/etc/hosts. When you get there, you'll notice that this file has no extension, and to edit it you need to open it in a text editor (like Notepad) with administrator permissions.

What are the advantages of using the hosts file to block access to specific websites?

Once you learn how to use the hosts file to block access to specific websites, you'll see how easy and advantageous it is. Whether for Protect yourself from malicious websites, block inappropriate content, or simply avoid distractions.This tool is 100% effective. Its advantages include:

  • To use it, no additional software needs to be installed and third-party programs. It's built into the operating system!
  • Works on any browser (Firefox, Chrome, Edge, etc.) blocking access to websites.
  • It also does not consume system resources, and is very fast and light.
  • Es Easy to use, even for users with little or no experience.

Steps to open the hosts file as Administrator

Open hosts file in Windows 11

Let's start by seeing How to open the hosts file in Windows with administrator permissions and then modify it to block access to specific websites. The procedure is the same in Windows 10 and Windows 11:

  1. On Windows, press Win + WILL and writes Memo pad.
  2. Right click on the application and select Run as administrator.
  3. If you see a User Account Control message, click Yes.
  4. Now, inside Notepad, click on Archive - Open.
  5. Navigate on the following route C: \ Windows \ System32 \ drivers \ etc \To do this, keep in mind that you'll see the C: drive in the left-hand menu, under the This PC tab.
  6. Once inside the folder etc, you won't see any type of file. For the hosts file to appear, Change the Text Documents (*.txt) filter to All Files (.)This field is located directly above the Open and Cancel buttons in the dialog box.
  7. Select the file hosts (the first one on the list) and click on Open.
Exclusive content - Click Here  How to turn off always-on display on iPhone 14 Pro

Steps to block access to specific websites by modifying the hosts file

Block access to specific websites by editing the Windows hosts file

Once you have opened the hosts file with administrator permissions, you can modify it to block access to specific web pagesAs you can see, this file has a few lines of comments beginning with the # symbol. It also contains the IP address of your local computer (127.0.0.1), which we'll use to block websites.

The procedure is very simple: At the end of the file, add a line containing the local IP address and domain of the website you want to block. Something like this: 127.0.0.1 www.website.comFor each domain name, you must enter a line, always preceded by the local IP address. If, for example, you want to block access to Facebook and TikTok, the change would look like this:

  • 127.0.0.1 www.facebook.com
  • 127.0.0.1 facebook.com
  • 127.0.0.1 www.tiktok.com
  • 127.0.0.1 tiktok.com

You will notice that Both the version of the domain with and without "www" must be included.This is important because some browsers may resolve the domain differently. Also, be careful not to make mistakes when typing the web address you want to block. If the name is misspelled, it won't block access to specific web pages.

Exclusive content - Click Here  How to stop text messages on MacBook

After you have added the desired entries, just click on Archive - Save and close Notepad. The changes will take effect immediately, although in some cases you may need to restart your browser or flush your DNS cache. If this is the case, you can clear DNS cache from the Command Prompt (CMD). Open it as administrator and run the following command ipconfig / flushdns.

How to verify that the lock is working

The best way to verify if blocking with the hosts file is working is to access the website in question. If everything is correct, the browser will display an error message and it will be impossible to access the website.

Y if you want to revert the changes and unblock websitesSimply follow the steps above to edit the hosts file. But this time, you'll need to delete the lines you added or add the # symbol at the beginning of each one. Then, save the file and run ipconfig / flushdns again to ensure unlocking.

Now you know how to block access to specific websites by editing the Windows hosts file. No doubt, It is a simple way to control access to certain websites, but it's not foolproof. If you want more robust blocking, consider combining this method with other tools, such as OpenDNS, firewall software like Glasswire o NetLimiter, or parental control programs.