Setting up a PiHole
What’s a PiHole? <
It’s basically a DNS sinkhole. DNS servers resolve domain names into IPs. DNS sinkholes are basically faulty DNS servers. For example when you go to a website your web browser will also download ads. In order to get them it has to resolve the domain name of the ads provider into an IP. That’s what DNS server does. PiHole is just a local DNS server which say ’nah’ when you ask it to serve a content from a blacklisted provider. You can add domains to the blacklist banning their content but you can also whitelist those you want to support.
The project has been started by Jacob Salmela. It’s open source and it runs on the cheap ARM boards like Raspberry Pi. It’s pretty amazing.
OS - DietPi <
I chose to go with DietPi for the OS. It’s a lightweight, heavily optimized OS for boards like Raspberry Pi. I really enjoy using this OS.
I’ve dropped my SD card into a USB card reader and plugged it into the PC. I’ve downloaded the DietPi image. For dropping the OS onto the SD card I’ve used Etcher. It’s an extremely easy program to use. Thumbs up for simplicity.
After flashing I’ve went through the
dietpi-wifi.txt
and
dietpi.txt
files
you can find on the
boot
partition of the SD card. The first one allows
you to drop in your WiFi network SSID and password. The latter has a plethora of
options to set.
Interesting ones:
AUTO_SETUP_NET_HOSTNAME=DietPi
- the default hostname. Cosmetics thing as long as you are running only one of those. Left it on default.AUTO_SETUP_GLOBAL_PASSWORD=dietpi
- the default password. Changing that would be a good idea. I left it default… (please don’t hack me).AUTO_SETUP_SSH_SERVER_INDEX=-1
- this one is interesting. By default DietPi uses Dropbear as an SSH server. Dropbear can’t transfer files withscp
command. I changed it to OpenSSH (-2
) because of that.AUTO_SETUP_AUTOSTART_TARGET_INDEX=0
- this field dictates into what should the board login (console, X server, etc.). The default value0
is console without logging as a root. That works for me.CONFIG_HDMI_OUTPUT=1
- this on allows you to turn off the HDMI output. Changed it to0
since I want to run this board headless.CONFIG_SERIAL_CONSOLE_ENABLE=0
- by default DietPi outputs the terminal onto the serial port only during the first boot, then it turns it off. I left it on default. I’ll regret that.
After going through those files I’ve dropped the SD card into the board and powered it
on. I logged into my router through a web browser and checked the board’s IP. It
was
192.168.1.126
… not like it matters but just wanted to share.
I’ve logged in to the board through SSH. As soon as you connect the
DietPi
starts going
through update/upgrade cycle. When it’s done, it reboots. On the second login
DietPi
starts another utility, to setup additional software. This utility is called
dietpi-software
.
That’s one of the things I enjoy when using
DietPi. It has it’s own utilities/tools
for updating software and changing settings. To see all of them you just need to
type
dietpi-
and press TAB.
Going through the settings I’ve found the options to set the static IP. Since PiHole makes a server out of this Pi, setting static IP seems to be the way to go. I’ve set the static IP and rebooted…
After the reboot I couldn’t connect to the board using the new or the old IP. The router didn’t report the board as connected… At this point having a terminal output on the serial port pins would be useful… I decided to just reflash the OS on the SD card once again. Seemed like the fastest way to go.
This time I didn’t set anything in the
.txt
files. That’s because when I went
through the
dietpi-
utilities I’ve seen that they provide the same options.
I’ve booted the board again, went through the typical setup and changed to
OpenSSH
through
dietpi-software
.
PiHole <
At this point I wasn’t worried about the static IP. That’s a problem I would solve
later. I’ve installed the PiHole using
curl
just as it’s described on the PiHole
website. Unfortunately the builtin
lighttpd
server didn’t serve the PiHole web
interface. Using
dietpi-services status
I could verify everything is fine with
the
PiHole
service. There was nothing about
lighttpd
in there.
Once again using
dietpi-software
solved the issue. Under
Software Optimized
you can find the
PiHole. Installing it through this utility also installs necessary
dependencies and also forces you to set the static IP. This time I have put in the
same IP it got from the DHCP server. After installation the
dietpi-services status
showed both
PiHole
and
Lighttpd
running.
I’ve quickly set the DNS server IP in my router settings to the same one the board used.
At this point everything should work (well except the static IP).
I’ve tried the
192.168.1.126/pihole
and my browser has shown me the PiHole’s web interface.
Was it worth it? <
No idea. I’m writing it the same day I’ve set it up. According to the PiHole stats 22.1% of the traffic has been blocked (1510 out of 6832 queries). Seems dramatic, doesn’t it. I’ll update this article if I’ll have any other thoughts about this project.
One thing that’s certain is that it’s ridiculously easy to setup. The
DietPi
is really
slim (just run
htop
or
dietpi-services status
- barely anything going on there). It’s
also really enjoyable to work with (PiHole
was basically a checkbox in the settings).