How to Edit the Hosts File on Windows 11 and 10

A flat vector illustration of a system file document with a pencil tool editing it, set against a deep teal background.

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:

  1. Click Start and type Notepad.
  2. Right-click Notepad in the results and choose Run as administrator.
  3. In Notepad, go to File > Open.
  4. Browse to C:\Windows\System32\drivers\etc.
  5. Change the file-type filter (next to the File name box) from Text Documents (*.txt) to All Files (*.*), or the extensionless hosts file will not show.
  6. Select hosts and click Open.
  7. Make your changes, then choose File > Save.
If you open Notepad normally (not as administrator), the file opens read-only and your save usually fails with “Access is denied”. Always launch the editor with Run as administrator first. If saving still fails even when elevated, antivirus or Controlled Folder Access may be blocking it (see Troubleshooting).

Where the Hosts File Is and Its Format 

On every modern Windows version the file lives at the same path:

Hosts file 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:

hosts
# 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):

PowerShell
ipconfig /flushdns
Output
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:

PowerShell
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.txt appears. Notepad added a .txt extension. When saving, set Save as type to All Files and use the name hosts with no extension; delete the stray hosts.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 etc folder. 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.

Support DevAnswers
Written, tested and maintained by one developer. Your support keeps these guides accurate and ad-light.
Buy me a coffee

Comments

Leave a reply