By editing the hosts file and adding: 0.0.0.0 sitetoblock.com I can block that particular website. Using the hosts file, is it possible to block every website except a few sites I specify? Wikipedia and dictionary.com would be whitelisted.

If this isn't possible with /etc/hosts, would you recommend another method or app that would do something similar? I do not want a browser plugin, but rather an OS wide block.

Can you use wildcards with your hosts file? (just a thought)
–
Bruno PereiraAug 27 '12 at 11:35

I'm not sure but that would be nice. Then after the wild card statements, I can put the sites I want to whitelist and their actual IP?
–
Kevin DukeAug 27 '12 at 11:36

Think you need to setup your own DNS server (allows wildcards) or use iptables to filter all traffic. hosts does not allow wildcards. Do you have the ability to setup and change the network we are are talking about or this is just a computer?
–
Bruno PereiraAug 27 '12 at 11:37

2

If you are trying to increase your producitivity, a browser extension might be the better option. Have you tried out Stayfocusd (chrome) or Leechblock (Firefox) ? Both offer the options you are searching for.
–
GlutanimateAug 27 '12 at 11:38

Nice solution from @Glutanimate ^^ Might work if the people we are talking about here are not that smart.
–
Bruno PereiraAug 27 '12 at 11:39

1 Answer
1

Also known as an intercepting proxy or forced proxy, a transparent
proxy intercepts normal communication at the network layer without
requiring any special client configuration. Clients need not be aware
of the existence of the proxy. A transparent proxy is normally located
between the client and the Internet, with the proxy performing some of
the functions of a gateway or router

Doing it with /etc/hosts is fine, as long as the user doesn't know about the file or doesn't have the permissions to edit the file. But I guess what you want to achieve would be easier if you use proxy, although it will take some time to set it up.

To set up the transparent proxy, you can use squid. Here are some quick steps to set it up:

Install squid

sudo apt-get install squid squid-common

Edit the /etc/squid3/squid file:

Look for the line http_port 3128 and make sure it is uncommented. squid by default listens to port 3128.