Modifying the hosts file on macOS might seem challenging for users who’ve done it on Windows, but it’s straightforward with the right steps. This guide will teach you how to both add and remove hosts on macOS, making it accessible even for beginners.
Table of Contents
How to Add Hosts on macOS
Adding hosts on macOS can be useful for blocking websites or servers for productivity or parental control reasons. Follow these steps to add hosts:
- Open the Terminal application, which can be found under Go > Utilities, or by searching for “Terminal” in Spotlight (magnifying glass icon).
- Double-click to start the Terminal application. A command window will open.
- In the terminal, input
sudo nano /private/etc/hosts
and press Enter. - You’ll be prompted to enter your administrator password. Type it (note that characters will not be displayed) and press Enter.
- In the editing window, add the host entries you wish to block. You can use either of the following formats:
127.0.0.1 [AddressYouWantToBlock]
0.0.0.0 [AddressYouWantToBlock]
For example:
127.0.0.1 www.youtube.com
- Once all desired hosts are added, save and close the file with the following keystrokes: CTRL + O, press Enter, then CTRL + X.
Now, the specified hosts will be blocked on your Mac, restricting access to those websites.
How to Remove Hosts on macOS
If you previously restricted certain sites for parental control or other reasons and now want to allow access, follow these steps to remove hosts:
- Open the Terminal application, which can be found under Go > Utilities, or by searching for “Terminal” in Spotlight (magnifying glass icon).
- Double-click to start the Terminal application. A command window will open.
- In the terminal, input
sudo nano /private/etc/hosts
and press Enter. - You’ll be prompted to enter your administrator password. Type it (note that characters will not be displayed) and press Enter.
- The hosts file that contains all the blocked addresses will open. To remove a specific host, navigate to it using the arrow keys and delete it character by character.
- Once all unwanted hosts are removed, save and close the file with the following keystrokes: CTRL + O, press Enter, then CTRL + X.
This will unblock the specified hosts, allowing access to those websites again.
Did you find this article helpful? You might also be interested in our guide for adding or removing hosts on Windows. Check out: How to Manage Hosts File on Windows.