Ubuntu – How to block all but one or two websites without browser extensions?

firewallwebsites

I want to block all, but one or two websites. This question is therefore relatively close to, but different from the following

I know that this can be done with leechblock (for FF) or something similar for other browsers. I think that is not a very clean solution, because it is browser-based. I know this was both possible and easy with Firestarter but that package is deprecated.

I am looking for something which is both easy (not manually editing hosts, but a script for instance) and systemwide. It can use the CLI.

I would love a relatively detailed answer rather than just links to other websites – screenshots would be most welcome.

Best Answer

  • You can block websites system-wide by adding entry to hosts file. It works same as in windows.

    Here's how to do it :

    Open terminal and type :

    sudo nano /etc/hosts

    append the file with

    127.0.0.1 facebook.com

    Now whenever you'll visit facebook.com it will take you to localhost. FYI, it is not re-direct.

    Worth reading: http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/