Windows Guide · Network Troubleshooting

How to Restore the Hosts File in Windows 10 & Windows 11

A complete guide to resetting the Windows hosts file to its default state, removing unwanted redirects, fixing permission errors, and checking whether name resolution works correctly again.

🧭 Default hosts file 🖥 Windows 10 & 11 🔐 Admin rights required 🛠 Manual & command methods

What Is the Hosts File in Windows?

The hosts file is a small plain-text system file that Windows checks before using DNS servers. It can map a domain name to a specific IP address. For example, a line in the hosts file can force example.com to open from a chosen IP address or block a domain by pointing it to 127.0.0.1.

Because the hosts file is checked early in name resolution, wrong or malicious entries can cause websites not to open, redirect browsers to the wrong address, block antivirus updates, or interfere with software activation and online services.

🌐
Controls name resolution
Windows can use the hosts file to resolve domains before it asks configured DNS servers.
🚫
Can block or redirect sites
A single line can block a domain, redirect it locally, or point it to another IP address.
🛡️
Often targeted by malware
Malware and unwanted software may modify this file to block security sites or redirect traffic.
ℹ️
Important Restoring the hosts file does not reset your router, browser, VPN, proxy, or DNS server settings. It only removes local domain-to-IP overrides stored in the Windows hosts file.

When Should You Restore the Hosts File in Windows?

You should reset or restore the hosts file when website access problems are caused by incorrect local mappings. This is especially useful after malware removal, after using ad-blocking scripts, or after manually editing the file for testing.

Where Is the Hosts File Located in Windows 10 and Windows 11?

The Windows hosts file is stored in the following folder:

C:\Windows\System32\drivers\etc\hosts

The file has the name hosts and normally has no file extension. It should not be named hosts.txt, hosts.ini, or hosts.bak if you want Windows to use it.

⚠️
Common mistake Notepad may save the file as hosts.txt if the file type is set to Text Documents (*.txt). When saving, choose All Files (*.*) and use the exact file name hosts.

Default Hosts File Content for Windows 10 and Windows 11

A clean Windows hosts file may contain only comments and the default localhost examples. Lines that begin with # are comments and are ignored by Windows.

Default hosts file C:\Windows\System32\drivers\etc\hosts
# Copyright (c) Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#       127.0.0.1       localhost
#       ::1             localhost

You can also use a minimal clean hosts file with no active mappings:

Minimal clean version No active redirects
# localhost name resolution is handled within DNS itself.
#       127.0.0.1       localhost
#       ::1             localhost

Back Up the Current Hosts File Before Restoring It

Before editing the hosts file, create a backup. This is useful if the file contains legitimate custom entries for a local server, development environment, intranet, virtual machine, or testing domain.

  1. Open File Explorer.
  2. Go to C:\Windows\System32\drivers\etc.
  3. Copy the file named hosts.
  4. Paste it to the Desktop or another safe folder.
  5. Rename the copy to hosts_backup or hosts_original_backup.
💡
Tip If you are restoring the file after malware cleanup, keep the backup only for inspection. Do not restore suspicious entries back into the active hosts file.

How to Restore the Hosts File with Notepad

This is the easiest method for most users. The key requirement is to open Notepad with administrator rights, because the hosts file is located in a protected system folder.

Restore hosts manually in Notepad
  1. Click Start and type Notepad.
  2. Right-click Notepad and select Run as administrator.
  3. In Notepad, click File → Open.
  4. Open this folder: C:\Windows\System32\drivers\etc.
  5. In the lower-right corner, change Text Documents (*.txt) to All Files (*.*).
  6. Select the file named hosts and click Open.
  7. Delete suspicious or unwanted active entries.
  8. Paste the default hosts file content from this guide.
  9. Click File → Save.

After saving the file, continue with the DNS cache flush section below. Without clearing the DNS cache, Windows or your browser may temporarily keep using cached results.

How to Reset the Hosts File Using Command Prompt

If the hosts file is heavily damaged, renamed, or difficult to edit manually, you can replace it using an elevated Command Prompt.

Create a clean hosts file with CMD
  1. Click Start, type cmd.
  2. Right-click Command Prompt and select Run as administrator.
  3. Run the following commands one by one:
cd /d C:\Windows\System32\drivers\etc
copy hosts hosts.bak
attrib -r -s -h hosts
type nul > hosts

Then add the minimal default content:

echo # localhost name resolution is handled within DNS itself. > hosts
echo #       127.0.0.1       localhost >> hosts
echo #       ::1             localhost >> hosts
⚠️
Warning The command type nul > hosts clears the current hosts file. Make a backup first if you may need old custom entries.

How to Restore the Hosts File Using PowerShell

