This is how you make an adblocker with Raspberry Pi and Pi-hole

It is one of the biggest annoyances on the internet: advertisements. You can of course install an ad-blocker in your browser for any device, but if you also want to protect your smartphone, smart television and game console against advertisements, a central ad-blocker is much more convenient. There are expensive commercial solutions available, but with a Raspberry Pi of a few tens and a Pi-hole you achieve exactly the same. In this article we show you how easy this is.

01 Buy Raspberry Pi

For the workshop you need a Raspberry Pi, it doesn't matter which version you use. The most recent version is Raspberry Pi 3 Model B, which costs about forty euros. In addition to the mini computer, you need a microSD card on which you place the software. If your computer doesn't have a card reader, you'll also need a card reader. You also need a micro USB cable and a 2 amp USB power supply. A housing is optional, but useful if you want to use the device for a longer period of time.

Download 02 Raspbian

For Pi-hole you can install the standard operating system Raspbian. Go to www.raspberrypi.org, click Downloads and then raspbian. Pi-hole needs a stripped version, so you can use Raspbian Jessie Lite on Download ZIP click. If you are using Raspbian for the first time, however, it is more convenient to download the normal version because you then have a desktop environment at your disposal. After downloading, extract the file. In this workshop we will work with the standard version of Raspbian with desktop environment.

03 Download DiskImager

Download the Win32DiskImager program, install it and open the program. Connect the SD card to your PC and check which drive letter is assigned to the SD card. In DiskImager check if the correct letter is shown and open the Raspbian disk image by clicking on the folder next to the letter. click on write to copy the image to the SD card. Confirm the action by pressing yes to click. Writing to the operating system may take a few minutes. When the message Write Successful appears, click OK and remove the SD card from your PC.

04 Install Raspbian

For the initial setup and configuration of Raspbian, you need to connect a keyboard and monitor to your Raspberry Pi. You connect the monitor to the connection of the Raspberry Pi via an HDMI cable. Then slide the microSD card into the slot on your Raspberry Pi. To power the Raspberry Pi, you can connect a power adapter or connect a USB cable between your Raspberry Pi and your PC. Raspbian will start and lines of code will appear on your screen, wait for the operating system to open automatically.

05 Configure Raspbian

Before you put the software Pi-hole on your Raspberry Pi, it is useful to change a few settings in Raspbian. Go to Menu / Preferences / Raspberry Pi Configuration and indicate, for example, your location, time zone and keyboard layout. It is also useful to configure your network setting beforehand. Go to the network icon at the top and choose your wireless network. Log in and you have connected the Raspberry Pi to the internet. Of course you can also use a wired network connection.

SSH

You can do the further installation of Pi-hole via an SSH connection from your computer. Before you disconnect the monitor, mouse and keyboard, first go to the Terminal at the top. type hostname -I to find out the IP address of your Raspberry Pi. For Windows you need to download an SSH client, PuTTY is a well known one. In the field Host Name type the IP address, then click Open. In macOS, go to the terminal and type ssh [email protected] address where of course you enter your IP address. The account name is pi and the password is raspberry.

06 Expand file system

To make sure you can use all the available space on your SD card, you can type sudo raspi-config in the terminal on the Raspberry Pi or in your SSH client on your PC or Mac. Select Expand Filesystem and then choose Finish. You have to restart your Raspberry Pi after this, so choose yes if you are asked to do so. This step also often helps if you run into problems while installing Pi-hole.

07 Install Pi Hole

Enter the following code in the terminal: curl -L //install.pi-hole.net | bash. Click twice OK and when you get to the static IP window, click again OK. Pi-hole only works if the Raspberry Pi has a static IP address. In the next window, select whether you have connected the Raspberry Pi via Ethernet or WiFi, you can make a selection by pressing the spacebar. If you want to go to the next window, navigate with the arrow keys and confirm an action with Enter.

08 Static IP Address

