The hosts file is stored in the operating system’s system directory, not in your user profile. On Windows it lives at C:\Windows\System32\drivers\etc\hosts; on macOS and Linux it resides at /etc/hosts. You must use administrator or root privileges to edit this file because standard user accounts do not have write access to system folders.
Exact File Paths by OS
Locating the file requires knowing which version of your operating system you are running. The path differs slightly between major platforms, but the structure remains consistent within each family. If you navigate to these locations using a standard file explorer, you will see the file named simply “hosts” without an extension. This lack of extension is intentional; the operating system treats it as a plain text configuration file rather than a document.
Windows Locations
On all modern versions of Windows, including Windows 10 and Windows 11, the file is located deep within the system tree. You can type the full path into the address bar of any folder window to jump directly to it:
- C:\Windows\System32\drivers\etc\hosts
Do not look for a folder named “Hosts”. The file exists inside the “etc” folder, which stands for “etcetera” and is a legacy naming convention from Unix systems that Windows adopted for compatibility. The “drivers” subfolder contains low-level network drivers, and the hosts file acts as a local override for DNS resolution before the computer contacts an external server.
macOS and Linux Locations
For macOS users, the path is straightforward and mirrors the Linux standard:
- /etc/hosts
Linux distributions follow the same pattern. Whether you are using Ubuntu, Fedora, Debian, or Arch, the file is always at /etc/hosts. The leading slash indicates the root directory of the file system. Because this is a core system file, you cannot modify it by simply double-clicking it in Finder or your file manager. You must open a terminal window and use a command-line text editor with elevated permissions.
Editing Permissions and Safety
The most common reason people search for this file is to block websites or redirect traffic. However, attempting to save changes directly often fails because of strict permission settings. Operating systems protect this file to prevent malware from silently redirecting banking sites or stealing credentials. If you try to edit it without proper rights, the system will reject the save operation or create a temporary copy that gets deleted upon reboot.
How to Edit on Windows
You need to launch your text editor with administrative privileges. The simplest method involves the Start menu. Search for Notepad, right-click the result, and select “Run as administrator.” Once the editor is open with elevated rights, go to File > Open. Navigate to C:\Windows\System32\drivers\etc\. You may need to change the file type dropdown from “Text Documents (*.txt)” to “All Files” to see the hosts file. After making your changes, save the file. The changes take effect immediately for new connections.
How to Edit on macOS and Linux
On Unix-based systems, you must use the terminal. Open Terminal and type a command that invokes a text editor with sudo (superuser do) privileges. For example, typing sudo nano /etc/hosts will open the file in the Nano editor. You will be prompted for your password. Type it carefully (characters will not appear on screen) and press Enter. Make your edits, then save using the control sequence for your specific editor. In Nano, this is Control+O followed by Enter. Exit with Control+X. On macOS, you may also need to flush the DNS cache for changes to apply immediately, though most systems update automatically.
Common Misconceptions About Location
A frequent error is assuming the hosts file is stored in the user’s home directory. Users often look in Documents, Desktop, or AppData, expecting to find a personal configuration folder. It does not exist there. The file is global to the machine. Any modification affects all user accounts on that computer, not just the one currently logged in. This global nature is why the security restrictions are so tight.
Another misconception is that the file must have a .txt extension. Some users rename it to hosts.txt to make it easier to open in basic editors. While this works for viewing, the operating system only recognizes the file as a valid hosts configuration when it has no extension. Renaming it back is required for the changes to be processed by the TCP/IP stack. Always ensure the file name ends strictly with “hosts”.
Practical Rules for Modification
When editing the file, you should follow a specific format to avoid syntax errors. Each line represents a single mapping. The format is the IP address, followed by one or more spaces or tabs, followed by the domain name. Do not use commas or other delimiters. Comments are allowed if you start the line with a hash symbol (#). This allows you to disable lines without deleting them, which is useful for troubleshooting.
Always backup the original file before making changes. Create a copy named hosts.bak in the same directory. If your edits cause network connectivity issues, such as being unable to load any web pages, you can restore the backup. The default hosts file usually contains only a few lines mapping localhost to 127.0.0.1. Restoring this default state will return your network to normal operation. Never delete the localhost entry, as many applications rely on it for internal communication.
Verifying Your Changes
After saving the file, you may wonder if the changes worked. The most direct way to verify is using the command prompt or terminal. Type ping followed by the domain name you edited. For example, ping example.com. The response will show the IP address the system resolved. If it matches the IP you entered in the hosts file, the override is active. If it shows a different IP, either the file was not saved correctly, you lack permissions, or another application is interfering with DNS resolution.
Some browsers cache DNS information aggressively. If the ping command shows the correct IP but the browser still loads the old page, clear the browser cache or restart the browser entirely. This ensures the application picks up the new system-level configuration. Understanding where the file lives and how permissions work empowers you to manage your network environment securely and effectively.