Installing Pi-hole on a Raspberry Pi

Check for, and install, any updates with:

sudo apt update
sudo apt upgrade

Once updates are complete, we need to set a static IP address using NetworkManager. List all the network interfaces with:

nmcli device status

Find and edit the ethernet connection with (make sure to swap “netplan-eth0” with your ethernet interface name if it differs):

sudo nmtui edit "netplan-eth0"

Use the arrow keys to navigate this interface to swap the IPv4 configuration from automatic to manual. Set your desired static IP address and gateway IP (usually your router’s). Restart NetworkManager to apply these changes and check your new IP address is set:

sudo systemctl restart NetworkManager
nmcli device show eth0

Now we need to install docker with the following commands:

# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Now add the user to the docker group so that you don’t have to use “sudo” to run docker commands:

sudo usermod -aG docker $USER 

Create new folder to store your docker compose file & create a the compose file:

mkdir docker
cd docker
nano docker-compose.yml

Copy the following example file into the compose file (source: https://docs.pi-hole.net/docker/):

# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    ports:
      # DNS Ports
      - "53:53/tcp"
      - "53:53/udp"
      # Default HTTP Port
      - "80:80/tcp"
      # Default HTTPs Port. FTL will generate a self-signed certificate
      - "443:443/tcp"
      # Uncomment the below if using Pi-hole as your DHCP Server
      #- "67:67/udp"
      # Uncomment the line below if you are using Pi-hole as your NTP server
      #- "123:123/udp"
    environment:
      # Set the appropriate timezone for your location from
      # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones, e.g:
      TZ: 'Europe/London'
      # Set a password to access the web interface. Not setting one will result in a random password being assigned
      FTLCONF_webserver_api_password: 'correct horse battery staple'
      # If using Docker's default `bridge` network setting the dns listening mode should be set to 'ALL'
      FTLCONF_dns_listeningMode: 'ALL'
    # Volumes store your data between container upgrades
    volumes:
      # For persisting Pi-hole's databases and common configuration file
      - './etc-pihole:/etc/pihole'
      # Uncomment the below if you have custom dnsmasq config files that you want to persist. Not needed for most starting fresh with Pi-hole v6. If you're upgrading from v5 you and have used this directory before, you should keep it enabled for the first v6 container start to allow for a complete migration. It can be removed afterwards. Needs environment variable FTLCONF_misc_etc_dnsmasq_d: 'true'
      #- './etc-dnsmasq.d:/etc/dnsmasq.d'
    cap_add:
      # See https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
      # Required if you are using Pi-hole as your DHCP server, else not needed
      - NET_ADMIN
      # Required if you are using Pi-hole as your NTP client to be able to set the host's system time
      - SYS_TIME
      # Optional, if Pi-hole should get some more processing time
      - SYS_NICE
    restart: unless-stopped

Edit the timezone and set a password for the web interface. Save and close the file. Then start docker with:

docker compose up -d

Pi-hole should now be downloaded and start running. Navigate to the IP address of your Raspberry Pi in a web browser.

http://<ip-address>/admin

Leave a comment

Your email address will not be published. Required fields are marked *