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 – 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 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:



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 Sorin Mustaca, All rights Reserved. Written For: Sorin Mustaca on Cybersecurity

Check for seeing the consulting services we offer.

Visit for latest security news in English
Besuchen Sie für IT Sicherheits News auf Deutsch

About the Author

Sorin Mustaca
Sorin Mustaca, (ISC)2 CSSLP, CompTIA Security+ and Project+, is working since over 20 years in the IT Security industry and worked between 2003-2014 for Avira as Product Manager for the known products used by over 100 million users world-wide. Today he is CEO and owner of Endpoint Cybersecurity GmbH focusing on Cybersecurity, secure software development and security for IoT and Automotive. He is also running his personal blog Sorin Mustaca on Cybersecurity and is the author of the free eBook Improve your security .

Comments are closed.

%d bloggers like this: