How To Edit The Hosts File In Windows 11 (2026)
Short answer: open Notepad as administrator, open the hosts file in C:\Windows\System32\drivers\etc, add a line, and save.
Each line holds an IP address, at least one space, and a name, such as 127.0.0.1 example.com.
If you would rather not edit a text file, the Hosts File Editor in Microsoft PowerToys does the same job with a form.
What the hosts file does
The hosts file maps names to IP addresses, and Microsoft’s PowerToys page says the computer checks it before asking DNS.
That makes it useful for testing a site on a new server or pointing a name at a different address.
It lives in the folder %SystemRoot%\System32\drivers\etc, which is normally C:\Windows\System32\drivers\etc.
Quick answer: pick a method
| Goal | Method |
|---|---|
| Add or remove a line yourself | Notepad opened as administrator |
| Add entries with a form, toggle them on and off | PowerToys Hosts File Editor |
| Undo a bad edit | Restore the default hosts file using the Microsoft steps below |
| Make a change take effect | Run ipconfig /flushdns |
Edit the hosts file in Notepad
- Select Start, search for Notepad, right-click it, and choose Run as administrator.
- Select File, then Open.
- Go to
C:\Windows\System32\drivers\etc. - Change the file type drop-down to All Files.
- Select the file named hosts and select Open.
- Go to a new line at the bottom and type your entry.
- Select File, then Save.
If a pop-up appears when you save, Notepad does not have administrator rights, so close it and start again from step 1.
You can also open Terminal as administrator for the flush command later.
How to write a line
Put the IP address first, leave at least one space, then type the name, and start a comment with a hash mark.
| Line | What it does |
|---|---|
| 203.0.113.10 mysite.example | Sends mysite.example to the address 203.0.113.10 (a documentation address, replace it with yours) |
| 127.0.0.1 example.com | Points the name at your own PC, which blocks it |
| 0.0.0.0 example.com | Also blocks the name, and How-To Geek prefers it because 127.0.0.1 can cause problems in some programs |
| # my note | A comment that Windows ignores |
To remove an entry, delete its line and save the file again.
Edit it with PowerToys Hosts File Editor
Hosts File Editor is part of Microsoft PowerToys, so install PowerToys first.
- Turn on Hosts File Editor in PowerToys Settings.
- Select the PowerToys icon in the system tray, then select Hosts File Editor.
- Accept the warning about changing name resolution.
- Select New entry.
- Fill in the IP address, the Host name and an optional Comment.
- Turn on Active, then select Add.
- Select Save.
Microsoft says the editor has no keyboard shortcut.
The Filter icon narrows the list by Address, Hosts or Comment.
Fix: Failed to save hosts file
This message means the editor lacks administrator rights, and Microsoft says to turn on Open as administrator in its settings.
With that setting off, the editor opens read-only.
Hosts File Editor settings
| Setting | What it does |
|---|---|
| Open as administrator | Needed to edit the file; on by default |
| Show a warning at startup | Warns about DNS changes; on by default |
| Placement of additional content | New entries go to Top (default) or Bottom |
| Encoding | UTF-8 (default) or UTF-8 with BOM |
| Automatically delete backups | Never, Based on count, or Based on age and count |
Placement matters when entries conflict, because it affects which one takes precedence.
Automatic backups
Before your first save in a session, the editor makes a backup in the same folder named hosts_PowerToysBackup followed by a timestamp.
By default it deletes backups older than 15 days but always keeps the 5 most recent.
Notepad makes no backup, so copy the file first if you edit it there.
Make the change take effect
Open Terminal or Command Prompt and run ipconfig /flushdns.
Microsoft says this flushes and resets the DNS client resolver cache, discarding entries added earlier.
If a browser ignores the entry
How-To Geek warns that Chrome, Firefox and Edge can use DNS over HTTPS by default, which bypasses the hosts file.
In that case you may need to turn DNS over HTTPS off in the browser, or turn it on in Windows 11 so the file is still used.
Our guide to changing the DNS server in Windows 11 covers the Windows side.
Reset the hosts file to default
Microsoft’s reset steps apply to both Windows 11 and Windows 10.
- Open Notepad and paste Microsoft’s default hosts text, which starts with the line # Copyright (c) 1993-2009 Microsoft Corp.
- Select File, then Save as, and type “hosts” in quotation marks as the file name.
- Set the save type to All files so the file gets no extension.
- Save it to your desktop and close Notepad.
- Go to C:\Windows\System32\drivers\etc and rename the existing hosts file to Hosts.old.
- Copy the new file from your desktop into that folder and approve the administrator prompt.
The default file is mostly comments, and the localhost lines in it are commented out.
To see which address your PC uses at the moment, read our find your IP and MAC address guide.