Edit Hosts File Windows – Full Step-by-Step Guide for Beginners (2025)
Learning how to edit hosts file Windows helps you block sites, redirect domains, and test local web projects without extra software. This tutorial covers what the hosts file is, where to find it, and how to safely modify it on Windows 10 or 11.
What Is the Hosts File in Windows?
The hosts file in Windows maps domain names (like example.com) to IP addresses. It takes priority before DNS lookups, letting you override connections locally. Typical use cases include testing a website before DNS propagation or blocking specific domains.
- Path:
C:\Windows\System32\drivers\etc\hosts - Purpose: Redirect or block websites locally
- Access: Administrator rights required
How to Edit Hosts File Windows (Safest Method)
Follow these steps to edit hosts file Windows correctly:
- Open the Start menu and type Notepad.
- Right-click and select Run as administrator.
- Go to File → Open.
- Navigate to
C:\Windows\System32\drivers\etc. - Switch file type to All Files (*.*).
- Select hosts and click Open.
- Add or modify entries, then click File → Save.
Edit Hosts File Windows 10 & 11
The process is the same on both versions. If saving fails, reopen Notepad as administrator. Some antivirus tools can lock the file — temporarily disable protection if needed.
Example: Block a Website Using Hosts File
To block Facebook, add these lines at the end of your hosts file:
127.0.0.1 facebook.com
127.0.0.1 www.facebook.com
This redirects both domains to your local machine, effectively blocking access.
Apply and Test Hosts File Changes
After editing the file, run this command to clear DNS cache:
ipconfig /flushdns
Then reopen your browser and try the site again. If it doesn’t load, your Windows hosts file edit worked successfully.
Common Issues and Fixes
- Access denied: Run Notepad as admin.
- No effect: Flush DNS and restart browser.
- File saved as hosts.txt: Remove the
.txtextension. - File locked: Disable antivirus temporarily, then re-enable after saving.
Advanced Uses of the Hosts File
Developers use it to test local projects by pointing domains to 127.0.0.1. IT admins use it for temporary redirects during DNS migration. You can also block ads system-wide by mapping ad domains to 127.0.0.1.
Security Tips
Malware can modify your hosts file to redirect you to fake sites. Check it regularly and ensure only trusted entries exist. Keep your antivirus active and avoid downloading unknown “optimizer” tools.
FAQ: Edit Hosts File Windows
1. Where is the hosts file located in Windows?
The hosts file is found in C:\Windows\System32\drivers\etc\hosts. It’s a plain text file used to map domain names to IP addresses.
2. Why can’t I save changes to the hosts file?
You need administrator privileges. Right-click Notepad and select Run as administrator before opening the hosts file.
3. How do I block a website using the hosts file?
Add a line such as 127.0.0.1 facebook.com at the bottom of the file. This redirects the domain to your local machine, blocking access.
4. Do I need to restart my PC after editing the hosts file?
Usually not. Simply run ipconfig /flushdns in Command Prompt to apply the changes immediately.
5. Can I use Notepad++ or VS Code instead of Notepad?
Yes, any text editor works as long as it’s launched with administrator privileges.
Helpful Resources
Final Thoughts
Knowing how to edit hosts file Windows gives you full control over local networking. Whether you’re blocking sites or testing a domain before launch, this method is safe, fast, and 100% reversible. Bookmark this guide — it’s an essential skill for every IT user or developer.
Meta: Edit hosts file Windows safely in 2025. Find, open, modify, and flush DNS on Windows 10 & 11.