Stop ads with Pi-hole
Set up your Pi as a powerful ad-blocking access point in minutes.
There aren’t many projects on the Raspberry Pi that can be installed using just one or two lines of code. However, the creators of the Pi-hole project have created an installer that’s so simple to download, you can set up your Raspberry Pi as an ad blocker in minutes.
While you may be familiar with browser plugins such as AdBlock Plus, these are used to block code from web pages that have already loaded. The Pi-hole blocks advertising websites at a DNS level, so they’re prevented from loading in the first place. This requires no client-side software and generally is a much smoother and easier way to keep your home or office network free of annoying adverts.
Opening your Pi-hole
In order to proceed, you’ll need to install the latest version of Raspbian on your Pi. Make sure to run sudo apt-get update and sudo apt-get upgrade on your Pi before following the steps in the tutorial. The Pi-hole is compatible with all models of Pi, but if you wish to connect it to your router via Ethernet (which we recommend) you’ll need to use either a Raspberry Pi 3 or a Pi Zero/Pi Zero W with a USB OTG Ethernet adaptor.
The term ‘DNS Servers’ is most commonly used to refer to publicly accessible computers, which contain hostnames such as www.linuxformat.com and their related public IP address. This enables websites to have recognisable names rather than a string of numbers. Every internet-enabled device you use queries a DNS server each time you try to access a website.
Pi-hole acts as a DNS server, connected to your local network. Any requests made from devices can be routed through the Pi-hole and checked against a constantly updated list called Gravity, which contains millions of domains that do little but offer advertising and spam. If a domain is listed, it’ll be consigned to a black hole of internet advertisements. In less-poetic terms, Pi-hole will simply not load the domain.
For permitted domains, the Pi-hole accesses an upstream DNS server available on the public internet such as OpenDNS, which will then load your page seamlessly.
Follow the steps in the guide ( opposite) to set up your Pi-hole. Once this is done you’ll need to configure your router or devices to use the Pi-hole as their DNS server. See the boxout ‘Down with DNS’ ( below) for more help with this.
If the prospect of automatically blocking millions of spammy websites isn’t enough to entice you, Pi-hole also has a handy admin interface that’s created automatically during setup.
You can access it either at http://pi.hole/admin or http://yourPi-hole-ipaddress/admin. The interface is protected by a password, which is generated for you during setup. You can change this from Terminal by running pihole -a -p .
Click Query Log in the left-hand side to view all the domains that have been accessed by devices on your network. Choose the Whitelist or Blacklist button next to each domain name to allow or block them respectively.
If you want to fine-tune your web filters further then click the Blacklist button on the left-hand side and enter a domain
name to block it automatically. We recommend that you take some time to explore the Settings section to discover all of Pi-hole’s features.
Is ad blocking theft?
Eyeo GmbH, the German company that makes Adblock Plus, has been through no fewer than six court cases by publishers, who claim that the blocking of their online ads is illegal, but so far the courts haven’t agreed. In the case of Adblock Plus, websites are asked to pay in order to feature acceptable ads on a pre-approved whitelist.
Pi-hole, on the other hand, is a project that runs on a notfor-profit basis, relying on donations to stay afloat. This is one of many ways that websites can monetise their content besides displaying adverts. If you’re using websites that are owned by multi-million dollar corporations, you also may not lose too much sleep in blocking their adverts before they reach your screen.
The strongest argument for ad-blocking software is that tracking cookies and advertisements can be used to gather information on your browsing habits and sometimes even install malicious ‘junkware’ on your devices. Most websites and apps have both a free and premium version, so if your conscience is pricking you, consider supporting your favourite services by subscribing or making a donation.
Getting Pi-hole up and running
During installation, the program will inform you that the Pi-hole needs a static IP address to function properly and offers to assign itself one using your network settings. Generally speaking, even if the device restarts any modern router won’t try to assign it a new IP. However, to be on the safe side you may prefer to configure your router to assign the same IP to your Pi-hole’s Mac address, so that none of your devices will run into problems.
If your router doesn’t support changing DNS settings, then you can configure each device manually to use the
Pi-hole. See the Down with DNS box ( belowleft) for more information. Bear in mind that some internet devices such as Google’s Chromecast media streaming device don’t support manually changing DNS settings. You can work around this by accessing Settings from the Pi-hole’s web admin interface and use Pi-hole’s DHCP server. Make sure to disable DHCP on your router if you do this.
If you’re setting up the Pi-hole to protect your family from harmful websites, remember that anyone with access to a device can also change their own settings back to using a Public DNS. This will enable them to visit any site without being logged by the service.
Should you find the settings are too restrictive, then you can also whitelist certain domains by entering your admin password on blocked pages, or even disabling Pi-hole altogether for a certain amount of time – for example just for five minutes – from the web admin interface.