The host file is a plain text document on your computer that tells your system which websites go to which addresses

Your operating system uses the host file to look up website names before it ever contacts the internet. When you type a web address into your browser, your computer checks the host file first to see if it has instructions for that address. If it finds a match, it uses that instead of asking a DNS server online.

The host file is small, hidden, and rarely needs your attention — but knowing where it is matters if malware has modified it, if you want to block certain websites on your own computer, or if you're troubleshooting why a website won't load the way it should.

Key Takeaways

  • On Windows, the host file is at C:\Windows\System32\drivers\etc\hosts with no file extension.
  • On Mac, the host file is at /etc/hosts and you access it through Terminal or a text editor that can open hidden files.
  • On Linux, the host file is at /etc/hosts and you can edit it with a terminal text editor like nano or vi.
  • Malware sometimes modifies the host file to redirect you to fake websites, so checking it is a basic security step if your browser behaves strangely.
  • You need administrator or root access to edit the host file, and a single typo can break your internet connection to that website.

Finding the host file on Windows

On Windows, the host file lives in a system folder that is hidden by default. The full path is C:\Windows\System32\drivers\etc\hosts. The file has no extension — it is just called "hosts", not "hosts.txt".

The easiest way to find it is to open Notepad (search for "Notepad" in the Windows search box), then go to File > Open. In the file browser, paste this path into the location bar: C:\Windows\System32\drivers\etc. You should see the hosts file listed. If you do not see it, make sure "All Files" is selected in the file type dropdown at the bottom right, because Notepad defaults to showing only .txt files.

Alternatively, you can press Windows key + R, type notepad C:\Windows\System32\drivers\etc\hosts, and press Enter. Windows will ask for permission to run as administrator — click Yes. The file will open in Notepad.

Finding the host file on Mac

On Mac, the host file is at /etc/hosts. This is a hidden system folder, so you cannot find it by clicking through Finder the normal way.

The simplest method is to open Terminal (search for "Terminal" in Spotlight), then type sudo nano /etc/hosts and press Enter. You will be asked for your password. Type it (you will not see the characters appear) and press Enter. The file will open in the nano text editor. To exit without saving, press Control + X, then N. To save changes, press Control + X, then Y, then Enter.

If you prefer a graphical editor, you can open Finder, press Command + Shift + Period to show hidden files, then navigate to /etc/hosts. You can also drag the hosts file into a text editor like TextEdit, but make sure to save it as plain text (Format > Make Plain Text) and not as a .rtf file, or the system will not recognize it.

Finding the host file on Linux

On Linux, the host file is at /etc/hosts. You can view and edit it using a terminal text editor.

Open a terminal and type sudo nano /etc/hosts to edit it with nano, or sudo vi /etc/hosts to edit it with vi. You will be prompted for your password. In nano, save by pressing Control + O, then Enter, then Control + X to exit. In vi, press Escape, type :wq, and press Enter to save and exit.

You can also view the file without editing by typing cat /etc/hosts, which is useful if you just want to check whether it has been modified.

What a normal host file looks like

A default host file contains only a few lines. The most important ones are:

127.0.0.1 localhost — this tells your computer that "localhost" refers to itself.

::1 localhost — the same thing, but for IPv6 addresses.

Everything after a # symbol is a comment and is ignored by your system. A healthy host file has mostly comments and these two lines. If you see many other entries, especially ones pointing websites to 127.0.0.1 or to unfamiliar IP addresses, that is a sign the file has been modified.

Signs the host file has been compromised

Malware sometimes edits the host file to redirect you to fake websites. You might visit your bank's website but end up on a lookalike that steals your password. You might try to reach a security software site and be sent to a malicious one instead.

Red flags include: websites you visit regularly suddenly not loading, or loading a different page than usual; your browser showing a security warning for a site that normally works; or entries in the host file pointing major websites (Google, Facebook, your bank) to IP addresses like 127.0.0.1 or 192.168.x.x. If you find suspicious entries, delete them, save the file, and restart your browser. If the entries reappear, malware may have deeper access to your system and you should run a full scan with your antivirus software.

Editing the host file safely

You need administrator or root access to edit the host file. On Windows, right-click Notepad and choose "Run as administrator". On Mac and Linux, use sudo in the terminal.

The host file format is strict: each line contains an IP address, followed by one or more spaces or tabs, followed by the website name. For example: 127.0.0.1 example.com. A single typo — a missing space, a misspelled domain, an extra character — will break that entry and your computer will not be able to reach that website at all. If you make a mistake, your browser will show a "server not found" error even though the website is online.

Always back up the original file before editing. On Windows, right-click the hosts file, choose Copy, then paste it in the same folder and rename it to "hosts.backup". On Mac and Linux, type sudo cp /etc/hosts /etc/hosts.backup in Terminal. If something goes wrong, you can restore the original by copying the backup back.

When you might need to edit the host file yourself

Most people never need to edit the host file. But some situations call for it: testing a website before it goes live (you can point a domain name to your local computer), blocking a website on your own machine (point it to 127.0.0.1 so your browser cannot reach it), or working around a DNS issue where a website's address is not resolving correctly.

If you are doing any of these things, write down exactly what you are adding before you save, and test it when ready. Open your browser and try to visit the website. If it does not work as expected, undo the change right away. The host file is powerful but unforgiving — a small mistake can make a website unreachable until you fix it.

Frequently Asked Questions

Can I delete the host file?

No. Your operating system needs the host file to function. If you delete it, your computer will recreate a default version on restart. If you have made changes you want to undo, restore from your backup instead of deleting the file.

Why is the host file hidden?

It is hidden because it is a system file that most people should not modify. Accidental changes can break your internet connection to specific websites. Keeping it hidden reduces the chance of accidental edits.

Does the host file slow down my internet?

No. The host file is checked locally on your computer before any internet request is made, so it has no effect on your connection speed. A very large host file (thousands of entries) might add a tiny delay to name lookups, but this is not noticeable in normal use.

If I block a website in the host file, can I unblock it later?

Yes. straightforward delete or comment out the line you added (add a # at the beginning). Save the file and restart your browser. The website will be reachable again.

What is the difference between the host file and DNS?

The host file is checked first, on your own computer. DNS is a service on the internet that translates website names to addresses. If the host file has no entry for a website, your computer asks a DNS server. The host file is faster but only works for entries you add yourself. DNS works for all websites.