The Windows host file is a plain text file that maps domain names to IP addresses on your computer

The host file is a simple text document that your computer checks before it looks up a website's address on the internet. When you type a web address into your browser, Windows consults this file first. If the address is listed there, your computer goes directly to the IP address you've specified instead of asking a DNS server. This is useful for testing websites before they go live, blocking certain domains, or redirecting traffic locally.

The file itself contains no graphics or special formatting — just plain text with domain names and IP addresses paired together. On Windows, it has no file extension, which confuses many people looking for it. The location varies slightly depending on your Windows version, but the path is always the same structure.

Key Takeaways

  • The Windows host file is located at C:\Windows\System32\drivers\etc\hosts on all modern Windows versions.
  • The file has no file extension and opens in Notepad or any plain text editor, not Word or other formatted programs.
  • You must run your text editor as administrator to save changes to the host file, or Windows will block the edit.
  • Changes take effect immediately on most browsers, though you may need to clear your browser cache or restart your browser to see them.
  • A single mistake in the host file syntax can break your internet connection to that domain, so back up the original before editing.

How to locate the host file using File Explorer

Open File Explorer and navigate to the address bar at the top. Type or paste C:\Windows\System32\drivers\etc and press Enter. You will see a folder containing several files with no extensions. The file named hosts (with no dot or extension) is the one you need. It will not have a recognizable icon — it may appear as a blank document or a text file icon depending on your Windows settings.

If you do not see the file, your view settings may be hiding it. Click the View tab in File Explorer, then check the box for "Hidden items" if it is unchecked. The hosts file is not actually hidden by default on most systems, but this setting helps if it does not appear. Once you locate it, right-click the file and select "Open with" to choose your text editor.

Opening the host file with the right permissions

The host file requires administrator privileges to edit. If you try to open it with a regular text editor and make changes, Windows will refuse to save your edits. Right-click Notepad (or your preferred text editor) in the Start menu and select "Run as administrator." Once the program opens with the admin badge visible in the title bar, use File > Open and navigate to C:\Windows\System32\drivers\etc\hosts.

Alternatively, you can right-click the hosts file itself and select "Open with," then choose your text editor. If you see a prompt asking for administrator permission, click "Yes" to proceed. Some text editors like Visual Studio Code will prompt you to elevate permissions when you try to save changes to a protected file — accept that prompt to complete the save.

Understanding the host file format and syntax

Each line in the host file contains an IP address, followed by whitespace (a tab or spaces), followed by a domain name. For example, 127.0.0.1 localhost is the standard first line, which points your computer to itself. Lines beginning with a hash symbol # are comments and are ignored by Windows. You can add comments to explain what each entry does.

A typical entry looks like this: 192.168.1.100 mywebsite.local. This tells your computer that when you type mywebsite.local into your browser, it should go to the IP address 192.168.1.100 instead of looking it up on the internet. Each entry must be on its own line. If you add extra spaces, use the wrong IP format, or misspell a domain name, that entry will not work and may cause connection problems for that domain.

Common reasons to edit the host file

Developers often add entries to test websites on a local server before the domain goes live on the internet. For example, you might add 127.0.0.1 newsite.com to view your development version of newsite.com on your own machine. This lets you test the site without publishing it publicly or waiting for DNS changes to propagate.

Some people also use the host file to block websites by pointing them to 127.0.0.1 (your local machine) or 0.0.0.0 (nowhere). This prevents your browser from reaching those addresses. Network administrators sometimes use host files to redirect traffic on a local network or to override DNS for testing purposes. Malware can also modify the host file without your knowledge, so if you notice unexpected redirects, checking this file is a good troubleshooting step.

Backing up and restoring the original host file

Before you make any changes, copy the original hosts file to a safe location. Right-click the file in File Explorer, select "Copy," then paste it in a folder like Documents or Desktop with a new name like hosts.backup. This way, if something goes wrong, you can restore the original by copying the backup back to C:\Windows\System32\drivers\etc.

If you make changes that break your internet connection to a domain, you can undo them by deleting the problematic line or restoring from your backup. If you have made many changes and cannot remember what was original, Windows includes a clean copy of the host file on installation media, but restoring from your own backup is faster. Keep your backup for as long as you plan to edit the host file.

Troubleshooting when changes do not take effect

After editing the host file, your browser may still show the old result because it has cached the DNS lookup. Clear your browser cache or restart the browser entirely. In Chrome, press Ctrl+Shift+Delete to open the cache-clearing menu. In Edge, use the same shortcut. In Firefox, press Ctrl+Shift+Delete as well. Select "All time" and check "Cookies and cached images and files," then clear.

If clearing the cache does not work, restart your computer. Windows caches DNS lookups in the system resolver as well, and a restart clears that cache. You can also flush the DNS cache manually by opening Command Prompt as administrator and typing ipconfig /flushdns, then pressing Enter. After any of these steps, try accessing the domain again in your browser.

Frequently Asked Questions

What is the difference between the host file and DNS?

The host file is checked first, on your local computer. DNS is a network service that looks up addresses on the internet. If an entry exists in your host file, your computer never contacts a DNS server for that domain. This is why the host file is useful for testing — it overrides the internet's DNS system.

Can I edit the host file on Windows 11 the same way as Windows 10?

Yes. The location C:\Windows\System32\drivers\etc\hosts and the editing process are identical on Windows 10, Windows 11, and Windows Server versions. The file format and permissions requirements have not changed across these versions.

What happens if I delete a line from the host file by mistake?

If you delete a line that was not part of your changes, your computer will no longer use that mapping. For most users, the only original line is 127.0.0.1 localhost, and deleting it can cause some local services to fail. Restore it from your backup or type it back in manually. If you deleted a line you added yourself, simply re-add it with the correct IP and domain.

Why does Windows not let me save changes to the host file?

You are not running your text editor as administrator. Close the file without saving, right-click your text editor in the Start menu, select "Run as administrator," and open the host file again. The title bar should show "Administrator" when you have the right permissions.

Can malware modify my host file?

Yes. Some malware redirects websites by adding entries to the host file. If you notice that websites are redirecting to unexpected pages, check your host file for unfamiliar entries. Compare it to a clean backup or to the original file from a fresh Windows installation. Remove any lines you did not add yourself, then run a full antivirus scan.