The Windows hosts file is edited by opening Notepad as administrator, loading C:\Windows\System32\drivers\etc\hosts, and saving with admin rights.
Most guides skip the one permission that makes hosts-file edits actually save: administrator access. Without it, every change disappears the moment you try to save. Knowing how to edit Windows host file gives you direct control over name resolution on your machine, letting you block sites or redirect domains without touching your router. The process takes about a minute once you know which menu options to use and why admin rights matter.
Editing the Windows Hosts File: The Permission You Need
The hosts file lives inside a protected system folder, and Windows blocks unprivileged programs from writing to it. That is why the single most important step is opening your text editor with administrator rights. Without that elevation, any edit attempt fails with a permission error, and the file stays unchanged.
The file itself is plain text with no file extension. Microsoft’s guidance is clear: never add a .txt or any other extension to the file name, or Windows stops recognizing it as the hosts file. The default location is always C:\Windows\System32\Drivers\Etc, which you can also reach by typing %WinDir%\System32\Drivers\Etc into any address bar.
How to Edit the Hosts File: Step-by-Step on Windows
These four steps work identically on Windows 10, Windows 8, Windows 7, and Windows Vista. Follow them in order, and you will see the changes take effect immediately after saving.
- Open Notepad as administrator. Press the Windows key, type Notepad, right-click the result, and select Run as administrator. Click Yes if User Account Control prompts you.
- Open the hosts file. In Notepad, go to File > Open. Navigate to
C:\Windows\System32\Drivers\Etc. Change the file-type filter from Text Documents (*.txt) to All Files (*.*). Select the file named hosts — it has no extension — and click Open. - Make your changes. Each entry goes on its own line: the IP address first, then one or more hostnames separated by spaces. A line that starts with
#is a comment and is ignored. For example,127.0.0.1 www.facebook.comblocks Facebook on this machine by sending the request back to your own computer. - Save the file. Choose File > Save. Do not change the file name or add an extension. When the save succeeds, the title bar in Notepad shows the file path without an asterisk — that asterisk disappearing is your confirmation the edit stuck.
What Happens If You Skip Administrator Mode?
If you open the hosts file in a normal instance of Notepad, you can view and edit the text freely. But when you try to save, Notepad shows an error telling you it cannot write to the file. The change goes nowhere. The fix is simple: close Notepad, reopen it as administrator, and repeat the same steps. The original file is not damaged by a failed save — it simply remains in its original state, so no harm done.
Common Hosts File Entries
The table below shows the most useful entry patterns, what each one does, and when you would use it on your own machine.
| Entry | Purpose | Example Use Case |
|---|---|---|
127.0.0.1 localhost |
Maps the name ‘localhost’ to your own machine | Required for most Windows networking to function correctly |
127.0.0.1 www.facebook.com |
Redirects Facebook to your local machine, effectively blocking it | Blocking distracting sites during focused work hours |
0.0.0.0 www.example.com |
Alternative block using the null address | Blocking ad servers or tracking domains |
::1 localhost |
IPv6 version of the localhost mapping | Required if IPv6 is enabled on your network |
192.168.1.100 devserver.local |
Maps a local network IP to a friendly hostname | Local web development and testing |
127.0.0.1 www.doubleclick.net |
Blocks the DoubleClick ad network at the system level | Adding a layer of privacy protection |
185.199.108.153 docs.github.com |
Overrides a hostname to a specific IP address | Accessing a service through a specific CDN node |
Add these entries one per line anywhere in the file below the commented header section. After saving, the changes take effect immediately — no reboot or browser restart required. If the changes do not appear to work, run ipconfig /flushdns in an administrator Command Prompt to clear the local DNS cache.
How to Reset the Hosts File to Default
If the file becomes corrupted or you want to undo every change, Microsoft provides a full reset procedure. Paste the default hosts content into a new Notepad document, save it as "hosts" (with the quotation marks) using the All Files (*.*) filter, and place the new file on your desktop. Then rename the existing hosts file in %WinDir%\System32\Drivers\Etc to Hosts.old and move the new file into that folder. The complete default content and detailed steps are on Microsoft’s official hosts reset guide.
PowerToys Hosts File Editor: A GUI Alternative
If you edit the hosts file often or prefer a visual interface, Microsoft PowerToys includes a dedicated Hosts File Editor. The tool lists every active entry, lets you toggle individual rules on and off with a switch, and handles admin elevation automatically. To add a new entry, open the editor, select New entry, enter the IP address and Host name, optionally add a comment, turn the Active toggle on, and select Add. The editor writes changes back to the same system file, so entries created in PowerToys appear in the raw hosts file and vice versa. Because PowerToys handles the admin requirement behind the scenes, it eliminates the most common failure point entirely.
Which Editing Method Fits Your Workflow?
For a one-time edit or a quick block, opening Notepad as administrator and editing the raw file is the fastest path — the whole process takes under a minute once you know the steps. If you manage many entries, toggle blocks on and off regularly, or want a cleaner view of what is active, the PowerToys Hosts File Editor saves time and protects against syntax errors. Either way, back up the current hosts file before any change by copying it to your desktop or renaming it to Hosts.backup inside the Etc folder. That backup takes five seconds and saves you from rebuilding entries from memory later.
References & Sources
- Microsoft Support. “How to Reset the Hosts File Back to the Default.” Official reset instructions and default file content.
- Microsoft Learn. “PowerToys Hosts File Editor.” Documentation for the GUI editing utility included with PowerToys.
