Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

marked as duplicate by Eric Carvalho, Alvin Row, Eliah Kagan, Alvar, Raja Aug 15 '13 at 15:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Why is this different from your other question? Stick a bounty on it if you want it answered rather than just asking it again and again. – Oli Aug 8 '13 at 9:36
Oli, check the chat. I talked it over with fossfreedom. Also there is no reference question for this problem. – don.joey Aug 8 '13 at 9:41
Should I conclude that this is not possible without modifying hosts? – don.joey Aug 12 '13 at 15:12
No, the very first option I gave you in your other question (the port of Self Control) does this with iptables. – Oli Aug 12 '13 at 15:22
I think it is a mistake to think of this as a duplicate. After all, the suggested dupe question is about restricting access to certain websites, whereas this question is from the other perspective: restricting everything except one or two. The solution proposed by Oli does not, and I repeat, not do that. It only blacklists, but does not whitelist. – don.joey Aug 20 '13 at 19:28

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

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

Worth reading:

share|improve this answer
For reference' sake, I was asking for something "easy (not manually editing hosts, but a script for instance)." – don.joey Aug 8 '13 at 10:09
This really does not answer my question as I ask for all websites to be blocked, except a few. – don.joey Aug 9 '13 at 14:40

I was able to achieve what your after by following 1st post in this thread:


share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.