The hosts file is one of the simplest yet most powerful networking configuration files on Windows. It allows you to manually map domain names to IP addresses, block websites, redirect URLs, test local development servers, and troubleshoot DNS issues—without modifying your router or DNS provider.
If you’re here reading this guide, you’re probably trying to edit the hosts file to block a specific website, point a domain to a local server, or test changes before going live. The good news? Editing the hosts file in Windows 10 and 11 is straightforward once you know the correct method.
In this in-depth guide, we’ll walk you through how to edit the hosts file safely, how to restore it, common errors to avoid, and when you should (or shouldn’t) use it.
What Is the Hosts File?
The hosts file is a simple text file located in the Windows system directory:
C:\Windows\System32\drivers\etc\hosts
Windows checks this file before using DNS, which means you can override any domain name directly from your computer.
Common Uses of the Hosts File
You can use the hosts file to:
- Block websites
- Redirect URLs (example.com → 127.0.0.1)
- Test websites locally
- Override DNS temporarily
- Map custom domains to servers
- Troubleshoot local network issues
Because it affects only your computer, it’s ideal for testing and local development.
How to Edit the Hosts File on Windows 11
The hosts file is protected, so you must edit it with administrator privileges. Otherwise, your changes will not save.
1. Edit the Hosts File Using Notepad (Easiest Method)
This is the simplest and most recommended method for beginners.
Open Notepad as Administrator
- Press Windows + S.
- Type Notepad.
- Right-click Notepad → choose:
Run as administrator
Without this step, you cannot save the hosts file.
Open the Hosts File
- Inside Notepad, click File → Open.
- Navigate to:
C:\Windows\System32\drivers\etc - Change the file filter from:
Text Documents (*.txt)to:All Files (*.*) - Select hosts and click Open.
Add or Edit Entries
Each entry follows this structure:
IP_address domain_name
Block a website
127.0.0.1 facebook.com
127.0.0.1 www.facebook.com
Redirect a domain to a local server
127.0.0.1 mywebsite.local
Map a domain to a custom IP
185.199.110.153 github.com
Save the Hosts File
Click File → Save, then close Notepad.
Your changes apply immediately—no restart required.
2. Edit the Hosts File Using PowerShell
If you prefer command-line tools, you can modify the hosts file from PowerShell.
Open PowerShell as Administrator
- Press Windows + X.
- Select:
Windows PowerShell (Admin)
Open the Hosts File for Editing
Run:
notepad C:\Windows\System32\drivers\etc\hosts
Edit the file as needed, then save.
Add a line directly using PowerShell
Example (block TikTok):
Add-Content -Path C:\Windows\System32\drivers\etc\hosts -Value "127.0.0.1 tiktok.com"
3. Edit the Hosts File Using a Third-Party Editor (Beginner-Friendly)
Some tools let you manage the hosts file with a graphical interface:
- Host File Editor (Microsoft Store)
- HostsMan
- BlueLife Hosts Editor
These apps allow:
- One-click blocking
- Entry sorting
- Backup/restore
- URL validation
If you’re not comfortable editing system files manually, these are safe and convenient options.
How to Flush DNS Cache After Editing
Sometimes browsers cache DNS entries. If changes don’t apply immediately, flush the DNS cache.
- Open Command Prompt (Admin).
- Run:
ipconfig /flushdns
You should see:
Successfully flushed the DNS Resolver Cache.
Now your new hosts file entries will take effect.
How to Restore the Default Hosts File
If you make a mistake or want to undo everything:
1. Delete custom entries manually
Open the hosts file and remove anything you added.
2. Replace with the default Windows hosts file
Default content:
# Copyright (c) 1993-2009 Microsoft Corp.
# This is a sample HOSTS file…
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
::1 localhost
Save and flush DNS.
Wrapping Up
And that wraps up our comprehensive guide on how to edit the hosts file on Windows 10 or Windows 11. Whether you’re blocking websites, testing domains, or redirecting URLs, the hosts file gives you direct control over DNS behavior on your PC. With the methods above, you can safely modify, manage, and restore it whenever needed.