Daniel Cano Merchán - Hacking & Tech

How to setup a pihole to block ads

2020-11-29 #Projects #Hardware

This post is about how to configurate a raspberry pi with pihole to block advertisements. I discovered Pihole on a CTF and was cool to have one !

I was bored this weekend and tired about the advertisements. So I decided to configure a Pihole, this post contains simple work memory used on the process.

SPECIAL THANKS to my friend Mario who just changed a raspberry pi for a few beers!

That raspberry pi has history too!. We won the raspberry on T3chFest, a hackathon on Universidad Carlos III. Each team member won one raspberry pi model 3 kit.

Mine is working hard on my 3D Printer, Ender3, as a remote server (Octopi) to control the printer.

After the cool story behind the raspberry pi, let’s go ahead !

0x01 Parts needed:

  1. Raspberry Pi, I think all or near to all models are Ok for this. 512 MB are required and a few disk space.
  2. SD Card with the system of your choice, I used Raspbian.
  3. A charger to power up your Raspberry pi.
  4. USB Keyboard, mouse and monitor for the initial setup.
  5. This is a must, admin access to your router.

0x02 Flashing the SD Card

Raspberry Pi has a cool image writer to do the process in a simple way:


alt text

Just download the software and plug in the SD card to flash It.

alt text

0x03 Setting up the raspberry pi

Connect everything. Keyboard, mouse and HDMI and just follow the steps and update the system.

Once I get the system up to date. I enabled the SSH service to remote management the Raspberry. No more keyboard, mouse and HDMI needed.

0x04 Installing Pihole

You can get Pihole from the official page:


There are 2 methods, I used the awesome wget method. To download the script, I enabled execution permissions and just fired with sudo:

wget -O basic-install.sh https://install.pi-hole.net
chmod +x basic-install.sh
sudo ./basic-install.sh

Just follow the steps. The script is well designed and will guide you to all the process:

I used the cloudfare DNS and enabled all the blacklists available on the install process.

Pihole needs a static IP address so just configure a static IP to be available.

In my case I used a local static IP address:

I recommend installing the admin interface, it is an accesible web admin panel to remote control the Pihole and enable full logging.

When the installation is over, the admin web panel will be accesible via the IP/admin:

alt text

0x05 Setting up the router

Pihole works as a DNS server, so this step consists in configurating our router to use Pihole as a DNS server.

This process will be different depending on your router model.

Access to the router, normally is the ip address:

Mine is a Movistar router, it was easy to access to the admin panel and change the DNS records. Just point to the DNS records to the static IP address for Pihole.

In my case was:

Local network > Local network > DNS1/DNS2

Probably you need to restart the router, because sometimes this things are cached. So I just restarted the router and the Pihole FTL:

sudo /etc/init.d/pihole-FTL restart

Final thoughts

When everything is OK you will have an additional protection VS those evil ads. But take into consideration that nothing is perfect, a great amount of ads will be blocked but others are just not blacklisted yet.

It is interesting that near 20% to 30% of traffic are blocked, so this 20%/30% are just junk traffic, amazing.

Awesome links:

https://pi-hole.net/ https://github.com/pi-hole/pi-hole