How to Edit the Hosts File in Windows 10 and Older Versions
Learn how to modify your system's hosts file to control domain name resolution and block unwanted websites on Windows PCs.

The hosts file is a powerful tool that allows you to override DNS settings and control how your Windows computer resolves domain names to IP addresses. While most users never need to touch this file, knowing how to edit it can be useful for tasks like blocking websites or speeding up web browsing. This guide will walk you through the process of locating and modifying the hosts file on Windows 10 and older versions.
What is the Hosts File?
The hosts file acts as a local DNS resolver, mapping domain names to specific IP addresses. When you enter a web address, your computer checks the hosts file before querying external DNS servers. This allows you to create custom domain-to-IP mappings or block access to certain websites by redirecting them to invalid IP addresses.
Locating the Hosts File
On all modern Windows versions (Windows 10, 8, 7, Vista, and XP), the hosts file is located in the same directory:
C:\Windows\System32\drivers\etc\
The file is simply named "hosts" with no extension.
How to Edit the Hosts File
Editing the hosts file requires administrator privileges. Here's a step-by-step process to open and modify it:
Step 1: Open Notepad as an administrator. Press the Windows key + R to open the Run dialog, type "notepad", and press Ctrl + Shift + Enter.
Step 2: In Notepad, click File > Open. Navigate to C:\Windows\System32\drivers\etc\.
Step 3: Change the file type filter from "Text Documents (*.txt)" to "All Files (*.*)".
Step 4: Select the "hosts" file and click Open.
Step 5: Make your desired changes to the file. Each entry should be on a new line with the IP address first, followed by at least one space, then the domain name. For example:
127.0.0.1 localhost
192.168.1.10 myserver.local
0.0.0.0 adserver.example.com
Step 6: To block a website, use the IP address 0.0.0.0 or 127.0.0.1. For example:
0.0.0.0 www.timewastingsite.com
Step 7: Save your changes by clicking File > Save.
If you encounter permission issues when trying to save, you may need to use an alternative method:
Step 1: Save the modified hosts file to your desktop with a different name (e.g., "hosts.new").
Step 2: Open File Explorer and navigate to C:\Windows\System32\drivers\etc\.
Step 3: Rename the existing hosts file to "hosts.old".
Step 4: Copy the new hosts file from your desktop into the etc folder.
Step 5: Rename the new file to simply "hosts" (no extension).
Common Uses for Editing the Hosts File
There are several reasons you might want to modify your hosts file:
- Blocking access to specific websites.
- Creating shortcuts to frequently accessed servers using custom hostnames.
- Testing websites in development without changing DNS settings.
- Improving browsing speed by bypassing DNS lookups for common sites.
Cautions and Considerations
While editing the hosts file can be useful, it's important to keep a few things in mind:
- Always make a backup of the original hosts file before making changes.
- Be careful not to block essential services or websites accidentally.
- Some antivirus software may flag changes to the hosts file as suspicious activity.
- Remember that hosts file entries override DNS settings, which can cause confusion if you forget about custom entries.
Modifying the hosts file gives you granular control over how your Windows PC resolves domain names. Whether you're blocking distracting websites or optimizing your local network, this powerful tool is just a few edits away. Just remember to use it responsibly and keep a backup of your original file.