To edit the hosts file in Windows 11, run Notepad as an administrator, open C:\Windows\System32\drivers\etc\hosts, add your entry on a new line (IP address, a space, then the domain name), and save. Then run ipconfig /flushdns so Windows uses the change right away.
These steps cover current versions of Windows 11 and also work on Windows 10, which stopped getting security updates on October 14, 2025. You need an administrator account. The hosts file only affects this one PC. Use it to block a site, test a website on a new server, or name a device on your network. For other ways to block a site, compare the methods for blocking a website on Chrome.
What the Hosts File Does
When you visit a website, Windows needs its IP address. Entries in the hosts file are loaded into Windows’ DNS cache, so they win over the answer from your DNS server. Point a name at 0.0.0.0 and the site can’t load; point it at a server’s IP and your PC goes there instead.
To see which servers your PC asks for everything else, check your primary and secondary DNS servers.
Microsoft describes the file as plain text: each entry sits on its own line, with an IP address followed by the host name, separated by at least one space. Lines starting with # are comments, and a comment can also follow an entry. The default file contains only comments, so it changes nothing until you add a line.

Back Up the Hosts File Before Editing
In File Explorer, open %WinDir%\System32\drivers\etc and copy the file named hosts to a separate backup folder, such as Documents. Write down which lines you add. To undo your own change later, reopen the file as administrator, remove only the line you added, save, and flush DNS again. If you restore the backup instead, copy it back with administrator approval and check that its name is exactly hosts, with no .txt extension.
Method 1: Edit the Hosts File With Notepad

- Select Start and type Notepad.
- Right-click Notepad and choose Run as administrator. Select Yes in the User Account Control prompt.
- In Notepad, select File > Open.
- Paste
C:\Windows\System32\drivers\etcinto the address bar and press Enter. - Change the file type menu from Text Documents (*.txt) to All files (*.*). The hosts file has no extension, so it’s hidden otherwise.

