Modify Hosts File To Block A Website On Mac OS X Lion [Tip]
If you use a Mac at work and have access to sites like Youtube and/or Facebook blocked, you might have experienced a mixture of disappointment and anger trying to access them. Understandably, these feelings probably helped fuel the search for a way around it. As annoying as these blocks are, they can sometimes be useful and if you’re wondering how it woks on Mac OS X Lion, this post details how you can block websites and domains. The process involves modifying the hosts file on your Mac via the Terminal. Once the domain or website is mapped with localhost, the website/domain is blocked on your system regardless of which browser you use. To unblock a site, you need to access the file again and edit out the modifications you’ve made. You must have Administrative rights to make these modifications or your user account must belong to the administrative group.
Launch the Terminal app and enter the following command;
sudo nano /private/etc/hosts
If your account is password enabled, you will be prompted to enter it. For those of you that have never had to enter their password in the Terminal, type it in like normal. You will not see an asterisk appear for each corresponding character, however, your password is still being typed. That is just how Terminal hides. Type and hit Enter to be taken to the next screen.
You will notice a localhost address on the next screen. Enter this address followed by the website’s address that you want to block. Make sure you do not write https:// or https:// before the address. Hit Control+o and then press Enter to save the modifications to the file. Hi Control+X to exit and press Y when prompted.
Check to see if the blocked site is still opening. If it is, restart your system. When blocking sites, writing
www.sitename.com
will block the website and all pages from it, however, it will not block its subdomains. To block subdomains, enter *.sitename.com. The asterisk (*) is a wild card character which denotes any character or name. Typing an asterisk before a website’s address will block all subdomains of a particular site.
To reverse the changes, revisit the hosts file in Terminal and delete the changes you’ve made. Save the file as you did when you modified it and you will be able to access the site again.
Using the asterisk to block all sub-domains doesn’t seem to work for me. Are there others with this issue?
Same issue with me. I found that we can’t use wild cards in the etc hosts file.
thanks , solved my problem