Block Access to Unwanted Websites in Ubuntu 13.10/13.04/Linux Mint

Last updated: September 10, 2013

Want to block access to certain websites from your machine running Ubuntu or Linux Mint? It’s easy to do it by editing the host file.

With the hosts file, you can tell Ubuntu to redirect the specific websites to 127.0.0.1. So that the web browser returns below error:

block specific websites in ubuntu

To do so, edit the /etc/hosts with your favorite editor. Press Ctrl+Alt+T on your keyboard to open terminal. When it opens, run below command to edit the hosts via gedit:

sudo gedit /etc/hosts

Add below lines to the end of the file. Exclude the “http://” and change the domain names.

# block access to certain sites
127.0.0.1 www.websites1.com
127.0.0.1 www.websites2.com
127.0.0.1 websites3.com
127.0.0.1 morewebsites.com

block-specific-sites-via-hosts

Save the file and re-launch your web browser. Done.

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via [email protected] Buy me a coffee: https://ko-fi.com/ubuntuhandbook1

7 responses to Block Access to Unwanted Websites in Ubuntu 13.10/13.04/Linux Mint

  1. i tried but the hosts file is names as readonly. then what shoud i do

    • You need root privilege to edit the file. Use the command in the article, or press Alt+F2 -> type gksudo nautilus and hit enter to open Nautilus file browser as root so that you can edit it in your browser.

  2. How to modify so I can block some sites with warning message?
    Can you help me? thanks before

  3. facebook then also can be easily opened as when
    we type https://www.facebook.com in browser tab
    it will be opened even after saving it in host file!

  4. I tried this for Facebook, and it kind of works… If I open my web browser and type in “facebook.com”, the hosts file reroutes “facebook.com” to “127.0.0.1”. HOWEVER, if I open Google and search for “Facebook”, I can still access the Facebook website. How to you prevent access to the “facebook.com” domain completely?

    Obviously, this is not really about blocking Facebook; it’s about blocking pornographic websites. I’ve tried configuring OpenDNS (208.67.222.123 and 208.67.220.123) as the default DNS for my home router, but its effects are still spotty–even after flushing the DNS cache of my computer and browser.

    I’m wondering if there’s a good way to use UFW to accomplish this? I don’t care if I have to manually list the websites one-by-one or if I can find a way to block all pornography by default–I just want it out of reach.

  5. i want to block facebook