Host File Location in Windows: Find & Edit It
In this article
The host file in Windows is a plain text file that maps domain names to IP addresses, allowing you to override DNS settings locally. Editing it lets you block websites, redirect domains for testing, or troubleshoot network issues. You can find and edit the host file using built-in tools, but you'll need administrator privileges. This guide shows you exactly where the host file is located, how to access and edit it safely, and what to watch out for.
What You'll Need
- Administrator access to your Windows PC
- Notepad or another plain text editor (not Word or WordPad)
- Basic understanding of IP addresses and domain names
Step-by-Step
- Open File Explorer by clicking the folder icon on the taskbar or pressing Windows + E.
- Navigate to the system drive, usually
C:\. This is where Windows is installed. - Open the
Windowsfolder. This is located at the root of the C: drive. - Inside the
Windowsfolder, open theSystem32folder. - Go into the
driversfolder. - Open the
etcfolder. This folder contains system configuration files, including the host file. - Look for a file named
hosts(no file extension). This is the host file. - Right-click the
hostsfile and select Open with > Notepad. Do not double-click it—this may open it in the wrong program or without proper permissions. - If prompted by User Account Control (UAC), click Yes to allow the app to make changes.
- Once open, you can view and edit the contents. Each line should follow the format:
IP_address domain_name. For example:127.0.0.1 example.comblocks access to example.com by redirecting it to your local machine. - After making changes, click File > Save to save your edits.
- Close Notepad. The changes take effect immediately—no restart is required.
Common Mistakes
- Editing without administrator rights: If you don’t run Notepad as an administrator, you won’t be able to save changes. Always allow UAC prompts when opening the file.
- Using the wrong editor: Word processors like Microsoft Word add formatting that corrupts the file. Always use Notepad or a plain text editor.
- Incorrect syntax: Each entry must be
IP_addressfollowed by a space or tab, then thedomain_name. Avoid commas, quotes, or extra spaces. - Forgetting to save: Some users close Notepad without saving. Always confirm the file was saved by reopening it.
- Typing errors in domains or IPs: A single typo can cause a site to fail to load or redirect incorrectly.
Tips
- Backup the original file: Before editing, copy the
hostsfile and rename it tohosts.bak. If something goes wrong, you can restore it. - Use comments: Add lines starting with
#to explain your entries. For example:# Block tracking siteabove a blocked domain. - Flush DNS after changes: Open Command Prompt as administrator and run
ipconfig /flushdnsto clear old DNS entries and ensure your changes take effect immediately. - Test one entry at a time: When adding multiple entries, test each one before adding more to isolate issues.
- Use 127.0.0.1 to block sites: Redirecting unwanted domains to this loopback address prevents them from loading.
Troubleshooting
If your changes don’t work or cause issues, follow these steps:
- Check file permissions: Right-click the
hostsfile, select Properties, and ensure your user account has full control under the Security tab. - Verify administrator mode: If you can’t save, reopen Notepad as an administrator: search for Notepad in the Start menu, right-click it, and choose Run as administrator, then open the file manually.
- Confirm file location: The correct path is
C:\Windows\System32\drivers\etc\hosts. Double-check each folder. - Check for hidden extensions: Ensure the file isn’t actually named
hosts.txt. In Folder Options, disable “Hide extensions for known file types” to verify. - Restore from backup: If the system behaves oddly, delete the edited file and rename
hosts.bakback tohosts. - Flush DNS cache: Run
ipconfig /flushdnsin an elevated Command Prompt to clear outdated records. - Scan for malware: Some malware modifies the hosts file. Run a full system scan using Windows Security or a trusted antivirus.
Frequently Asked Questions
Can I edit the hosts file on any Windows version?
Yes, the hosts file exists in all modern Windows versions including Windows 10 and 11, and is located in the same path.
Do I need to restart after editing the hosts file?
No, changes take effect immediately. However, flushing the DNS cache ensures faster recognition.
Why can’t I save changes to the hosts file?
This usually happens without administrator rights. Always open Notepad as an administrator when editing system files.
Can I block multiple domains with one IP?
Yes. List each domain on a separate line pointing to the same IP, such as 127.0.0.1, to block multiple sites.
Is editing the hosts file safe?
Yes, if done correctly. Mistakes can block websites or disrupt network functions, but the file can always be restored.
Can malware change the hosts file?
Yes. Malware sometimes redirects legitimate sites to malicious IPs. Regular checks and antivirus scans help prevent this.