Using HOSTS File To Block Web Access 4


Using HOSTS File To Block Web Access


Quite a while ago I mentioned about using Parental Controls to restrict the sites that are accessed on an account. There is a higher level version of this that can be used to block complete access to websites, the good thing about this trick is that it is a lot harder to remove, and for enterprising kids it will be a lot more difficult to find out and remove.

This tip is going to modify a file called hosts, its basically a text file which tells you computer what to do with specific domains and IP addresses. It similar to your DNS except it is used to change where they go. Hosts file is a high level file, as a result it will always take precedent over other files and applications. You do need a bit of technical experience with this tip, so proceed with caution.

The simplest way to do this is as follows, if you know how to use Terminal and nano you can use that. The first step is to follow this tip, and allow TextEdit to become an admin user. This allows you to edit the host file. First copy and paste this command into Terminal.

sudo /Applications/

In TextEdit, open up the open new file window. This will be used to open the hosts file. Due to the way Finder works you won’t be able to navigate to the specific file, due to this open Finder, and go to Go > Go To Folder and type the following


The window that pops up contains lots of important files which allow your computer to run. In the list there should be a file called hosts. Drag this file onto the open window of TextEdit. The file should then open.

This is now you text file, and you should see a couple of lines. Do not delete any of the lines. The file should look like the following:          localhost    broadcasthost
::1                localhost
fe80::1%lo0        localhost

This contains IP addresses on the left and websites on the right. Currently there are no websites in the list. To add one to be blocked type the following:

When you save the file any time you access or it should produce a 404 error. This file is sending any requests to to your home IP address, since there is nothing there it wont load a page. If you host a website on your computer you can always change to As a result you can’t access the website. Ideally you don’t need to add the www and the none www, bit however this should work 100% of the time. The host file will take a couple of minutes to come into effect so, sit back and wait if the results don’t work straight way.

This method shouldn’t be used as a comprehensive list of website to block, since its a convoluted method to add them. Its best used to block one or two websites which you really don’t want to be accessed.

To restore access simply delete the line or add a hash (#) in front of the IP address. When you have completed finished quit text edit and return to what you were doing.

If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips