echo facebook.com >> /etc/hosts is a pretty simple solution to prevent facebook.com and its subsites from resolving to an IP address. (This is also how Linux Mint's Mint Nanny works).

I would like to extend this to all sites except for a select few, however, I can't seem to find any workable solution on the web.

I have found some clues suggesting using a transparent proxy server, however I can't seem to be able to get it to work.

Can anyone post a concrete, straightforward recipe on how to achieve this simple goal (in an Unix-like operating system, preferably a GNU/Linux)?

  • 2
    How about only adding the white listed hosts to /etc/hosts and disabling external DNS lookup ? (Note that people still can access those sites if they just use the sites IP rather than its name).
    – Hennes
    Jul 30, 2013 at 13:27

2 Answers 2


Use dnsmasq. This is a really neat service.

On Debian/Ubuntu/Mint:

sudo apt-get install dnsmasq

edit /etc/dnsmasq.conf

add this line to make all sites redirect to localhost:


add these lines to make specific sites use the DNS server at


then restart the dnsmasq service:

sudo service dnsmasq restart
  • When I was using Ubuntu 18 this was working for me. Since I upgraded to Ubuntu 20 this doesn't work for me anymore.
    – BigJ
    Jun 11, 2021 at 17:45

You don't need to DNS block. Setting up an Apache mod_proxy and ProxyBlock would be enough.

  • Some details would be nice though Mar 31, 2022 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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