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

How can I block complete access of my computer to certain domains but be able to switch it on whenever I want to? That is, I want that by default whenever my browser or any other application hits a page of the form, or a page who is somehow connecting me to — that it blocks it and don't send anything without my explicit consent.

I know we can block something completely by using hosts, but the trouble is that I may need to check these domains once in a while, so I would have to keep removing and adding it to hosts. Which is ok if I can refresh it somehow, or have a script do it quickly for me.

Is there a simple way to do it?

I have the impression it can be done with iptables, but this is a subject I am not familiar with.

share|improve this question
up vote 2 down vote accepted

There is a Linux version of SelfControl program which essentially does that - blocks a list of domains for a specified number of hours. It does this using iptables, so you may consider it a nice wrapper for shell commands. The difference from your description is that it intentionally makes it difficult to unblock a domain - to make self-control a bit easier :)

Other options, such as editing /etc/hosts or writing a script which adds/removes an iptables rule - are also viable.

At least you can study SelfControl source to see how it manipulates iptables.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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