Edit Hosts File in Windows (Windows 10/11) – Step-by-Step Guide
Edit hosts file windows to block websites, redirect domains, or test projects locally—without any third-party software. This beginner-friendly tutorial shows exactly how to find, open, edit, and safely save the Windows hosts file, plus how to flush DNS so your changes take effect immediately.
What Is the Hosts File in Windows?
The hosts file in Windows is a plain text file that maps hostnames (for example, example.com) to IP addresses. When you open a website, Windows checks this file before querying DNS. That means you can override DNS to block or redirect specific domains on your computer.
- Location:
C:\Windows\System32\drivers\etc\hosts
- Purpose: Override DNS to redirect or block domains
- Permission: Administrator rights required to edit
How to Edit Hosts File Windows (Safest Method)
Follow these steps to edit Windows hosts file using built-in tools:
- Open the Start menu and search for Notepad.
- Right-click Notepad and choose Run as administrator.
- In Notepad, go to File > Open.
- Navigate to
C:\Windows\System32\drivers\etc
. - Change the file type to All Files (*.*) to reveal the file.
- Select hosts and click Open.
- Add your entries, then File > Save.
Windows 10 Hosts File Edit
The path and process are identical on Windows 10. If saving fails, you likely didn’t run Notepad as admin. Always launch the editor with elevated permissions before performing a windows 10 hosts file edit.
Windows 11 Hosts File Edit
On Windows 11, the UI is slightly updated but the steps are the same. After any windows 11 hosts file edit, flush the DNS cache to apply changes.
Example: Block a Website
To block facebook.com
, add these lines to the end of the file:
127.0.0.1 facebook.com
127.0.0.1 www.facebook.com
This redirects the domain to your local machine, effectively blocking it.
Save and Apply Changes
After saving your edits, flush the DNS cache:
ipconfig /flushdns
Close and reopen your browser (or use a private window) to test the new mapping.
Best Practices
- Always run your editor as administrator; otherwise the file won’t save.
- Use the correct format:
IP-address<space>domain
(one entry per line). - Use
#
at the start of a line to comment or temporarily disable an entry. - Keep a backup copy of the original hosts file before you make changes.
- Clear browser cache or use a private window when validating changes.
Advanced Uses of the Hosts File
Beyond blocking sites, the hosts file can be used for advanced networking and development tasks. Web developers often redirect domains to local servers for testing before deploying changes. IT administrators may use the file to force internal systems to resolve through specific IPs. It’s also useful for quickly bypassing DNS issues when a domain change has not yet propagated globally.
You can also use the hosts file for ad-blocking by mapping known ad-serving domains to 127.0.0.1
. While browser-based ad blockers are more flexible, a hosts-based solution works system-wide, covering all browsers and many applications.
Security Considerations
Because the hosts file controls how domains resolve, malware sometimes modifies it to redirect users to malicious websites. For this reason, you should check the file periodically for suspicious entries. If you find entries pointing to strange IP addresses for common sites like Google or banking websites, remove them immediately and run a full antivirus scan.
To protect the file, ensure you have reliable security software, and avoid downloading unknown scripts that may alter system files without permission.
Common Issues (and Fixes)
- Access denied: Notepad wasn’t launched as administrator. Close it and reopen with elevated rights.
- No effect: You didn’t flush DNS or your browser cached the result. Run
ipconfig /flushdns
and restart the browser. - Saved as hosts.txt: Remove the
.txt
extension. The file name must be exactlyhosts
with no extension. - File locked: Some antivirus tools protect system files. Temporarily disable protection, edit, then re-enable.
FAQ: How to Edit Hosts File Windows
Q: Can I use another editor?
A: Yes, but always run it as administrator. The path is the same.
Q: Do I need to restart my PC?
A: Not usually. Flushing DNS is enough for most changes.
Q: Will this affect other users on the network?
A: No. Hosts file changes only affect the local machine.