Pihole + Unbound mit Docker auf dem Raspi

Ziel

pihole und unbound in jeweils einem eigenen Container, um mögliche Port Konflikte zu vermeinden.
Es wird macvlan verwendet

Quelle: https://forum.openmediavault.org/index.php?thread/50758-pihole-and-unbound-in-docker/
Was gegen diese Lösung mit den macvlan spricht: https://blog.oddbit.com/post/2018-03-12-using-docker-macvlan-networks/

Netzwerk einrichtung MACVLAN

Erstelle unter „Networks“ ein neues Netzwerk:

  • Name: mypiholevlan
  • Driver: macvlan
  • Parent network: eth0 (den richtigen Adapter auswählen, mit dem das VLan verknüpft sein soll)
  • Subnet: „192.168.130.0/24“
  • Gateway: „192.168.130.1“ (Im Regelfall der Router)
  • IP range: „192.168.130.12/30 # 192.168.130.12 and 192.168.130.13“ (Kann frei bleiben, sofern man die IP-Adressen selbst und ohne DHCP verteilet.
    Alternativ reserviert man ein paar IP-Adressen, die von Docker verwendet werden dürfen und nicht per DHCP genutzt werden.)
  • Der pihole

# Pihole
#
# https://github.com/pi-hole/docker-pi-hole?tab=readme-ov-file
#
version: "3"

services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    hostname: pihole #Choose your hostname
    dns:
     - "192.168.130.13" #DNS1: Should be the address of your unbound system
     - "9.9.9.9"        #DNS2: Quad9 as an example, optional
    networks:
      mypiholevlan:    #the network name you specified in the first step
        ipv4_address: 192.168.130.12    #The IP address you want to assign to your pihole. Make sure this address is available to be used in your network
    # For DHCP it is recommended to remove these ports and instead add: network_mode: "host"
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      # - "67:67/udp" # Only required if you are using Pi-hole as your DHCP server
      - "80:80/tcp"
    # Volumes store your data between container upgrades
    volumes:
      - './etc-pihole:/etc/pihole'
      - './etc-dnsmasq.d:/etc/dnsmasq.d'
    environment:
      - TZ='Europe/Berlin'
      - WEBPASSWORD=${PIHOLE_WEBPASSWORD}
      - DHCP_ACTIVE=false
    labels:
      - com.centurylinklabs.watchtower.enable=false
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    restart: unless-stopped
    # Required if you are using Pi-hole as your DHCP server, else not needed
    # cap_add:
      # - NET_ADMIN

networks:
  mypiholevlan:  #network name
    external: true

Unbound-Container

version: "3"

services:
  unbound:
    container_name: unbound
    image: mvance/unbound:latest
    hostname: unbound
    networks:
      mypiholevlan: #the network name you specified in the first step
        ipv4_address: 192.168.130.13 #The IP address you want to assign to Unbound. Make sure this address is available to be used in your network
    ports:
      - "53:53/tcp"
      - "53:53/udp"
    #volumes:    #It's important to comment out these two lines if you don't want to use your own unbound configuration! An own configuration can be tricky as you have to provide several config files manually.
    #  - './etc-unbound:/opt/unbound/etc/unbound'
    restart: unless-stopped
networks:
  mypiholevlan:  #the network name you specified in the first step
    external: true

Raspi neu aufsetzten

Grundinstallation

Mit dem Raspberry Pi Imager das Raspberry Pi OS Lite (hier verwende ich die 64-bit-Version [Debian 12 – bookworm]) installieren.
Bei den erweiterten Einstellungen hostname festlegen, ssh mit public-key aktivieren sowie Spracheinstellungen festlegen…

  • Raspi booten, das dauert dann erstmal ein bisschen.
  • .bash_aliases anpassen
  • nano configurieren in .config/nano/nanorc
  • staticIP-Adresse mit den NetworkManager festlegen

Watchdog einrichten

In der /boot/firmeware/config.txt den Hardware-Watchdog aktivieren:

dtparam=watchdog

Installation des Watchdog

sudo apt update
sudo apt install watchdog

In der Datei /etc/watchdog.conf folgende Zeilen aktivieren

watchdog-device = /dev/watchdog
watchdog-timeout = 15
log-dir = /var/log/watchdog
max-load-1 = 24

Der Raspi hat wohl als maximales timeout 15 Sekunden!
Anschließend der Service aktivieren und starten

sudo systemctl enable watchdog
sudo systemctl start watchdog
sudo systemctl status watchdog

Unattended-Upgrades einrichten

Original hier: www.elektronik-kompendium.de/sites/raspberry-pi/2002101.htm

sudo apt-get install unattended-upgrades
# Aktivieren/Deaktivieren:
sudo dpkg-reconfigure -plow unattended-upgrades

# genaue Config:
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

Schreibzugriff auf SD-Karte reduzieren

siehe Artikel dort…