Categories
Gadgets Geekery Raspberry Pi

Raspberry Pi as an adblock server for iPad, iPhone, Android and anything else on your network

Adblocker without Jailbreak:

On my computer I find using Adblock plus a handy way to speed up surfing and hide invasive pop-up ads.

Annoyingly you can’t install Adblock on an iPad without jailbreaking it – and I’ve yet to come across a way of installing it on Android devices easily without requiring root access.

Fortunately there’s an easy way to install Privoxy on a Raspberry Pi that can block adverts (and do a few other things as well) and that works seamlessly on iOS and more or less anything you attach to your network.

You could run this software on any PC attached to your network – but with the Pi’s low power consumption  (3.5 watts) you can afford to leave it on all the time. Plus you could combine this functionality with a fileserver or an airplay speaker for a bit of extra usefulness.

Setting up your Raspberry Pi for remote control by iPad

Raspberry Pi running as an Adblock for iOS
Nice conversation piece for geeky dinner parties

First step is to prepare an SD card for your Pi – I’ve been using the default Raspbian.

Next step is to boot up the Pi with a screen and keyboard attached, and connected to your home network with an Ethernet cable. This would also work with a wireless connection, but ethernet is a bit simpler, more stable and means the Pi will run happily off a low powered USB adapter (e.g. a kindle power supply). On it’s first boot the Pi will run the config app – if you’ve already run your Pi before you can restart the config app by typing the following into the console:

sudo raspi-config

Make sure you change the default Pi password, and enable SSH in the menu. We’ll be using SSH to control the Pi remotely.

Now find your Pi’s IP address – in the terminal type:

ifconfig

This will give you some information about how the Pi is connecting to the network – make a note of the inet addr – usually 192.168.1.number (I’ll use this notation to refer to this value in the guide)

Next you can connect to your Pi using an SSH client – I’ve been using Remoter Fusion on the iPad (other SSH apps are available but I was using Remoter for something else) note that you will need to purchase SSH support in app which adds £5 to it’s price.

To connect to your Raspberry Pi with Remoter Fusion, click on discovery list -> Add Session Manually. On the Server Type choose SSH.

In the box that says SSH Hostname enter your Pi’s IP address which you found out above:  192.168.1.number then choose Manual – leave the SSH Port setting at 22 and in SSH Username enter your Pi username and SSH Password your Pi password.

Remoter Fusion iPad with Raspberry Pi
Remoter Fusion

Then connect – you might get a warning message (just accept) and then you should be seeing the Linux prompt.

Now you need to change your Pi from having a dynamic IP address (given to it by the router every time it reboots) to a static IP address which will stay the same. In the prompt type:

cd /etc/network
sudo nano interfaces

this launches nano which is a basic text editor – the following settings will depend on your Router – most routers will have a configuration page which will give you this information if you visit their configuration page – usually found on your network by typing 192.168.1.1 into a browser. The following settings worked for the BT Homehub version 3.

auto eth0
iface eth0 inet static
address 192.168.1.number
gateway 192.168.1.254
netmask 255.255.255.0
network 192.168.1.1
broadcast 192.168.1.255

Press control and O and then enter to save, followed by control and X to exit.

You might want to test your settings – either by using the Ping command, or by attaching a monitor / keyboard / mouse directly to the Pi and firing up the web-browser – the Pi should be able to connect to the internet.

Installing Privoxy on your Raspberry Pi

Finally we just need to install Privoxy – with the nice simple:

sudo apt-get install privoxy

then start Privoxy

sudo /etc/init.d/privoxy start

Then you’ll need to setup Privoxy by editing the configuration file –

sudo nano /etc/privoxy/config

This is a long file with lots of options – scroll or do a search with control W and find the listen-address line. Change it to 192.168.1.number:8118

Control O to save in nano then control X to exit.

Restart Privoxy with:

sudo /etc/init.d/privoxy restart

Now on your iPad go to settings -> Wi-Fi -> your network name and then scroll to the HTTP proxy options. Choose Manual and where it says Server type your Pi’s IP address: 192.168.1.number and where it says port type 8118.

Finally go to config.privoxy.org and if it’s all working correctly you should see an enabled message.

Straight out of the box Privoxy started blocking ads for me – you can edit the exact way it does this in the configuration files. So websites like this:

Lots of Adverts
Lots of Adverts

Become websites like this:

After Adblock on iOS
Less adverts. Still rubbish.

You can take this a bit further by turning your Pi into a personal VPN for secure browsing on the go with this Lifehacker tutorial.

Probably an overkill using a Pi for this, but it is handy being able to work on the Pi using an iPad and as I mentioned before there are a few other useful things your Pi could be doing at the same time.

17 replies on “Raspberry Pi as an adblock server for iPad, iPhone, Android and anything else on your network”

Thanks for the great tutorial! I set it up for my iPad but I have an issue: privoxy blocks Youtube and iMessage pictures. Could you tell me how to add the necessary lines to the config file? that would help me out a lot 🙂

Hi Maze W, I get the same thing with the out of the box functionality of Provoxy. I’ll post back here when I work out how to configure the actions file….

Thats pretty nice and EXACTLY what i am looking for (because i want to buy a pi), but one question, is there a possibility to FORCE every Computer in MY NETWORK to use this Proxy?
Because some of my friends have an ipad too and they looking astonished when they see i have no ads in my ipad but they have, and i don’t wanna show them to always shut on / shut off the proxy.

I gave this a go last night, but I found the page load performance was quite poor.. so I’ve decided not to use Privoxy like this on a Pi. Bit of a shame. Thanks for the guide.. only took 10min to give it a go 🙂

Hot Tip: set the listen-address in /etc/privoxy/config to 0.0.0.0 (instead of 192.168.1.number).
This means that privoxy listens on ALL network interfaces (including the loopback interface).

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.