How to Find and Edit the Hosts File in Windows 11 (Block Websites)



If you want to block a website on your Windows 11 PC without installing third-party software, you can use a simple built-in tool called the Hosts file.

The Hosts file allows Windows to associate specific domain names with IP addresses. By editing it, you can redirect a website to another address, including your own computer, effectively preventing the website from loading.

In this guide, you'll learn where to find the Hosts file in Windows 11, how to edit it safely, and how to use it to block websites.

What Is the Hosts File?

The Hosts file is a small text file that Windows uses to map domain names to IP addresses before contacting a DNS server.

For example, when you enter a website address such as example.com, Windows can check the Hosts file to see whether there is a specific IP address associated with that domain.

The Hosts file is located in:

C:\Windows\System32\drivers\etc\hosts

Because this file controls how Windows resolves certain website addresses, changing it can be useful for testing websites, troubleshooting network problems, or blocking access to specific websites.

Read More: “The Truth Nobody Is Telling You About This—You Need to Read This Before It’s Too Late”

Why Use the Hosts File to Block Websites?

There are several reasons you might want to block a website using the Hosts file.

You can use it to:

  • Block distracting websites while working.
  • Prevent access to certain websites on a personal computer.
  • Test how a computer behaves when a domain is unavailable.
  • Block unwanted domains without installing additional software.
  • Troubleshoot DNS and website connection problems.

However, keep in mind that the Hosts file is not a complete parental-control or network-security solution. Someone with administrator access can change it, and it may not effectively block every way of accessing a website.

How to Find the Hosts File in Windows 11

Finding the Hosts file is straightforward, but Windows normally stores it inside a protected system folder.

Step 1: Open File Explorer

Press Windows + E on your keyboard to open File Explorer.

You can also open it by clicking the File Explorer icon on the Windows taskbar.

Step 2: Navigate to the Hosts File Location

In File Explorer, go to:

C:\Windows\System32\drivers\etc

You should see several files in the folder, including a file named:

hosts

The file usually does not have a .txt extension.

Step 3: Don't Open It Normally

If you double-click the Hosts file, Windows may not give you the proper option for editing it.

Instead, you should open your text editor with administrator privileges and then open the file from within the editor.

This is necessary because the Hosts file is protected by Windows.

How to Open the Hosts File as an Administrator

The easiest method is to use Notepad.

Step 1: Open Notepad as Administrator

Click the Start button and search for Notepad.

Right-click Notepad and select Run as administrator.

If Windows displays a User Account Control prompt, click Yes.

Step 2: Open the Hosts File

In Notepad, select:

File → Open

Navigate to:

C:\Windows\System32\drivers\etc

Notepad may initially show only text files.

Change the file type from Text Documents (*.txt) to All Files (.).

You should now be able to see the hosts file.

Select it and click Open.

How to Block a Website Using the Hosts File

Once you've opened the Hosts file, you can add entries that redirect a website's domain to your computer.

For example, you could add:

127.0.0.1 example.com

To also block the www version, add:

127.0.0.1 www.example.com

Replace example.com with the actual domain you want to block.

The 127.0.0.1 address refers to your own computer, also known as the localhost address. When Windows tries to connect to the blocked domain, the request is directed back to the local computer instead of the actual website.

Important: Block Each Domain You Need

Websites can use multiple domains or subdomains.

For example, blocking:

127.0.0.1 example.com

does not necessarily mean every subdomain associated with that website will be blocked.

You may need to add separate entries for relevant domains and subdomains.

How to Save the Hosts File

After adding your entries, click:

File → Save

If Notepad was opened with administrator privileges, Windows should allow you to save the changes.

If Windows says you don't have permission to save the file, close Notepad and make sure you opened it using Run as administrator.

How to Test Whether the Website Is Blocked

After saving the Hosts file, open your web browser and try visiting the website.

If the browser still loads the website, you may need to clear Windows' DNS cache.

Flush the DNS Cache

Press Windows + X and select Terminal (Admin) or Windows PowerShell (Admin), depending on your Windows 11 configuration.

Enter:

ipconfig /flushdns

Then press Enter.

Windows should confirm that the DNS Resolver Cache has been successfully flushed.

Close and reopen your browser, then try accessing the website again.

How to Unblock a Website

If you previously blocked a website and want to restore access, you can simply remove or disable the corresponding Hosts file entries.

Open the Hosts file again as an administrator and find the lines you added.

For example:

127.0.0.1 example.com

You can either delete the lines or place a # at the beginning:

# 127.0.0.1 example.com

The # turns the line into a comment, meaning Windows will ignore it.

Save the file and flush the DNS cache again using:

ipconfig /flushdns

Create a Backup Before Editing

Before making changes, it is a good idea to create a backup of the original Hosts file.

You can copy the original hosts file and store the backup somewhere safe.

This gives you an easy way to restore the original configuration if something goes wrong.

You should also avoid deleting existing entries unless you understand what they do.

Common Problems When Editing the Hosts File

The Hosts File Doesn't Appear

If you can't see the Hosts file in Notepad's Open dialog, make sure the file type is set to:

All Files (.)

rather than Text Documents (*.txt).

Windows Won't Let You Save the File

This usually happens because Notepad wasn't opened with administrator privileges.

Close Notepad, search for it from the Start menu, right-click it, select Run as administrator, and try again.

The Website Still Opens

If the website continues to load, run:

ipconfig /flushdns

You should also completely close and reopen your browser.

Some browsers and applications may use their own DNS settings, which can affect how domain names are resolved.

You Accidentally Saved the File as hosts.txt

Windows may try to add .txt if the file is saved incorrectly.

When editing the existing Hosts file, make sure you are saving the file as hosts, without adding .txt.

Is Editing the Hosts File Safe?

Editing the Hosts file is generally safe when you know exactly what you're changing.

However, it is a system configuration file, so you should be careful when modifying it.

Avoid changing unfamiliar entries simply because they look unusual. If you're unsure about an entry, leave it alone and create a backup before making changes.

You should also remember that administrator privileges are required to modify the file.

Can the Hosts File Block Websites Permanently?

The Hosts file can block a website for a Windows user as long as the relevant entries remain in place.

However, it isn't designed to provide strong website filtering or security.

A user with administrator access can edit or remove the entries. In addition, modern websites may rely on multiple domains and services, making simple Hosts-file blocking less comprehensive than dedicated website-blocking or parental-control software.

Final Thoughts

The Windows 11 Hosts file is a useful built-in tool for controlling how your computer connects to specific domains. With a few simple changes, you can use it to block websites without installing additional software.

The key steps are to locate the file at:

C:\Windows\System32\drivers\etc\hosts

open it using an administrator-enabled text editor, add the appropriate 127.0.0.1 entries, save the file, and flush your DNS cache.

Always create a backup before making changes, and remember that the Hosts file is best suited for basic local website blocking and troubleshooting rather than comprehensive internet filtering.

Comments

LEARN MORE

How to Remove Evaluation Copy Watermark in Windows 11

Ways to Fix Hypervisor Error in Windows 11

Steps to Activate Split Screen on iPhone

How to Send a Folder By Email | Full Guide

How to Fix Chrome Not Downloading Files on Android