The Windows hosts file lets you manually map domain names to IP addresses. It is commonly used for website testing, blocking specific websites, overriding DNS records, or troubleshooting network issues. Because the file is protected by Windows, you must edit it with administrator privileges.
What Is The Hosts File?
Before Windows queries a DNS server, it checks the hosts file for matching entries. If a domain is listed there, Windows uses the specified IP address instead of performing a DNS lookup.
For example:
127.0.0.1 example.com
This entry directs example.com to your local computer.
Where Is The Hosts File Located?
The hosts file is stored in:
C:\Windows\System32\drivers\etc\hosts
The file has no file extension and is typically hidden among other system files.
How To Edit The Hosts File
Because the file is protected, you must open your text editor as an administrator.
Follow these steps:
- Click the Start menu.
- Search for Notepad.
- Right-click Notepad and select Run as administrator.
- In Notepad, click File > Open.
- Navigate to:
C:\Windows\System32\drivers\etc\
- Change the file type from Text Documents (.txt) to All Files (.*).
- Select the hosts file and open it.
- Add or modify entries as needed.
- Save the file.
Common Hosts File Examples
The hosts file can be used for several purposes.
To block a website:
127.0.0.1 facebook.com
127.0.0.1 www.facebook.com
To point a domain to a specific server:
192.168.1.100 mysite.local
To redirect a domain to another IP:
203.0.113.10 example.com
Each entry should appear on its own line.
Flush The DNS Cache
After editing the hosts file, Windows may continue using cached DNS information.
To refresh DNS records:
- Open Command Prompt as Administrator.
- Run:
ipconfig /flushdns
You should see a message confirming that the DNS Resolver Cache was successfully flushed.
Common Problems
If your changes do not work, check the following:
- Notepad was opened as Administrator
- The file was saved as
hosts and not hosts.txt
- There are no typing mistakes in the entries
- DNS cache has been flushed
- Browser cache is not serving old results
- Security software is not protecting the hosts file
How To Restore The Default Hosts File
A default Windows hosts file usually contains only comments and a localhost entry.
A basic version looks like:
# localhost name resolution
127.0.0.1 localhost
If you are troubleshooting, backing up the original file before making changes is a good practice.
When Should You Use The Hosts File?
The hosts file is useful for:
- Testing websites before DNS changes go live
- Blocking unwanted websites
- Redirecting domains during development
- Troubleshooting DNS issues
- Creating local development environments
For large-scale DNS management, dedicated DNS servers are generally more practical, but the hosts file remains a simple and effective tool for local overrides.
Join The Discussion
Have you used the hosts file for website development, blocking websites, or troubleshooting network issues? What challenges, tips, or use cases have you encountered when working with hosts file entries? Share your experiences, questions, and best practices to help others get the most from this powerful Windows feature.