Your host file is a plain text document on your computer that tells your system which websites go to which internet addresses
The host file sits in a specific folder on your computer and contains a simple list: domain names matched to IP addresses. When you type a website address into your browser, your computer checks this file first before asking the internet. Most people never need to touch it, but knowing where it is helps if you're troubleshooting network problems, testing websites before they go live, or blocking access to certain sites on your own machine.
The location depends on which operating system you use. Windows, Mac, and Linux each store it in a different place, and you'll need administrator access to edit it. This guide shows you exactly where to find it on your system and what you're looking at when you open it.
Key Takeaways
- On Windows, the host file is at C:\Windows\System32\drivers\etc\hosts with no file extension.
- On Mac and Linux, it's at /etc/hosts and you access it through the Terminal application.
- You need administrator or root permissions to edit the file, and most text editors will refuse to save changes without them.
- The file contains two columns: an IP address on the left and a domain name on the right, separated by whitespace.
- Mistakes in this file can break your internet connection to specific sites, so back it up before making changes.
Finding the host file on Windows
On Windows, open File Explorer and navigate to C:\Windows\System32\drivers\etc. The host file has no extension — it's just called "hosts", not "hosts.txt". If you don't see it, make sure you're showing hidden files: click the View tab at the top, then check the box next to "Hidden items".
Once you find it, right-click and choose "Open with" and select Notepad. Do not double-click it, because Windows may try to open it with the wrong program. If you want to edit the file, you must run Notepad as administrator first, then open the file from inside Notepad. Right-click Notepad in your Start menu and choose "Run as administrator", then use File > Open to navigate to the hosts file.
Finding the host file on Mac
On Mac, you'll use the Terminal application to view and edit the host file. Open Terminal (find it in Applications > Utilities or search for it with Spotlight). Type this command and press Enter:
sudo nano /etc/hosts
The system will ask for your password — type it in (you won't see the characters appear). This opens the file in a text editor called nano. To edit, use the arrow keys to move around, type your changes, then press Control + X to exit. It will ask if you want to save; type Y for yes and press Enter.
If you prefer a graphical editor instead of Terminal, you can also open the file with a text editor like TextEdit, but you must open the editor as administrator first and then navigate to /etc/hosts from the File menu.
Finding the host file on Linux
On Linux, the host file is at /etc/hosts. Open a Terminal window and use the same command as Mac:
sudo nano /etc/hosts
You'll need to enter your password. Make your changes in the nano editor, then press Control + X, type Y, and press Enter to save. Alternatively, you can view the file without editing by typing cat /etc/hosts — this just displays the contents without opening an editor.
What you'll see inside the host file
The host file contains lines with two main parts: an IP address on the left and a domain name on the right. For example:
127.0.0.1 localhost ::1 localhost
These two lines are standard on every system. The address 127.0.0.1 is your computer talking to itself (called "localhost"). The :: 1 is the same thing in IPv6 format. Lines starting with a # symbol are comments and don't do anything — the system ignores them.
If someone has added other lines, each one tells your computer to send traffic for that domain to a specific IP address instead of looking it up on the internet. For example, if a line says 192.168.1.100 example.com, your computer will try to reach example.com at address 192.168.1.100 instead of the real one.
Why the host file matters for your security
Malware sometimes modifies your host file to redirect you to fake websites. If you suddenly can't reach a legitimate site but others can, or if you're being sent to a different page than usual, check your host file for unexpected entries. Look for domain names you don't recognize or IP addresses that don't match what you intended.
Some people intentionally add entries to block access to websites on their own computer — for example, blocking social media sites during work hours or preventing children from reaching certain domains. This works only on that specific computer; it doesn't affect other devices on your network.
Before you edit the file, save a backup copy. On Windows, right-click the hosts file and choose "Copy", then paste it in the same folder and rename it to "hosts.backup". On Mac or Linux, type sudo cp /etc/hosts /etc/hosts.backup in Terminal. If something breaks after your changes, you can restore the original.
Common reasons to check your host file
You might look at your host file if a website won't load but your internet connection works fine. If the site works on someone else's computer or phone but not yours, the host file could be redirecting you somewhere else. You can also check it if you're testing a website on your own computer before it goes live on the internet — developers often add a temporary entry to test locally.
If you find unexpected entries and didn't put them there, it's worth running a malware scan. Entries that point to 127.0.0.1 or 0.0.0.0 are usually harmless (they block the site), but entries pointing to random IP addresses on the internet could be redirecting you to malicious copies of legitimate sites.
Frequently Asked Questions
Can I edit the host file with any text editor?
Yes, but you must open the editor with administrator (Windows) or root (Mac/Linux) permissions first, then open the file from inside the editor. If you open the file directly and try to edit it without the right permissions, the editor will let you make changes but refuse to save them.
What happens if I delete the host file?
Your system will recreate a basic version with just the localhost entries the next time it starts up. You won't break anything permanently, but it's better to back it up first and restore it if needed rather than deleting it outright.
Does editing the host file affect other people on my network?
No. The host file only controls what happens on that one computer. Other devices on your Wi-Fi or network won't see your changes. If you want to block a site for everyone on your network, you'd need to change settings on your router instead.
How do I know if malware changed my host file?
Look for domain names you don't recognize or entries you didn't add yourself. Legitimate entries are usually just localhost and maybe a few entries you added on purpose. If you see dozens of unfamiliar domains or entries pointing to random IP addresses, run a malware scan with a tool like Malwarebytes or Windows Defender.
Can I use the host file to speed up my internet?
No. The host file only redirects specific domain names to IP addresses you choose. It doesn't affect your connection speed or how fast websites load. Any tool claiming to speed up the internet by modifying your host file is misleading.