In this guide we’ll set up a Raspberry Pi with a DNS server to block ads on your network. You can then use this on your iPad to block ads, but also on other devices. Not only will this make browsing a much cleaner experience, it will also make it much faster!

Prerequisites

To complete this guide you’ll need the following things:

  • A Raspberry Pi
  • A 4GB SD card
  • HDMI display and keyboard
  • Network cable

Flashing the Raspberry Pi

The first step is preparing the Raspberry Pi. For this guide we used Raspbian (version 2014-07-01), which you can download here. Once you have downloaded Raspbian you’ll have to unpack the .zip file by double clicking it. This will give you a .img file.

Now we need to flash the .img file to a SD card. First of all you need to place an SD card in your computer of at least 4GB. On the Mac we will do this using Apple Pi Baker, download Apple Pi Baker from here and open it. Select your SD card on the left side. Then on the right side in the section ‘IMG Recipe’ click the ‘…’ button and select the Raspbian image from your Downloads folder. Then click ‘IMG to SD-Card’.

raspberry pi flashing

The flashing might take about ten minutes to complete. As soon as it is completed eject the SD card and place it in your Raspberry Pi.

Starting and updating Raspbian

Power on your Raspberry Pi. After the first start you’ll be greeted with a setup screen. All settings are already as we need them by default but changing your user password with option 2 in the menu is very recommendable. After changing your password use the arrow keys on your keyboard to go to ‘Finish’.

Now it’s time to update the system to make sure all security updates are installed. Enter the following to commands (and confirm each by pressing Enter):

sudo apt-get update
sudo apt-get upgrade

You’ll have to confirm the second command by pressing Y and confirming with Enter.

Setting up a static IP address

Because we will need to enter the IP address of your Raspberry Pi in your iPad later we don’t want it to change. To do this we will assign it a static IP address in our router. The process to do this differs for every router unfortunately, so we can’t explain this for every situation. If you use an Apple Airport base station or Time Capsule please use the steps in this guide. To find out the MAC address of your Raspberry Pi run the following command:

ifconfig eth0

Note the value next to HDaddr. This is the MAC address of your Raspberry Pi. After you’ve configured your router reboot your Raspberry with the following command:

sudo reboot

Installing and configuring the ad blocking server

Now would be a good time to switch to SSH. This means you can control the Raspberry Pi from your Mac and just past commands. You can skip this step if you want though and keep using the keyboard. Open the Terminal on your Mac (find it in the Utilities folder in your Applications). Enter the following command and replace raspberry_ip with the IP address you assigned to it:

ssh pi@raspberry_ip

The first time you do this you’ll have to type ‘yes’ and confirm with Enter. Then enter your password and confirm again with Enter.

For this guide we will use the DNS server called Bind to block the servers the ads are hosted on. In addition to this we will install Apache to serve empty pages when ads are loaded. Don’t worry, you won’t get empty blocks in your websites, it’s just there to make sure you won’t get any errors about pages that aren’t loading correctly. Run the following command:

sudo apt-get install bind9 apache2

Confirm the selection by pressing Y and then Enter.

When the installation is complete we’ll configure the DNS server. Enter the following commands:

cd /etc/bind/
sudo wget http://www.macgeeks.co.uk/downloads/blacklist
sudo wget http://www.macgeeks.co.uk/downloads/null.zone.file
sudo nano named.conf

The last command will open a text editor. Add the following line:

include “/etc/bind/blacklist”;

Now to save the file press CTRL + X, followed by Y and Enter. Now edit the file called ‘null.zone.file’ using the same method, and change 10.0.1.51 (three times) to your assigned static IP.

sudo nano null.zone.file

That’s it! The Raspberry Pi is ready. Just make sure to reboot it with this command:

sudo reboot

Setting up your iPad to use the ad blocking server

Make sure your iPad is connected to Wi-Fi (so it’s on the same network as your Raspberry Pi). Go to ‘Settings’, then to ‘Wi-Fi’ and tap the ‘i’ next to your wireless network. Change the entry for DNS to the IP address you assigned as a static IP. Don’t change any other settings! In the screenshot below we used 10.0.1.51.

Enjoy your ad-free iPad!

iPad wifi settingsEnabling ad blocking on other devices

On other devices you can now also block ads. The only thing you’ll need to do is change the DNS server like we did on the iPad to the Raspberry Pi’s IP address. The way to do this is a bit different per device though. Usually you’ll find this option under advanced network settings.

Tagged on:             

Call now

You can reach us at: 0905 078 0424

Open Mo-Fr from 9 AM to 6 PM.

Calls cost 76p per minute from a BT landline. Calls from other networks may vary. For complaints and inquiries you can call 020 369 52 721. SP IMSupport.