Markus Löning

Software Engineering & Machine Learning

Setting up Pi-hole on Raspberry Pi

Posted at Apr 27, 2024 23:59:05 — Last modified at Nov 1, 2024 13:29:40

I’ve finally had some time to set up Pi-hole on my Raspberry Pi. For most parts, I followed the excellent tutorial on the Raspberry Pi website – more details below.

More recently, I came across this Hackernews thread which mentions some interesting alternatives, including AdGuard Home and NextDNS.

Set up Raspberry Pi

A few useful commands:

Easier login with ssh key and configuration

For an easier login experience, you can use an ssh key. This allows you to login without having to type your password every time. From your usual computer:

You should now be able to connect without your password using: ssh <user>@<host>.local.

To make this even easier, you can configure ssh settings in ~/.ssh/config. For example:

Host anon
  HostName anon.local
  User mloning
  IdentityFile ~/.ssh/id_raspberrypi
  UseKeyChain yes
  AddKeysToAgent yes

You should now be able to simply run: ssh anon.

To log out, simply run: exit.

Assigning a static IP address to the Raspberry Pi

From the Raspberry Pi, run:

Alternatively, you can use the terminal UI mntui (see this blog post for details).

You can also set the static IP from your router’s admin page:

If you don’t know the address of your router’s admin page, you can find it using: nmcli -f IP4.GATEWAY device show wlan0, assuming your computer is connected via wlan0.

Install Pi-hole

On the Raspberry Pi:

In the tutorial, the Raspberry Pi is connected via WiFi, with the wlan0 interface being configured in the installation. If you can connect via an Ethernet cable using eth0 for the interface, that’s usually the preferred choice as it’s more reliable.

After the installation, check if Pi-hole is running:

If you want to reconfigure Pi-hole later, you can always run: pihole -r and select “reconfigure”.

Configure Pi-hole as your network’s DHCP provider

My router did not allow me to set a DNS server, so I configured Pi-hole as my DHCP provider instead. For other options, see the tutorial.

From your router’s admin page:

Next, open the Pi-hole admin dashboard in your browser at: http://<host>/admin/ (for example, http://anon.local/admin/) using the admin password from the Pi-hole installation step above. From the Pi-hole admin dashboard:

You may want to restart your router afterwards. On your computer, you can also try to renew your IP address from the DHCP server. Your usual computer should then show up under the “Currently active DHCP leases” on the Pi-hole admin dashboard “DHCP” settings page.

Check if Pi-hole is working

Finally, verify that Pi-hole is working:

Update Pi-hole

To update Pi-hole, run: pihole -up.