The hosts file is a text file on your computer that tells it which web address goes to which internet location

Your computer has a file called the hosts file that works like a personal phonebook for websites. When you type a web address into your browser, your computer checks this file first to see if it already knows where that address lives on the internet. If the address is in the hosts file, your computer uses that location instead of asking the internet.

Most of the time, the hosts file is empty or nearly empty. But malware, viruses, and unwanted programs sometimes add entries to it without your permission. When that happens, typing a website address might take you somewhere you did not intend to go. Finding and cleaning your hosts file is one way to fix a computer that is redirecting you to the wrong sites or running slowly because of background traffic.

Key Takeaways

  • The hosts file sits in a different location depending on whether you use Windows, Mac, or Linux, but it is always a plain text file with no file extension.
  • Malware and unwanted programs often modify the hosts file to redirect your web traffic or block certain sites, which can slow your computer or change where websites take you.
  • You can open and read the hosts file with Notepad (Windows) or TextEdit (Mac), but you need administrator permission to save changes.
  • Cleaning the hosts file means removing lines that do not belong there, but you should back it up first in case you need to restore it.
  • If your hosts file keeps getting modified after you clean it, malware is still present and you should run a full antivirus scan.

Where the hosts file lives on Windows

On Windows, the hosts file is located at C:\Windows\System32\drivers\etc\hosts. It has no file extension — the name is just "hosts", not "hosts.txt" or anything else. The file is hidden by default, so you may not see it when you browse your folders normally.

To find it, open File Explorer and navigate to the address bar at the top. Type or paste the full path C:\Windows\System32\drivers\etc and press Enter. You should see the hosts file listed there. If you do not see it, go to the View menu and turn on "Show hidden files" or "Hidden items".

Where the hosts file lives on Mac

On Mac, the hosts file is at /private/etc/hosts. Like the Windows version, it has no file extension and is hidden from normal view.

The easiest way to open it is to use the Terminal process. Open Terminal (you can find it in Applications > Utilities), then type sudo nano /private/etc/hosts and press Enter. You will be asked for your password. Type it in (you will not see the characters as you type) and press Enter again. The hosts file will open in the nano text editor, and you can read and edit it there.

How to open and read the hosts file

On Windows, right-click the hosts file and choose "Open with" and then "Notepad". This opens the file in plain text so you can see what is inside. Do not use Word or another word processor — those add formatting that will break the file.

The hosts file contains lines that map web addresses to internet addresses (called IP addresses). A normal entry looks like this: 127.0.0.1 localhost. Lines that start with a # symbol are comments and do not do anything. If you see lines that map real websites (like google.com or facebook.com) to strange IP addresses, those are usually added by malware and should be removed.

What to look for when cleaning the hosts file

A clean hosts file typically has only a few lines, mostly comments and the localhost entry. Anything else is suspicious. Common signs of malware in the hosts file include entries that redirect popular websites to IP addresses you do not recognize, or entries that block websites by pointing them to 127.0.0.1 or 0.0.0.0.

Before you delete anything, back up the file by making a copy and saving it to your Desktop with a different name, like "hosts_backup". That way, if you accidentally delete something important, you can restore it. Then open the original hosts file again and delete the lines that do not belong. Save the file when you are done.

On Windows, you will need to run Notepad as administrator to save changes. Right-click Notepad in your Start menu and choose "Run as administrator", then open the hosts file from inside Notepad using File > Open.

What to do if malware keeps modifying the hosts file

If you clean the hosts file and the unwanted entries come back after a restart, malware is still running on your computer. Cleaning the hosts file alone will not fix the problem — you need to remove the malware itself.

Run a full antivirus scan using Windows Defender (built into Windows) or a third-party antivirus program. Set it to scan your entire computer, not just quick scan. This can take an hour or more, but it will find and remove the programs that are modifying your hosts file. After the scan completes and any threats are removed, clean the hosts file again.

How the hosts file affects your computer's speed

A modified hosts file can slow your computer down in two ways. First, if malware is constantly rewriting the file, that uses processing power and disk activity. Second, if the hosts file redirects your web traffic to malicious servers, your browser has to connect to those servers before it realizes the address is wrong, which adds delay to every page load.

Cleaning the hosts file is a quick fix that can help, but it is not a complete solution if malware is the cause. A full antivirus scan and removal of the underlying malware will have a bigger impact on your speed.

Frequently Asked Questions

Can I delete the entire hosts file?

No. The hosts file serves a real purpose, and your computer needs at least the basic entries to work correctly. Back it up first, then remove only the lines that look suspicious. If you accidentally delete everything, restore from your backup.

What does 127.0.0.1 mean in the hosts file?

127.0.0.1 is your computer's own address, called localhost. The entry "127.0.0.1 localhost" is normal and should stay. But if you see other website names pointed to 127.0.0.1, that is malware blocking those sites.

Do I need to restart my computer after cleaning the hosts file?

Not always, but it is a good idea. Some programs cache the hosts file in memory, so restarting ensures your computer reads the cleaned version. If you are still seeing redirects after cleaning, restart and run an antivirus scan.

Is it safe to edit the hosts file myself?

Yes, as long as you only delete lines that look wrong and keep a backup. The hosts file is just text, so you cannot break anything permanently. If something goes wrong, restore your backup and try again.