If the window with the option Select Protocols appears, choose IPv4, currently the ad-blocker works best over IPv4. You will then be asked whether the offered static IP address is okay for you. In most cases this is fine and click yes. Should the IP address be in the range of the addresses your router randomly assigns to devices, it could cause a conflict. In that case you choose no and enter your own IP address. If you for yes If you choose, Pi-hole will warn you in any case for this possible conflict.

09 Upstream provider

The installation is almost done, at the end Pi-hole asks if you want to change the Upstream DNS Provider. Google is the default choice and this is fine in most cases, but you can also use the OpenDNS, Level3, Comodo or Norton upstream. When the text Make it so appears on the screen, the installation is complete. Write down the IP address of your Pi-hole, this is the address your devices should use from now on, we'll get started in the next steps. End with OK, a few more lines of code appear and then the installation is really done.

10 Router or individual devices

To block ads, you now have to route all your internet traffic through the Pi-hole. This can be done in two ways. The first way is to reference your Pi-hole on all your devices. This has the disadvantage that you have to set this on each device separately. Another option is to set up your router so that any connection goes through the Pi-hole before it is passed to devices on your network. We explain both options in the following steps.

11 Configure Windows

In Windows 10, go to the control panel and click Network and Internet / Network Center. click on Adapter Settings modify. Right click on the connection you want to change and select Characteristics. Make sure you are in the tab Networking are and select Internet Protocol version 4. click on Features / Advanced. Choose the tab DNS and add the IP address of your Pi-hole by pressing Add to click. End with OK and don't forget to do these steps with any other network connections.

Macs and smartphones

On the Mac, go to System Preferences / Network. Select your connection and click on Advanced. Choose the tab DNS and enter the IP address here. On an iPhone you will find the setting at Institutions / WiFi. Click on the i behind your network name and change the address after DNS. In Android go to Institutions and hold your finger on the name of your network. Tap on Customize network and put a checkmark in front of it Advanced options. Scroll down and change DHCP nasty Static. at the bottom at DNS 1 enter your Pi-hole address. Bee DNS 2 enter 8.8.8.8, Google's DNS service.

12 Administration panel

In your browser, go to the IP address of your Pi-hole and type after the IP address /admin. This is your Pi hole's configuration page. You can see how much advertising has already been blocked today, how many domains have been blocked and which devices have made which requests. below Top Advertisers you can see from which domains the most ads are blocked. Bee Query Log you will find an overview of all your internet traffic, unfortunately you cannot disable this or delete certain entries.

13 Local DNS in your router

The most convenient way is to redirect all traffic from your router to your Pi-hole. Go to your router's settings and look for the settings screen where you can change DHCP options or find settings for IPv4 addresses. Here you will probably also find the option to indicate a local DNS server. You can only find out whether this option is offered in your router and whether this is possible at all by looking in the manual of your router or by sending your provider an email.

14 DHCP Refresh

You may need to renew the DHCP lease on your device before traffic is routed through the Pi-hole. In Windows, open the Command Prompt by in the search bar cmd to key in. type ipconfig /release and press the Enter key. If successful, then type the command again ipconfig /renew and close by pressing Enter to push. On your Mac you will find this option at System Preferences / Network. Click on you network connection and choose Advanced. click on TCP/IP and select Renew DHCP lease.

15 Blacklist and whitelist

If you want to whitelist or blacklist certain domains, you can do that in the administration panel of your Pi-hole. Websites "live" off ad revenue, so it's "nice" to whitelist sites you enjoy visiting. click on whitelist or blacklist to add a domain. Since the Pi-hole filters advertisements at the DNS level, it makes no sense to just add a url. On the Pi-block website you will find a clear explanation of how to apply a whitelist or blacklist to your Pi-hole. Here we explain how to whitelist our sites.

IPv4 and IPv6

A lot of ads are blocked by Pi-hole, but sometimes one slips through. In most cases this concerns advertisements via IPv6. Ad networks have been delivering more and more advertising over IPv6 recently, but for now, Pi-hole filtering over IPv4 still works best. It is recommended that you wait for the notifications on the website www.pi-hole.net and upgrade your Pi-hole to IPv6 filtering in the future.

Recent Posts