How to Edit the Hosts File on Windows and macOS
The hosts file is a crucial system file that maps domain names to IP addresses. Editing this file allows you to control the mapping of hostnames, making it a useful tool for various purposes. In this guide, we'll walk you through the process of editing the hosts file on both Windows and macOS.
Editing the Hosts File on Windows:
The hosts file on Windows is located at C:\Windows\System32\drivers\etc\hosts
.
Follow these steps to edit the file:
- Open Notepad or any text editor with administrator privileges.
- Go to File > Open, and navigate to the hosts file location.
- Add or modify entries in the following format:
IP_address domain_name
. - Save the file and close the text editor.
Editing the Hosts File on macOS:
The hosts file on macOS is located at /private/etc/hosts
.
Follow these steps to edit the file:
- Open Terminal.
- Type
sudo nano /private/etc/hosts
and press Enter. - Enter your administrator password when prompted.
- Add or modify entries in the following format:
IP_address domain_name
. - Press
Ctrl + X
to exit, pressY
to confirm changes, and press Enter.
After editing the hosts file, changes take effect immediately. This allows you to locally override DNS settings and control access to specific websites. Remember to save a backup of the original hosts file before making changes for safety.
If your changes aren’t reflecting in your browser after editing the hosts file, flushing your DNS cache can resolve the issue. This process removes saved IP records and allows your browser to reflect the updated IP address from the edited hosts file.
To update your browser's DNS records, enter the following command into the Terminal application:
sudo killall -HUP mDNSResponder
This step ensures that your changes go live within your browser. You have now successfully edited your Mac hosts file!
Whether you're configuring a local development environment or blocking access to certain sites, understanding how to edit the hosts file empowers you with more control over network resolutions.