The Hosts File in Windows 10: What It Is, Where to Find It, and How to Edit It
Whether you're a developer testing a new web application, a sysadmin troubleshooting DNS propagation issues, or simply someone who wants to block distracting websites, the Windows 10 hosts file is one of the most powerful — and most overlooked — tools at your disposal.
In this comprehensive guide, we'll explain exactly what the hosts file is, how it works under the hood, where to find it, and how to edit it safely and effectively with real-world examples.
—
What Is the Hosts File?
The hosts file is a plain-text system file that maps human-readable domain names to their corresponding IP addresses. It acts as a local, static alternative to DNS (Domain Name System) resolution.
Here's the key point: your operating system checks the hosts file *before* querying any external DNS server. This means that any entry you define in the hosts file takes immediate precedence over whatever a DNS server might return.
How Domain Resolution Works (Simplified)
When you type www.example.com into your browser, your system follows this lookup order:
- Local cache — Has this domain been resolved recently?
- Hosts file — Is there a static entry for this domain?
- DNS resolver — Query the configured DNS server (e.g., Google's
8.8.8.8or your ISP's server)
Because the hosts file sits at step two — above external DNS — any mapping you define there will override DNS entirely for that domain on your local machine.
—
Common Use Cases for the Hosts File
Understanding *why* you'd edit the hosts file makes it much easier to use it correctly. Here are the most practical scenarios:
| Use Case | Description |
|---|---|
| Block websites | Redirect a domain to 127.0.0.1 to prevent it from loading |
| Local development testing | Point a production domain to a local or staging server IP |
| Bypass DNS propagation delays | Manually assign an IP while DNS changes are still propagating |
| Override broken DNS records | Fix resolution issues without waiting for upstream corrections |
| Ad and tracker blocking | Redirect known ad-serving domains to a null address |
> Pro tip for developers: If you're running a local development environment or testing a new server configuration — for example, before migrating your site to a new VPS Hosting plan — the hosts file lets you preview exactly how your site will behave on the new IP address without touching live DNS records.
—
Where Is the Hosts File Located in Windows 10?
In Windows 10, the hosts file is located at the following path:
C:WindowsSystem32driversetchostsThis is a protected system file, which means:
- It has no file extension (it's simply named
hosts) - You cannot edit it without administrator privileges
- Standard file browsers may not display it unless you change the file type filter
> Note: The etc folder also contains other network configuration files such as networks, protocol, and services. Do not modify these unless you know exactly what you're doing.
—
How to Edit the Hosts File in Windows 10 (Step-by-Step)
There are two reliable methods to edit the hosts file: using Notepad with administrator privileges (the most common approach) or using PowerShell. We'll cover both.
—
Method 1: Edit the Hosts File Using Notepad (Recommended)
#### Step 1 — Open Notepad as Administrator
- Click the Start button (or press the
Windowskey) - Type Notepad in the search bar
- Right-click on Notepad in the results
- Select "Run as administrator"
- Click Yes if prompted by User Account Control (UAC)
> ⚠️ Critical: If you open Notepad normally (without administrator rights) and try to save the hosts file, Windows will silently fail or prompt an error. Always run as administrator first.
#### Step 2 — Open the Hosts File
- In Notepad, click File → Open
- Navigate to:
C:WindowsSystem32driversetc - In the bottom-right corner of the Open dialog, change the file type filter from
Text Documents (*.txt)to All Files (*.*) - You will now see the
hostsfile listed — select it and click Open
#### Step 3 — Understand the File Structure
When you open the hosts file, you'll see something like this:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhostLines beginning with # are comments and are ignored by the system. All active entries must follow this format:
IP_address domain_name- The IP address comes first
- Followed by at least one space or tab
- Then the domain name
- One entry per line
#### Step 4 — Add, Modify, or Remove Entries
Scroll to the bottom of the file (below all the comments) and add your entries. Here are the most common formats:
Block a website:
127.0.0.1 www.example.com
127.0.0.1 example.comRedirect a domain to a specific server:
192.168.1.100 www.mytestsite.comAdd a comment to document your changes:
# Blocking social media during work hours
127.0.0.1 www.facebook.com
127.0.0.1 facebook.com#### Step 5 — Save the Hosts File
- Click File → Save (or press
Ctrl + S) - If prompted by UAC, confirm the administrative permission
- The changes take effect immediately — no reboot required
> If Windows refuses to save, it's because Notepad wasn't opened with administrator privileges. Close and repeat from Step 1.
—
Method 2: Edit the Hosts File Using PowerShell
For sysadmins who prefer the command line, you can open the hosts file directly in Notepad via an elevated PowerShell session:
- Press
Windows + Xand select Windows PowerShell (Admin) - Run the following command:
notepad C:WindowsSystem32driversetchosts- Make your edits and save
Alternatively, you can append a new entry directly from PowerShell without opening a text editor:
Add-Content -Path "C:WindowsSystem32driversetchosts" -Value "127.0.0.1`twww.example.com"—
Practical Examples: Real-World Hosts File Use Cases
Example 1 — Blocking Unwanted or Distracting Websites
To block a website, redirect its domain to 127.0.0.1 (your local loopback address). Since no web server is listening there, the browser will return a connection error.
Block Facebook entirely:
127.0.0.1 www.facebook.com
127.0.0.1 facebook.com
127.0.0.1 m.facebook.comBlock YouTube:
127.0.0.1 www.youtube.com
127.0.0.1 youtube.com> Why include both www and non-www versions? Because browsers may try both. If you only block www.facebook.com, navigating to facebook.com will still work. Always add both variants.
—
Example 2 — Testing a Website Before DNS Propagation
This is one of the most valuable uses of the hosts file for developers and sysadmins. Suppose you're migrating a website to a new server — for instance, moving from shared hosting to a Dedicated Server — and you want to verify everything works on the new IP before updating your live DNS records.
Scenario: Your new server's IP is 203.0.113.50 and your domain is www.mybusiness.com
Add this entry to your hosts file:
203.0.113.50 www.mybusiness.com
203.0.113.50 mybusiness.comNow, when *you* visit www.mybusiness.com, your browser resolves it to the new server. Everyone else in the world still sees the old server via DNS. Once you've confirmed the new server is working perfectly, update your DNS records — and then remove these entries from your hosts file.
This technique is especially useful when:
- Migrating between hosting providers
- Testing a new SSL Certificate configuration before going live
- Verifying server-side redirects and
.htaccessrules - Checking email deliverability on a new Email Hosting setup
—
Example 3 — Bypassing DNS Propagation Delays
DNS changes can take anywhere from a few minutes to 48 hours to propagate globally. If you've just pointed a domain to a new server and need immediate access from your machine, the hosts file is your best friend.
Scenario: You've updated your domain's A record to 93.184.216.34, but DNS hasn't propagated yet.
93.184.216.34 www.example.com
93.184.216.34 example.comYour machine will now resolve the domain to the new IP immediately, regardless of what DNS servers are returning.
> Remember to remove these entries once DNS has fully propagated. Leaving stale hosts file entries can cause confusing connectivity issues later.
—
Example 4 — Blocking Ad Networks and Trackers
You can use the hosts file as a basic ad blocker by redirecting known ad-serving and tracking domains to 0.0.0.0 (which is slightly faster than 127.0.0.1 because it doesn't wait for a connection timeout):
0.0.0.0 ads.doubleclick.net
0.0.0.0 googleadservices.com
0.0.0.0 pagead2.googlesyndication.com
0.0.0.0 tracking.example-analytics.com> For large-scale ad blocking via the hosts file, community-maintained lists like StevenBlack/hosts on GitHub provide regularly updated, consolidated hosts files with tens of thousands of blocked domains.
—
How to Flush the DNS Cache After Editing the Hosts File
While hosts file changes typically take effect immediately, your browser or OS may have cached old DNS responses. To ensure your changes are applied instantly, flush the DNS cache:
- Open Command Prompt as Administrator
- Run the following command:
ipconfig /flushdnsYou should see:
Windows IP Configuration
Successfully flushed the DNS Resolver Cache.- Restart your browser for good measure
—
How to Restore the Default Hosts File
If you've made changes and want to revert to the original Windows 10 hosts file, simply delete all custom entries you've added (everything below the default comments), leaving only the standard commented-out content.
Alternatively, you can replace the entire file with the default Windows 10 hosts file content:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost—
Hosts File Best Practices and Security Considerations
Before you start editing your hosts file freely, keep these important points in mind:
✅ Do's
- Always back up the hosts file before making changes — copy it to your Desktop as
hosts.backup - Document your entries with comments using
#so you remember why each entry was added - Remove temporary entries once they're no longer needed (e.g., after DNS propagation)
- Use
0.0.0.0instead of127.0.0.1for blocking — it fails faster and doesn't attempt a local connection
❌ Don'ts
- Never download and blindly apply a hosts file from an untrusted source — malicious hosts files can redirect your banking or email domains to phishing servers
- Don't leave stale entries — they can cause mysterious connectivity failures that are hard to debug
- Don't use the hosts file as a permanent DNS solution — for production environments, use proper DNS management through your hosting provider or Domain Registration service
Security Warning
Malware frequently targets the hosts file to redirect legitimate domains (like banking sites or Windows Update servers) to malicious IP addresses. If you're experiencing unexpected redirects or connectivity issues, check your hosts file for unauthorized entries. Legitimate security software should flag unauthorized hosts file modifications.
—
Hosts File vs. DNS: When to Use Each
| Scenario | Hosts File | DNS |
|---|---|---|
| Quick local testing | ✅ Ideal | ❌ Too slow to propagate |
| Permanent domain routing | ❌ Not scalable | ✅ Correct solution |
| Blocking sites on one machine | ✅ Works well | ❌ Requires router/DNS config |
| Blocking sites network-wide | ❌ Must edit every machine | ✅ Configure at DNS/router level |
| Bypassing propagation delays | ✅ Perfect use case | ❌ Not applicable |
| Production website routing | ❌ Never use | ✅ Always use |
For production-grade DNS management, domain routing, and hosting infrastructure, you need reliable hosting services. Whether you're running a small business site on Shared Web Hosting or managing complex multi-server infrastructure on a VPS with cPanel, proper DNS configuration through your hosting provider is always the right long-term solution.
—
Frequently Asked Questions
Does editing the hosts file require a reboot?
No. Changes to the hosts file take effect immediately. However, you may need to flush your DNS cache (ipconfig /flushdns) and restart your browser to clear cached responses.
Can the hosts file affect all browsers?
Yes. The hosts file operates at the operating system level, below the browser. It affects all applications that use the system's network stack — including Chrome, Firefox, Edge, and any other software that makes DNS lookups.
What's the maximum number of entries in the hosts file?
There is no hard limit enforced by Windows, but performance may degrade with extremely large files (tens of thousands of entries). For large-scale blocking, consider using a dedicated DNS-based solution instead.
Can I add IPv6 addresses to the hosts file?
Yes. The hosts file supports both IPv4 and IPv6 addresses:
127.0.0.1 localhost
::1 localhost
2001:db8::1 www.example.comWhy can't I save the hosts file even as an administrator?
This is usually caused by antivirus software protecting the hosts file from modification. Check your antivirus settings and temporarily disable hosts file protection, or add an exception for Notepad.
—
Conclusion
The Windows 10 hosts file is a deceptively simple yet remarkably powerful tool for developers, system administrators, and power users alike. By understanding how it works and when to use it, you gain precise local control over domain name resolution — without touching a single DNS record.
To summarize the key takeaways:
- The hosts file is located at
C:WindowsSystem32driversetchosts - It overrides DNS resolution for any domain listed within it
- Always open your text editor as administrator before editing
- Flush your DNS cache after making changes with
ipconfig /flushdns - Use it for testing, blocking, and bypassing propagation — not as a permanent DNS solution
- Always back up the file before making changes and remove stale entries promptly
For everything beyond local machine configuration — from managing your domain's DNS records to deploying a fully configured web server — AlexHost provides the infrastructure and tools you need, including VPS Hosting, Dedicated Servers, Domain Registration, and more.
