The best way to work with the Hosts file is using the Terminal application found in your Mac’s Utilities folder. You’ll need to know the IP address of the device you’d like to send your Mac to, or the domain names you’re trying to keep your Mac away from.
- Double-click Terminal.
- type sudo nano /etc/hosts then hit return.
- You’ll be asked for your password. Enter your admin password.
You’re now in the Nano text editor. You should see something that looks like this:
If you want to add a new device or domain, move the cursor using the cursor keys and position it after the text you see, then begin typing. If you’re mapping a particular IP address on your local network to a domain, you can type the IP address, hit tab, then type the domain name.
Conversely, if you’d like to make sure a web URL doesn’t go to its intended site — if you’re trying to keep your Mac away from certain sites, use “127.0.0.1.” That’ll map it back to your Mac. Even if your Mac is assigned a different IP address by its router, 127.0.0.1 defaults to the local machine thanks to the default settings in that hose file.
Once you’re done, hold down the control and O keys to save the file, then control and X to exit.
Back at the command line, type sudo killall -HUP mDNSResponder then type return. That will flush your Mac’s DNS cache, so it doesn’t get confused by any changes you’ve made to the Hosts file.
Don’t forget you’ve modified the Hosts file, because at some point you may need to undo the changes you’ve made in order to keep your Mac working right.