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 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


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


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:

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 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 “”, the hosts file reroutes “” to “”. HOWEVER, if I open Google and search for “Facebook”, I can still access the Facebook website. How to you prevent access to the “” domain completely?

    Obviously, this is not really about blocking Facebook; it’s about blocking pornographic websites. I’ve tried configuring OpenDNS ( and 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