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.
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.
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.
The Windows hosts file is stored in the following folder:
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.
hosts.txt if the file type is set to Text Documents (*.txt). When saving, choose All Files (*.*) and use the exact file name hosts.
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.
# 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:
# localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost
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.
C:\Windows\System32\drivers\etc.hosts_backup or hosts_original_backup.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.
C:\Windows\System32\drivers\etc.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.
If the hosts file is heavily damaged, renamed, or difficult to edit manually, you can replace it using an elevated Command Prompt.
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
type nul > hosts clears the current hosts file. Make a backup first if you may need old custom entries.
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.
$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.
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.
| Problem | What to do |
|---|---|
| Notepad says access is denied | Close Notepad, then open it again with Run as administrator. |
| File saves as hosts.txt | Choose All Files (*.*) and name the file exactly hosts. |
| File is read-only | Open an elevated terminal and run attrib -r C:\Windows\System32\drivers\etc\hosts. |
| Security software blocks changes | Temporarily allow the change only if you are sure the edit is legitimate. |
| You cannot see the file | Switch the Open dialog filter from Text Documents to All Files. |
After resetting the hosts file, clear the Windows DNS resolver cache. This forces Windows to discard cached domain lookups and read fresh information again.
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.
After restoring the file, test whether websites resolve normally. You can use ping, nslookup, and browser testing.
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.
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.
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.
hosts.txt will not work as the Windows hosts file.
ipconfig /flushdns and restarting the browser is enough. Restart Windows only if the problem continues or if another application keeps the old network state.
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.
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.
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.
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.