Set up an Ad-filter with Privoxy on Raspberry Pi for free

I hate ads… They are for many companies, unfortunately, the main source of income. So, they are a necessary evil in today’s world where everything is expected to be free of charge.

In general, I use an anti-advertisements filter in the browser. Now I use AdBlock for Chrome. It is available for FF and IE as well.

But, what do you do with mobile devices which, normally, don’t have such a filter?

You use a filtering proxy or gateway.

To set up a gateway with a transparent proxy (or filter) is more complicated.

To set up a filtering proxy is very simple and here is how you can do it easily.

 

What you need

Raspberry Pi B (1 or 2) – you need a network interface and a large enough SD card (8 GB should do)

Raspbian – the de facto OS for RPi

Privoxy – as Privacy Proxy

Privoxy is a non-caching web proxy with advanced filtering capabilities for enhancing privacy, modifying web page data and HTTP headers, controlling access, and removing ads and other obnoxious Internet junk. Privoxy has a flexible configuration and can be customized to suit individual needs and tastes. It has application for both stand-alone systems and multi-user networks.

 

Go to the Quick-Start area for details, I will show you below the bare minimum to run it.

 

Install and setup

Run as root:

#sudo su –

Make the system up to date:

#apt-get update

#apt-get upgrade -y

Now install Privoxy

#apt-get install privoxy

 

The default config will be, in most cases, just fine.

What I did for my installation was to overwrite the default template when an ad is removed.

Normally, Privoxy will replace the add with a JS that allows the user to see the ad.

I don’t want that, so I removed all this nonsense.

So, go to /etc/privoxy/templates and do this:

# copy blocked blocked.original

# echo > blocked

This will backup the original and will make the default template for blocked ads an empty file.

 

Next steps

By default, Privoxy will :

  • bind on the local interface 127.0.0.1 – This is again, a nonsense for me, because I need this to work for my mobile devices.

You need to change this to bind to all IP addresses of the RPi.

  • listed on port 8118 which I personally don’t like. I replaced it with 8888.

Change both by going in /etc/Privoxy/config and search “listen-address”.

Replace the default 127.0.0.1:8118 with

listen-address :8888

 

Last thing to do is to go on your device and change the default proxy:

iOS: go to Settings -> WiFi -> your SSID -> click on “i” and select in HTTP Proxy the option MANUAL.

Enter there the IP of the RPi and set the port 8888 (if you changed it).

That’s it!

Say goodbye to ads !

 

Block more ads

I found quickly that I want more than what Privoxy does by default.

If you find some ads that you don’t want to see anymore, just enter their domains here:

#mcedit /etc/privoxy/user.action

Go to the line with the text “{+block{Nasty ads.}}” at about line 123 / 200.

Insert the ad domains like this:

*.ad120m.com

*.adcash.com

Save it and restart Privoxy

#service privoxy restart

 

PS: Here is my configuration folder for Privoxy. Just unpack it in /etc/

 

Final note

This setup is not the most optimal from a performance point of view. It is just the easiest way to install it. It is rather slow, but good enough for browsing and even online movie watching.

A better approach would be to create a WiFi access point with an USB dongle and to redirect the traffic via the Ethernet connection that runs with a cable.

However, this means that the mobile device needs to connect to the WiFi access point you create. And from this point on, everything what the device does goes over the RPi. I didn’t want this and this is why I chose this setup.


© Copyright 2015 Sorin Mustaca, All rights Reserved. Written For: Sorin Mustaca on Cybersecurity


Check www.endpoint-cybersecurity.com for seeing the consulting services we offer.

Visit www.itsecuritynews.info for latest security news in English
Besuchen Sie de.itsecuritynews.info für IT Sicherheits News auf Deutsch

One thought on “Set up an Ad-filter with Privoxy on Raspberry Pi for free

Comments are closed.