- Select hosts and choose Open. You should see Microsoft’s comment lines, plus any entries added earlier.
- Click at the end of the last line, press Enter, and type your entry, for example
0.0.0.0 example.com. - Press Ctrl + S. The file should save without any prompt. If a Save As window or a permission error appears, Notepad isn’t running as administrator; see the troubleshooting section.
Shortcut: press Windows + R, paste notepad C:\Windows\System32\drivers\etc\hosts, then hold Ctrl + Shift and select OK. That opens the file in an elevated Notepad in one step. If you’ve turned on sudo for Windows (Windows 11 version 24H2 or later, under Settings > System > Advanced), sudo notepad C:\Windows\System32\drivers\etc\hosts in Terminal does the same. Use a plain text editor, never Word, which can add formatting.
If Windows is on a different drive, replace C: with that drive letter. The universal path is %WinDir%\System32\drivers\etc.
Make the Change Take Effect
- Right-click Start and choose Terminal (Admin).
- Type
ipconfig /flushdnsand press Enter to clear the DNS cache. Windows replies that it flushed the DNS Resolver Cache. - Test it: run
ping example.com -n 1and check that the address shown next to the name matches your entry. The ping itself can time out even when the new address is being used, so judge by the address, not the reply. - Close and reopen your browser.
If an old address keeps showing up, run ipconfig /displaydns to see what’s in the DNS cache, and nbtstat -R to clear the NetBIOS name cache.
If your browser ignores the change
Check the hostname in the address bar: example.com and www.example.com need separate entries, and a redirect may send you to a different hostname. A VPN, proxy, browser extension, or cached page can also affect what you see. On a work PC, ask your administrator to check those settings.
Method 2: Use PowerToys Hosts File Editor
Microsoft’s free PowerToys includes a Hosts File Editor with a form, so you don’t have to worry about formatting.
- Install PowerToys from the Microsoft Store or from Microsoft’s PowerToys install page if you don’t have it.
- Open PowerToys Settings, select Hosts File Editor, and make sure it’s turned On.
- Select the PowerToys icon in the system tray, then select Hosts File Editor. Approve the admin prompt.
- Select New entry, type the IP address and Host name, add an optional comment, turn on Active, and select Add.
- The entry appears in the list and is written to the hosts file. By default, PowerToys places new entries near the top of the file, after Windows’ comment lines.
Microsoft’s documentation says the editor needs Open as administrator (on by default) to save, and it backs up the hosts file to the same etc folder, named hosts_PowerToysBackup plus the date, on the first save of each session. If you see “Failed to save hosts file,” turn Open as administrator back on. We also use PowerToys to change keybinds on Windows 11.
Method 3: Add a Line From Terminal
For a quick one-line change, open Terminal (Admin) and run the following, replacing the entry with yours. The `n starts a new line so your entry isn’t stuck to the end of the last one.
Add-Content -Path "$env:windir\System32\drivers\etc\hosts" -Value "`n0.0.0.0 example.com"
The command shows no output. Run Get-Content $env:windir\System32\drivers\etc\hosts to check that the new line is at the bottom, then flush DNS. The full reference is on the Add-Content page.
Hosts File Examples
| Goal | Line to add | Notes |
|---|---|---|
| Block a site | 0.0.0.0 example.com |
Add 0.0.0.0 www.example.com too; each name needs its own entry |
| Test a site on a new server | 203.0.113.10 example.com |
Use the new server’s IP; remove the line after DNS moves |
| Name a device on your network | 192.168.1.50 nas |
Then open http://nas from this PC |
| Turn an entry off | # 0.0.0.0 example.com |
The # makes it a comment |
Use 0.0.0.0 rather than 127.0.0.1 for blocking, because a program running on your PC could answer on 127.0.0.1. Wildcards such as *.example.com don’t work; list every subdomain you want to block. If a site won’t load and you didn’t block it here, you may need to unblock websites on Windows 11.
Reset the Hosts File to the Default
If you’re not sure what’s been changed, or sites stopped loading after someone edited the file, Microsoft’s reset steps replace it with a clean copy:
- Open Notepad (not as administrator) and paste Microsoft’s default hosts text from that page.
- Select File > Save as, type
"hosts"with the quotes as the file name, set Save as type to All files, and save it to the desktop. - Open
%WinDir%\System32\drivers\etcin File Explorer. - Rename the existing hosts file to hosts.old.
- Move the new hosts file from the desktop into the folder and approve the admin prompt.
- Flush DNS again with
ipconfig /flushdns.
Troubleshooting
“Access denied” or Notepad asks where to save
Notepad isn’t running as an administrator. Close it and reopen it with Run as administrator. If it still fails, right-click the hosts file, choose Properties, and clear Read-only. Another workaround: copy hosts to the desktop, edit the copy, then copy it back into the etc folder and approve the prompt.
If right-clicking Notepad doesn’t offer the option, there are other ways to run an app as administrator in Windows 11.
The file saved as hosts.txt
Windows ignores hosts.txt. In the etc folder, turn on View > Show > File name extensions, delete the extra hosts.txt, and save again with All files selected.
Windows Security warns about the hosts file
Malware often edits this file to send you to fake sites, which is why Microsoft Defender watches it. An alert named something like SettingsModifier:Win32/PossibleHostsFileHijack means Defender saw entries it didn’t expect. Compare the flagged lines with the changes you made and with your backup. Don’t automatically allow the alert or add an exclusion. If an entry is unexplained, remove it or reset the file using the steps above, then run a full scan in Windows Security. On a managed PC, ask your administrator.
Nothing changed
Check the hostname spelling, the IP address, and whether the line starts with #, which makes it inactive. Remove conflicting duplicate entries you added, confirm the file is named hosts without an extension, save, flush DNS, and reopen the browser. Check any redirected hostname separately.
Frequently Asked Questions
Where is the hosts file in Windows 11?
C:\Windows\System32\drivers\etc\hosts. It’s a file named hosts with no extension.
Do I need to restart after editing it?
No. Flushing the DNS cache and reopening the browser is enough.
Is it safe to edit the hosts file?
Yes, if you only add lines you understand and keep a backup. Add a comment explaining each change so you can find and undo it later.
Can I use the hosts file to block ads?
Only site by site. Each blocked name needs its own line, and wildcards don’t work. Avoid pasting in large lists from unknown sources, since a bad line can redirect a real site somewhere unsafe.
Hard to read long lines while editing? It helps to turn on word wrap in Notepad.

Matthew Burleigh is the founder, head writer, and editor of Solve Your Tech, which he launched in 2012. He has written technology tutorials since 2008 and worked in IT since 2003, including small-business support, IT management, and consulting. He holds Bachelor’s and Master’s degrees in Computer Science from Arizona State University.
Matthew writes practical guides for Windows, iPhone and iPad, Microsoft Office, Outlook, Google apps, and Android. Solve Your Tech’s guides are checked step by step against the device or app maker’s own documentation and tested on his own devices whenever he has the hardware or software, with clear steps, sources, and update dates.
Read more about Matthew and how Solve Your Tech writes and updates its guides, or report a correction.