How to Edit Host File on Windows
In this article
Yes, you can edit the host file on Windows to block websites, redirect domains, or map hostnames to specific IP addresses. This is done by modifying the local hosts file using a text editor with administrator privileges. The hosts file overrides DNS lookups, so changes take effect immediately on your machine. Before editing, ensure you know the correct IP addresses and domain names you want to map, and back up the original file.
What You'll Need
- Administrator access to your Windows PC
- Notepad or another plain text editor (avoid word processors like Word)
- A backup method (copying the original file)
- Knowledge of the domain and IP address mappings you intend to add
Step-by-Step
- Press the Windows key, type Notepad, and right-click the result. Select Run as administrator. Confirm the UAC prompt if it appears.
- In Notepad, click File > Open. Navigate to
C:\\Windows\\System32\\drivers\\etc. This folder contains system files, so you must have admin rights to access it. - By default, Notepad shows only text files. To see the hosts file, change the file type dropdown at the bottom of the Open dialog from Text Documents (*.txt) to All Files (*.*).
- Click the file named hosts (no extension) and click Open.
- At the end of the file, add your custom entries. Each entry should follow this format:
IP_address hostname. For example, to block a site, use127.0.0.1 example.com. Use spaces or tabs to separate the IP and domain. - To block multiple domains, add one entry per line. For example:
127.0.0.1 badsite.com
127.0.0.1 tracker.example.net - Save the file by pressing Ctrl + S or clicking File > Save. If you get a permission error, ensure Notepad was opened as administrator.
- Close Notepad. The changes take effect immediately—no restart is needed.
- To test, open Command Prompt and type
ping example.com(replace with your domain). It should resolve to the IP you specified. - Optionally, flush the DNS cache to ensure old lookups don’t interfere. Open Command Prompt as administrator and run:
ipconfig /flushdns.
Common Mistakes
- Forgetting to run Notepad as admin: Without admin rights, you can’t save changes to the hosts file.
- Editing in a regular text editor: Programs like WordPad or basic Notepad (not run as admin) may not save correctly or may add formatting.
- Using incorrect syntax: Each line must have only one IP and one domain. Avoid commas, extra spaces, or multiple domains per line unless properly spaced.
- Forgetting to flush DNS: Old DNS entries may persist in cache, making it seem like the change didn’t work.
- Typing the wrong IP: Using
0.0.0.0instead of127.0.0.1may not block reliably on all systems. Stick to127.0.0.1for blocking. - Editing the wrong file: Ensure you're opening the file in
C:\\Windows\\System32\\drivers\\etc, not a copy elsewhere.
Tips
- Always back up the original hosts file before editing. Copy it to your desktop as
hosts_backup. - Use comments to label entries. Start lines with
#to add notes, like# Blocked ads. - Use
127.0.0.1to block domains locally. This redirects them to your own machine, where nothing responds. - Test changes with
pingornslookupin Command Prompt. - Keep the file clean—remove unused entries to avoid confusion later.
- Consider using third-party tools like Hosts File Editor (from official sources) if manual editing feels risky, but verify safety first.
Troubleshooting
If the hosts file changes don’t seem to work, start with the simplest fixes. First, ensure you saved the file after making changes. Then, flush the DNS cache using ipconfig /flushdns in an elevated Command Prompt. If that fails, double-check that you opened Notepad as administrator—this is the most common issue.
If websites still load despite being mapped to 127.0.0.1, check for typos in the domain name or spacing. Ensure there are no extra characters or line breaks. Also, some applications use their own DNS (like browsers with DNS-over-HTTPS), which can bypass the hosts file. Disable such features if needed.
If you can’t open the hosts file at all, verify the file path. Navigate manually to C:\\Windows\\System32\\drivers\\etc and confirm the file exists. If it’s missing, your system may be corrupted—run sfc /scannow in an elevated Command Prompt to repair system files.
If changes work on one PC but not another, remember the hosts file is local. It only affects the machine it’s on. For network-wide blocking, consider router or DNS-level solutions.
If you accidentally break something, restore from your backup. Copy the saved hosts_backup file back to C:\\Windows\\System32\\drivers\\etc, overwriting the current one (as admin).
Frequently Asked Questions
Can editing the host file harm my computer?
No, not if done correctly. Mistakes can misroute domains locally, but they don’t damage the system. Always back up first.
Does the hosts file work on all Windows versions?
Yes, it works on Windows 10, 11, and older versions like 7 and 8. The location and method are the same.
Why isn’t my domain redirect working?
Check for typos, ensure you flushed DNS, and verify the app isn’t using alternate DNS. Also, confirm Notepad saved the file successfully.
Can I block IPv6 addresses in the hosts file?
Yes. Use the IPv6 loopback address ::1 to block IPv6 domains, like ::1 example.com.
Do I need to restart my computer after editing?
No. Changes take effect immediately after saving, though flushing DNS helps clear old entries.
Can I use the hosts file to speed up websites?
Not significantly. It can map a domain to a faster server IP if you know one, but most sites use CDNs, making manual mapping ineffective.