|

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

GoalMethod
Add or remove a line yourselfNotepad opened as administrator
Add entries with a form, toggle them on and offPowerToys Hosts File Editor
Undo a bad editRestore the default hosts file using the Microsoft steps below
Make a change take effectRun ipconfig /flushdns

Edit the hosts file in Notepad

  1. Select Start, search for Notepad, right-click it, and choose Run as administrator.
  2. Select File, then Open.
  3. Go to C:\Windows\System32\drivers\etc.
  4. Change the file type drop-down to All Files.
  5. Select the file named hosts and select Open.
  6. Go to a new line at the bottom and type your entry.
  7. 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.

LineWhat it does
203.0.113.10 mysite.exampleSends mysite.example to the address 203.0.113.10 (a documentation address, replace it with yours)
127.0.0.1 example.comPoints the name at your own PC, which blocks it
0.0.0.0 example.comAlso blocks the name, and How-To Geek prefers it because 127.0.0.1 can cause problems in some programs
# my noteA 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.

  1. Turn on Hosts File Editor in PowerToys Settings.
  2. Select the PowerToys icon in the system tray, then select Hosts File Editor.
  3. Accept the warning about changing name resolution.
  4. Select New entry.
  5. Fill in the IP address, the Host name and an optional Comment.
  6. Turn on Active, then select Add.
  7. 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

SettingWhat it does
Open as administratorNeeded to edit the file; on by default
Show a warning at startupWarns about DNS changes; on by default
Placement of additional contentNew entries go to Top (default) or Bottom
EncodingUTF-8 (default) or UTF-8 with BOM
Automatically delete backupsNever, 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.

  1. Open Notepad and paste Microsoft’s default hosts text, which starts with the line # Copyright (c) 1993-2009 Microsoft Corp.
  2. Select File, then Save as, and type “hosts” in quotation marks as the file name.
  3. Set the save type to All files so the file gets no extension.
  4. Save it to your desktop and close Notepad.
  5. Go to C:\Windows\System32\drivers\etc and rename the existing hosts file to Hosts.old.
  6. 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.

Sources

Leave a Reply

Your email address will not be published. Required fields are marked *