PowerShell is convenient if you want to replace the file content in a controlled way. Run it as administrator and write a clean default hosts file.

Reset hosts with PowerShell
  1. Right-click Start.
  2. Select Terminal (Admin), Windows PowerShell (Admin), or Command Prompt (Admin) depending on your Windows version.
  3. Run this command:
$hostsPath = "$env:SystemRoot\System32\drivers\etc\hosts"
Copy-Item $hostsPath "$hostsPath.bak" -ErrorAction SilentlyContinue
@"
# localhost name resolution is handled within DNS itself.
#       127.0.0.1       localhost
#       ::1             localhost
"@ | Set-Content -Path $hostsPath -Encoding ASCII

This creates a backup named hosts.bak in the same folder and writes a clean hosts file without active redirects.

Fix “Access Denied” When Editing the Hosts File

If Windows does not let you save changes, the usual cause is missing administrator privileges, read-only attributes, antivirus protection, or saving the file with the wrong extension.

ProblemWhat to do
Notepad says access is deniedClose Notepad, then open it again with Run as administrator.
File saves as hosts.txtChoose All Files (*.*) and name the file exactly hosts.
File is read-onlyOpen an elevated terminal and run attrib -r C:\Windows\System32\drivers\etc\hosts.
Security software blocks changesTemporarily allow the change only if you are sure the edit is legitimate.
You cannot see the fileSwitch the Open dialog filter from Text Documents to All Files.
Do not weaken permissions permanently Avoid giving full control of the hosts file to regular users. The file is protected for a reason. Edit it as administrator, save the change, and keep normal system permissions intact.

Flush DNS Cache After Restoring the Hosts File

After resetting the hosts file, clear the Windows DNS resolver cache. This forces Windows to discard cached domain lookups and read fresh information again.

Flush DNS from Command Prompt or Terminal
  1. Open Command Prompt, PowerShell, or Terminal.
  2. Run this command:
ipconfig /flushdns

If the operation succeeds, Windows will show a message that the DNS Resolver Cache was successfully flushed.

It is also useful to close and reopen your browser. Some browsers keep their own DNS cache or connection pool for a short time.

How to Check Whether the Restored Hosts File Works

After restoring the file, test whether websites resolve normally. You can use ping, nslookup, and browser testing.

Check a domain from the command line

Open Command Prompt and run:

ping example.com

If the hosts file contains no active entry for the domain, Windows should resolve it through DNS instead of a local hosts override.

Find active entries in the hosts file

Active entries are lines that do not begin with # and are not empty. You can inspect them manually or use PowerShell:

Get-Content "$env:SystemRoot\System32\drivers\etc\hosts" | Where-Object { $_ -and $_ -notmatch '^\s*#' }

If the command returns nothing, there are no active hosts file mappings.

Security Check: Which Hosts File Entries Are Suspicious?

Not every hosts entry is malicious. Developers, administrators, ad-blocking tools, and local testing environments may use the file intentionally. However, some entries are a warning sign.

🛡️
Recommended follow-up If suspicious hosts entries return after you delete them, scan Windows with Microsoft Defender or another trusted antivirus tool. A recurring change usually means another program is modifying the file again.

Frequently Asked Questions About Restoring the Windows Hosts File

Q Is it safe to delete everything from the hosts file?
Yes, in most home-user cases it is safe to clear active entries from the hosts file. Windows does not require custom hosts entries for normal internet access. However, if you use local development domains, intranet mappings, virtual machines, or server aliases, back up the file before clearing it.
Q Should the hosts file have a file extension?
No. The correct file name is hosts with no extension. A file named hosts.txt will not work as the Windows hosts file.
Q Do I need to restart Windows after restoring the hosts file?
Usually no. In most cases, running ipconfig /flushdns and restarting the browser is enough. Restart Windows only if the problem continues or if another application keeps the old network state.
Q Can the hosts file block websites?
Yes. A domain can be blocked by pointing it to 127.0.0.1, 0.0.0.0, or another unreachable address. This is why restoring the hosts file can fix websites that are blocked only on one Windows PC.
Q Why do changes to the hosts file not work?
Common causes include saving the file as hosts.txt, forgetting to run Notepad as administrator, browser DNS caching, typing the domain incorrectly, or placing a # at the start of the line, which turns it into a comment.

Best Way to Restore the Hosts File in Windows

The most reliable way to restore the hosts file is to open Notepad as administrator, open C:\Windows\System32\drivers\etc\hosts, replace suspicious entries with the default clean content, save the file without an extension, and then run ipconfig /flushdns.

🏁 Bottom Line

If websites are blocked, redirected, or behave differently only on one Windows computer, the hosts file is one of the first places to check. Resetting it to a clean default state removes local domain overrides and helps restore normal DNS-based browsing.