🛠 Serveur de blocage de pub réseau avec Pi-hole
Objectives
Deploy a real network service on the Zero 2 W: Pi-hole, a DNS server that filters advertising and tracking domains for the entire household. The official prerequisites (512 MB of RAM, Raspberry Pi OS) match the Zero 2 W exactly — it is its ideal use case, with a power consumption of approximately 1.8 W during operation. You will learn: static IP, systemd service, and moderated SD card logging.
Hardware
- 1 Raspberry Pi Zero 2 W connected to the network (2.4 GHz Wi-Fi or gadget/USB depending on previous tutorials)
- Access to the router interface (to point DNS clients to the Zero 2 W's IP address)
- A stable 2 A power supply — the server runs 24/7 and the Zero series never reports undervoltage conditions
Complete Code
# IP statique recommandée (ex. via la box en bail réservé, ou :
sudo raspi-config nonint do_wifi_static_ip ... # ou /etc/dhcpcd.conf à la main)
# Installation officielle :
curl -sSL https://install.pi-hole.net | bash
# L'installateur demande : interface (wlan0), upstream DNS (celui de la box),
# interface d'admin (web), mot de passe du tableau de bord.
# Vérifications :
pihole status # DNS active
dig +short doubleclick.net @127.0.0.1 # doit répondre 0.0.0.0
pihole query ad.doubleclick.net # trace de résolution
# Pointer les clients : DHCP de la box -> DNS = IP de la Zero 2 W
# Tableau de bord : http://IP_DE_LA_ZERO2W/admin
Expected Verification
pihole status displays Status: Active; a test dig query on a blacklisted domain returns 0.0.0.0. After pointing a device to this DNS, the dashboard begins counting blocked requests in real time. CPU load remains very low: the quad-core A53 is more than sufficient for this role.
Common Errors
- DNS loop: setting the Zero 2 W itself as the upstream DNS — it will no longer resolve anything. Upstream = the router or 1.1.1.1.
- SD card corruption due to excessive logging: limit log retention (Settings > Daemon), or even move the database to RAM (lighttpd/dnsmasq have cache options) — 512 MB of RAM and a low-quality SD card are a fragile combination.
- Forgetting to expire DHCP leases: old clients keep the previous DNS and "Pi-hole doesn't work on this phone".
Other tutorials for this board
- Premier démarrage de la Zero 2 W sans écran (headless)
- Se connecter au Wi-Fi (et comprendre les limites 2,4 GHz / WPA2)
- Surveiller la température et la fréquence de la Zero 2 W
- GPIO en Python : LED et bouton avec gpiozero
- Le tour de passe-passe « clé USB Linux » : Ethernet sur USB (g_ether)
- Remettre une Zero 2 W en état de boot : usbboot et boot files
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash