Amazon Cyber Monday deals See deals →ad

Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

Windows Hosts File Location and How to Find and Edit It

The Windows hosts file is located at %SystemRoot%\System32\drivers\etc\hosts. On most PCs, Windows is installed in C:\Windows, so the full path is C:\Windows\System32\drivers\etc\hosts; the file has no extension.

The Exact Hosts File Path

The standard location is inside the Windows system folder, in System32\drivers\etc. The environment variable %SystemRoot% stands for the folder containing the active Windows installation. It is usually C:\Windows, but Windows can be installed on another drive or in a differently named folder. Using the variable in the path avoids assuming that Windows is on drive C.

The same location is used by current desktop editions such as Windows 10 and Windows 11, and by Windows Server installations. Windows does not keep a separate hosts file for each user: this is a system-wide file. Its name is simply hosts, with no .txt or other suffix. File Explorer may hide extensions for known file types, so check the actual filename if you are unsure whether an editor saved it as hosts.txt.

To open the location in File Explorer, enter %SystemRoot%\System32\drivers\etc in the address bar and press Enter. The folder also contains related network files, so make sure you select hosts, not a similarly named file such as lmhosts.sam.

What the Hosts File Does

The hosts file is a plain-text list that associates IP addresses with hostnames. When Windows or an application looks up a name, Windows name-resolution components can consult this local file as part of resolving it. A matching hosts entry can therefore direct a hostname to the specified address instead of relying on an ordinary DNS answer. It can be useful for a local development site, a test server, or troubleshooting a name-resolution problem.

For example, a line such as 203.0.113.25 portal.example.test associates that example hostname with the example IP address. The address block shown here is reserved for documentation, not a real service. A hosts entry applies to the hostname, not to a complete web address: it cannot distinguish between pages such as /help and /account, and it does not specify a port. It also does not create a website or make the destination server available; it only supplies a local name-to-address mapping.

Because the file is read locally, a hosts mapping can work without a DNS server being available. Conversely, it can cause a site to go to the wrong address if an obsolete or mistaken entry remains in the file. A hosts entry is not a wildcard rule: adding example.test does not automatically map every subdomain such as shop.example.test.

How to Open It in Windows

You can view the file with a text editor, but saving changes usually requires administrator permission. One straightforward option is to launch Notepad with elevated rights before opening the file:

  1. Open the Start menu, search for Notepad, and choose Run as administrator. Approve the User Account Control prompt if it appears.
  2. In Notepad, choose Open and browse to %SystemRoot%\System32\drivers\etc, or enter the full path in the filename field.
  3. If the file list appears empty, change the file-type filter from text documents to all files. Select the file named hosts.
  4. After making a change, use Save. If Windows reports that you do not have permission, confirm that the editor was opened as administrator rather than trying to change the file permissions unnecessarily.

You can also start an elevated editor from an administrator Command Prompt or Terminal, but the Start menu method is often easier. A normal, non-elevated editor may let you view the file while refusing to save it, or may offer to save a separate copy somewhere else. Check the location in the Save dialog: a copy on the Desktop does not replace the system hosts file.

Editing Entries Safely

Before editing, make a backup by copying the original file to a location you can find again. Keep the backup outside the etc folder, and do not replace the active file with an unfamiliar download. Then make the smallest change needed. To add a mapping, put an IP address first and one or more hostnames after it, separated by spaces or tabs.

  • 203.0.113.25 portal.example.test maps one name to the example address.
  • 203.0.113.25 portal.example.test files.example.test maps both listed names to that same address.
  • # 203.0.113.25 portal.example.test is a comment because the line begins with a hash sign; it has no effect.

Use a new line for each mapping, and avoid adding punctuation such as a comma between the address and hostname. If you need to undo a rule, delete that line or put # at its start, save the file, and test again. Do not remove existing entries merely because they are unfamiliar; standard localhost mappings and comments may be present, and a computer or organization may rely on custom entries.

After saving, confirm that the filename remains hosts without an extension. In Notepad’s Save As dialog, selecting all files rather than text documents can help prevent an accidental .txt suffix. If Windows says access is denied, do not work around it by saving an edited copy over the original through a different folder; reopen the editor as administrator and save the actual system file.

When Changes Take Effect

Windows normally checks local name-resolution information as part of resolving a hostname, but a result may also be cached. If a newly added or removed mapping does not appear to take effect, open Command Prompt as an administrator and run ipconfig /flushdns. This clears the Windows DNS resolver cache; it does not repair a misspelled hosts entry or clear every application’s separate cache.

Close and reopen the application you are testing, or restart it if it maintains its own network cache. Browsers can have their own DNS or connection caches, and some browsers use secure DNS settings that change how DNS queries are handled. Applications may also use their own resolver or networking stack. Thus, a hosts-file change is not guaranteed to override every application or every network policy. If the result still seems wrong, test with another program and check the exact hostname and address in the file.

When testing a web address, remember that HTTPS adds another layer. If a hostname is redirected to a machine that does not present a certificate valid for that hostname, the browser can show a certificate warning. The hosts file changes name resolution; it does not alter a site’s certificate or make a different server impersonate the intended site safely.

Common Problems and Misconceptions

A frequent issue is editing the wrong file. The path must end at System32\drivers\etc\hosts, not a similarly named backup or a file saved in the user profile. Another common mistake is accidentally creating hosts.txt. Windows then continues using the extensionless original, so the new line appears to have no effect.

Check these points when a mapping fails:

  • Verify that the line is not commented out and that the hostname is spelled exactly as the application uses it.
  • Confirm that the address comes first and that the entry is saved in the system file.
  • Check for a conflicting entry elsewhere in the file and remove or comment out obsolete mappings.
  • Flush the Windows DNS cache, then restart the program being tested.
  • Consider whether a VPN, organizational policy, browser resolver, proxy, or application-specific lookup method affects the result.

Another misconception is that the hosts file is a DNS server or a complete firewall. It is a local mapping list, not a general-purpose traffic filter. Pointing a hostname to 127.0.0.1 or 0.0.0.0 may prevent some programs from reaching a particular host, but it is not a dependable way to block all related domains, apps, alternate hostnames, or network traffic. Security controls designed for filtering are more appropriate for that job.

Security and Maintenance

The hosts file is a legitimate Windows component, and its presence is normal. However, unwanted software can modify it to redirect commonly used names to another server, interfere with security or update services, or prevent access to particular sites. If you notice unexplained entries, do not assume automatically that they are malicious: check whether you or an administrator installed a development tool, VPN, filtering product, or other software that added them.

For a suspicious or unexpected change, save a copy for investigation, review the entries, and run a scan with a trusted security product. On a work-managed computer, ask the IT administrator before changing entries, since company policy or internal services may depend on them. Avoid replacing the entire file with a template from an unknown website. If you choose to restore a clean default, use guidance from Microsoft that matches your Windows version and preserve any legitimate custom mappings you need.

When you are finished with a temporary test, remove its mapping and flush the resolver cache if necessary. Keeping the file short and documenting the reason for nonstandard lines makes future troubleshooting easier. A comment can record the purpose and date of a test without changing how the entry works.

Related

Frequently Asked Questions

Where is the hosts file in Windows 11?
It is at %SystemRoot%\System32\drivers\etc\hosts, usually C:\Windows\System32\drivers\etc\hosts. The same standard path is used in Windows 10.

Does the Windows hosts file have a file extension?
No. The active file is named hosts with no extension. A file named hosts.txt is a different file and is not the standard hosts file Windows reads.

Why can’t I save changes to the hosts file?
The file is protected because it affects the whole computer. Open the text editor with Run as administrator, then open and save the file at its system location. A normal editor session may not have permission to write there.

Do I need to restart Windows after editing the hosts file?
Usually not. If a change is not visible, flush the DNS resolver cache with ipconfig /flushdns in an elevated Command Prompt and restart the relevant application. Some programs keep their own cache, so a full restart of that program may help.

Can the hosts file block a website?
It can redirect a specific hostname to another address, which may stop some connections to that name, but it is not a reliable website blocker. A site can use other hostnames, and applications may resolve names differently; use a suitable filtering or security tool for dependable blocking.

Windows Hosts File Location and How to Find and Edit It
Scroll to top