The host file location depends on your Windows version

The host file is a text file that tells your computer how to translate website addresses into the numbers it actually uses to connect. On Windows 10 and Windows 11, it lives in C:\Windows\System32\drivers\etc\hosts — no file extension, just "hosts". On older versions like Windows 7, the path is identical.

You cannot see this file by opening File Explorer and navigating there the normal way, because Windows hides system files by default. You need either to show hidden files first, or open it directly through a text editor. Both methods take less than a minute once you know the steps.

The host file is small — usually just a few kilobytes — and mostly empty on a fresh Windows installation. It contains only comments (lines starting with #) and a single active line that points "localhost" to your own computer. You edit it when you want to block websites, test a website before it goes live, or redirect a domain to a different address on your network.

Key Takeaways

  • The host file is located at C:\Windows\System32\drivers\etc\hosts on all modern Windows versions, with no file extension.
  • Windows hides this file by default, so you must either enable viewing hidden files or open it directly through Notepad or another text editor.
  • You need administrator permission to save changes to the host file, so right-click your text editor and choose "Run as administrator" before opening it.
  • The host file works on your computer only — changes do not affect other devices on your network or the internet at large.

Opening the host file through Notepad

The fastest way to find and open the host file is to use Notepad directly. Press Windows key + R to open the Run dialog, type notepad C:\Windows\System32\drivers\etc\hosts, and press Enter. Notepad will open the file when ready.

If you see a message saying the file does not exist, your Windows installation is damaged or the path has changed — this is rare. If you see a blank window or only comments, the file is open correctly and you are seeing its normal state.

Before you make any changes, close Notepad without saving. Then right-click Notepad in your Start menu, select "Run as administrator", and repeat the steps above. Windows will ask for permission, and you must click "Yes". Without administrator permission, you can read the file but cannot save edits.

Finding the host file through File Explorer

If you prefer to navigate visually, open File Explorer and go to C:\Windows\System32\drivers\etc. The folder exists, but you will not see the hosts file because Windows hides it. Click the View tab at the top, then check the box labeled Hidden items. The hosts file will now appear in the folder.

Once you see it, right-click the hosts file and select Open with, then choose Notepad. If Notepad is not in the list, click Choose another app and scroll down to find it. Again, if you want to save changes, you must close the file, right-click Notepad itself, choose "Run as administrator", and open the file again from there.

Some people prefer to copy the hosts file to their Desktop, edit it there, and then copy it back to the original location. This avoids the administrator permission step, but it is slower and creates a second copy you must remember to delete.

What you will see inside the host file

When you open the hosts file, you will see lines that start with # — these are comments and do nothing. Below them is usually a single active line that reads 127.0.0.1 localhost. This tells your computer that the name "localhost" points to 127.0.0.1, which is your own machine. You will also see a similar line for IPv6: ::1 localhost.

If the file is completely empty except for comments, this is normal. If you see many entries with IP addresses and domain names, someone has edited the file — either to block websites, test a local server, or (rarely) because malware added entries. Malware-added entries usually point to unfamiliar IP addresses or domains you do not recognize.

Each line follows the same pattern: an IP address, then one or more spaces or tabs, then a domain name. For example, 192.168.1.100 mywebsite.local would tell your computer that "mywebsite.local" lives at 192.168.1.100 on your network. The host file checks these entries before asking the internet, so it overrides normal DNS lookups.

Editing the host file safely

If you need to add an entry, place your cursor at the end of the file, press Enter to create a new line, and type the IP address, a tab or space, and the domain name. For example: 127.0.0.1 testsite.local. Save the file (Ctrl+S) and close Notepad.

Changes take effect when ready on most programs, but some browsers cache DNS results. If a change does not work right away, close and reopen your browser. If you are testing a website on your own computer, use 127.0.0.1 as the IP address. If you are redirecting to another computer on your network, use that computer's IP address instead.

To remove an entry, select the entire line and delete it, or add a # at the beginning to comment it out. Commenting is safer because you can undo it easily if something breaks. Save the file and close Notepad. If something goes wrong, you can always delete the line you added or restore the file from a backup.

When the host file will not save

If you edit the file and Notepad will not save your changes, you did not open it as administrator. Close Notepad without saving, right-click Notepad in the Start menu, select "Run as administrator", and open the file again. This time the save should work.

If you still cannot save, your antivirus software may be blocking changes to system files. Check your antivirus settings and look for an option to allow changes to protected files, or temporarily disable the antivirus while you edit. Some antivirus programs treat the hosts file as a security risk because malware sometimes modifies it.

Another cause is file permissions. If you inherited the computer from someone else or upgraded Windows, your user account may not have permission to edit system files. Right-click the hosts file itself, select Properties, click the Security tab, and check whether your username appears in the list with "Full Control" permission. If not, click Edit, select your username, and check the "Full Control" box.

Restoring the host file to its default state

If you added entries and want to remove them all, you can delete everything except the comments and the localhost lines. Open the file as administrator, select all lines that contain IP addresses and domain names (but not lines starting with #), and delete them. Save the file.

If you accidentally deleted the localhost lines or corrupted the file, you can restore it from a Windows backup if you have one, or you can manually recreate the default entries. The default host file contains only comments and these two lines: 127.0.0.1 localhost and ::1 localhost. Copy these into a blank Notepad window, save it as hosts (with no extension) to your Desktop, then copy it back to C:\Windows\System32\drivers\etc and replace the original.

Frequently Asked Questions

Can I edit the host file on a Mac or Linux computer?

Yes, but the location is different. On Mac, it is /etc/hosts. On Linux, it is also /etc/hosts. The file format and how it works are identical to Windows. You open it with a text editor and need administrator or root permission to save changes.

Will changes to my host file affect other people on my WiFi?

No. The host file only works on your own computer. Other devices on your network have their own host files and will not see your changes. If you want to redirect a domain for everyone on your network, you would need to change the settings on your router or DNS server instead.

What happens if I delete the entire host file?

Windows will still work, but you may see error messages about localhost. You can recreate the default file by opening Notepad as administrator, typing the two default lines (127.0.0.1 localhost and ::1 localhost), and saving it as hosts to C:\Windows\System32\drivers\etc. Windows will ask for permission to replace the file.

Can malware hide itself in the host file?

Malware can add entries to redirect websites to fake versions, but it cannot hide there — the file is plain text and you can see every entry. If you see unfamiliar domain names or IP addresses in your host file, you can delete those lines. Run a full antivirus scan afterward to check for other infections.

Do I need to restart Windows after editing the host file?

No. Changes take effect when ready for most programs. Some browsers cache DNS results, so close and reopen your browser if a change does not work right away. You do not need to restart your computer.