The host file is a plain text file on your computer that maps domain names to IP addresses, and its location depends on your operating system.
On Windows, the host file lives at C:\Windows\System32\drivers\etc\hosts. On Mac and Linux, it's at /etc/hosts. This file has no file extension — it's just called "hosts" — and your operating system checks it before asking the internet for a website's address. Most people never need to touch it, but system administrators, developers, and people troubleshooting network problems sometimes edit it to redirect websites or test local servers.
The host file is one of the oldest parts of how computers talk to each other on networks. Before the internet had a central directory of domain names, computers used local host files to know where to find each other. Today it still works the same way: your computer reads this file first, and only if it doesn't find an answer there does it ask a DNS server on the internet.
Key Takeaways
- Windows stores the host file at C:\Windows\System32\drivers\etc\hosts with no file extension.
- Mac and Linux store it at /etc/hosts in the root directory.
- You need administrator or root permissions to edit the host file on any operating system.
- The host file is a plain text file that your computer checks before asking the internet for a website's address.
- Malware sometimes modifies the host file to redirect you to fake websites, so checking it is part of malware removal.
Finding the host file on Windows
Open File Explorer and navigate to C:\Windows\System32\drivers\etc. You will see a file called "hosts" with no extension. If you don't see it, make sure you have "Show hidden files" turned on — go to View in the File Explorer menu, click Options, then the View tab, and check "Show hidden files, folders, and drives."
Do not try to open the hosts file by double-clicking it. Windows will ask you which program to use, and the wrong choice can corrupt it. Instead, right-click the file, select "Open with," and choose Notepad. If Notepad is not in the list, click "Choose another app" and find it in the full list. Once it opens, you will see lines that look like this:
127.0.0.1 localhost ::1 localhost
These two lines are normal and should stay. Anything else in the file was added by you, a system administrator, or malware. If you see entries you don't recognize — especially ones that redirect common websites to different IP addresses — that is a sign of infection.
Finding the host file on Mac and Linux
Open Terminal (on Mac, search for it in Spotlight; on Linux, open your terminal application). Type sudo nano /etc/hosts and press Enter. You will be asked for your password because editing the host file requires administrator permissions. Type your password and press Enter again.
The file will open in the nano text editor. You will see lines starting with 127.0.0.1 and ::1, which are normal. Any other entries were added intentionally or by malware. To exit without making changes, press Ctrl+X, then N, then Enter. To save changes, press Ctrl+X, then Y, then Enter.
If you prefer a graphical editor, you can also open the file with your system's text editor by using sudo open -a TextEdit /etc/hosts on Mac. On Linux, use sudo gedit /etc/hosts or sudo kate /etc/hosts depending on your desktop environment.
Why the host file matters for security
Malware sometimes modifies the host file to redirect you to fake websites. For example, it might add a line that sends you to a fake bank login page when you type your bank's real web address. You would see the fake site in your browser and think it was real. This is one reason security software checks the host file during scans — if it finds unexpected entries, that is a sign of infection.
The host file is also used legitimately by developers and system administrators to test websites on their own computers before they go live on the internet, or to block ads and tracking by redirecting ad servers to a dead address. If you see entries in your host file that you did not add, and you are not a developer or administrator, that is worth investigating.
What to do if you find suspicious entries
If you see entries in the host file that you don't recognize, do not delete them immediately without understanding what they do. First, take a screenshot or write down the entries. Then search the internet for the domain name or IP address to see if it is legitimate. Many developers and administrators add entries to the host file intentionally, and deleting them could break something.
If you are certain an entry is malicious, you can delete the entire line. Open the file with administrator or root permissions, select the line, delete it, and save the file. You will need to restart your browser or computer for the change to take effect. If you are not sure, run a full malware scan with your security software first — it can tell you whether an entry is known malware.
Restoring the host file to default
If the host file becomes corrupted or you accidentally delete important lines, you can restore it to its default state. On Windows, the default host file contains only the two localhost lines shown earlier. On Mac and Linux, it is the same.
To restore it on Windows, open Notepad as administrator, create a new file, and type these two lines exactly:
127.0.0.1 localhost ::1 localhost
Then save the file as "hosts" (with no extension) in C:\Windows\System32\drivers\etc, replacing the old one. On Mac and Linux, open Terminal and type sudo nano /etc/hosts, delete everything, type the same two lines, and save.
Frequently Asked Questions
Can I edit the host file without administrator permissions?
No. On Windows, you need administrator rights. On Mac and Linux, you need root permissions, which you get by using the sudo command. If you try to edit it without these permissions, the file will not save your changes.
What does the IP address 127.0.0.1 mean?
127.0.0.1 is the loopback address — it points back to your own computer. When you type localhost in a web browser, your computer looks it up in the host file, finds 127.0.0.1, and connects to a web server running on your own machine. Developers use this to test websites locally.
Will editing the host file slow down my internet?
No. Your computer checks the host file instantly before asking the internet. If anything, it is slightly faster because it does not have to wait for a response from a DNS server on the internet. However, if you add many entries, the file will still load in milliseconds.
Is it safe to delete the host file entirely?
No. Your operating system expects the host file to exist. If you delete it, restore it to its default state with the two localhost lines. If you accidentally delete it, recreate it with those two lines and save it in the correct location.
Why does my antivirus software keep warning me about the host file?
Some security software flags any changes to the host file because malware modifies it. If you made the changes intentionally, you can tell your security software to ignore that file. If you did not make the changes, run a full scan to check for malware.