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

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:

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.

By Ji m

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 remind me outdated tutorial! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via Buy me a coffee:


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

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

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

Comments are closed.

Exit mobile version