Whether you are testing a site on a new server before changing public DNS, pointing a domain at a local development server, or blocking a site, the Windows hosts file is the fastest way to override DNS on one machine. This DevAnswers guide shows how to edit the hosts file on Windows 11 and 10, the catch being that Windows protects it, so you cannot just double-click and save.
Edit the Hosts File with Notepad (Run as Administrator)
The hosts file is a protected system file, so the one rule that trips everyone up is that your editor must run elevated. Using Notepad:
- Click Start and type
Notepad. - Right-click Notepad in the results and choose Run as administrator.
- In Notepad, go to File > Open.
- Browse to
C:\Windows\System32\drivers\etc. - Change the file-type filter (next to the File name box) from Text Documents (*.txt) to All Files (*.*), or the extensionless
hostsfile will not show. - Select hosts and click Open.
- Make your changes, then choose File > Save.
Where the Hosts File Is and Its Format
On every modern Windows version the file lives at the same path:
C:\Windows\System32\drivers\etc\hosts
Each active line is an IP address, then at least one space or tab, then a hostname. Lines starting with # are comments and are ignored. A few example entries:
# Local development overrides
127.0.0.1 myapp.test
192.168.1.50 devanswers.test
# Block a site (use the hostname you want to block)
0.0.0.0 tracker.devanswers.test
Point devanswers.test at the IP of the server you want this PC to reach for that name. Use 127.0.0.1 for a service running on this machine, or a LAN IP for another box. Do not remove the default localhost lines, as other software depends on them.
The Easier Way: PowerToys Hosts File Editor
On Windows 10 and 11, if you edit the hosts file often, Microsoft’s free PowerToys includes a dedicated Hosts File Editor, a graphical tool that handles the elevation and formatting for you. It opens with administrator rights by default, lets you add, enable, or disable individual entries with a toggle, and keeps automatic backups of the file before each editing session.
Once PowerToys is installed, turn on Hosts File Editor in PowerToys Settings, open it, and use Add to enter an IP, a hostname, and an optional comment. The toggle beside each entry lets you switch an override on or off without deleting it, which is handy when testing.
Apply and Verify the Change (Flush DNS)
Windows caches DNS lookups, so after saving you should clear the resolver cache to be sure the new entry is used. Run this in PowerShell (or Command Prompt):
ipconfig /flushdns
Windows IP Configuration
Successfully flushed the DNS Resolver Cache.
Then confirm the override resolves to the IP you set. Pinging the hostname is the quickest check:
ping devanswers.test
The reply should show the IP address from your hosts file. You can also just open the site in your browser; if it still loads the old destination, restart the browser so it drops its own internal DNS cache.
Troubleshooting: Can’t Save or No Effect
- “Access is denied” or the save fails. The editor was not run as administrator. Close it, relaunch with Run as administrator, and open the file again.
- A file called
hosts.txtappears. Notepad added a.txtextension. When saving, set Save as type to All Files and use the namehostswith no extension; delete the strayhosts.txt. - The change has no effect. Run
ipconfig /flushdns, restart your browser, and double-check there is no#at the start of your line (which would comment it out). - Saving is blocked even as administrator. Antivirus or Windows Controlled Folder Access can protect the
etcfolder. Temporarily allow your editor through it, edit, then re-enable protection. See our notes on Windows name-resolution issues if a hostname still will not resolve.
Summary
Edit C:\Windows\System32\drivers\etc\hosts with an editor run as administrator, add lines of IP hostname, save, then run ipconfig /flushdns and verify with ping. For frequent edits, the PowerToys Hosts File Editor removes the elevation and formatting friction.
Comments