Installation, configuration, administration de Pi-hole + certificat ssl sur Rasberry Pi |
Article original Publié le : 04 octobre 2020 Mise a jour le : – |
Entre le big data et le rgpd on se fait éplucher ..
Au quotidien j’utilise Blokada et sur PC Ublock et d’autre module complémentaire.
Pi-hole est une bonne alternative pour se libérer de la publicité sur son réseau domestique.
Les listes par défaut bloque déjà pas mal d’ads/malware, la navigation c’est faite rapidement sur des sites bourrés de pubs, c’est assez efficace.
Pour aller plus loin il y a des listes alternatives que l’on peut importer pour bloquer d’autres types de domaines que l’ads (porn, phising, drogue …)
Pas de client a installer, des que le serveur est opérationnel, il faut simplement ajouter en DNS primaire sur chaque device, (téléphone, tablette, pc …) l’adresse IP de ce serveur pour que les requêtes transite par lui.
Un petit schéma fait rapidement sur draw.io
Pour le déploiement de ce service, j’utilise un Raspberry Pi 3 qui héberge déjà un service (serveur OpenVPN), cela n’altère en rien le fonctionnement
Sommaire
Installation de Pi-hole UP
L’installation se fait via le script
$ sudo curl -sSL https://install.pi-hole.net | bash
/!\ Si l’erreur ci dessous apparaît en début d’installation,
pi-hole curl: (60) SSL certificate problem: unable to get local issuer certificate Il faut installer le paquet ca-certificates $ sudo apt install ca-certificates |
Installation en cours, des fenêtres de dialogue apparaîtront pour personnaliser le serveur..
[✓] Root user check .;;,. .ccccc:,. :cccclll:. ..,, :ccccclll. ;ooodc 'ccll:;ll .oooodc .;cll.;;looo:. .. ','. .',,,,,,'. .',,,,,,,,,,. .',,,,,,,,,,,,.... ....''',,,,,,,'....... ......... .... ......... .......... .......... .......... .......... ......... .... ......... ........,,,,,,,'...... ....',,,,,,,,,,,,. .',,,,,,,,,'. .',,,,,,'. ..'''. [✓] Update local cache of available packages [✓] Disk space check [✓] Checking apt-get for upgraded packages... up to date! [i] Installer Dependency checks... [✓] Checking for dhcpcd5 [✓] Checking for git [✓] Checking for iproute2 [✓] Checking for whiptail [i] Checking for dnsutils (will be installed) [i] Processing apt-get install(s) for: dnsutils, please wait... --------------------------------------------------------------------------------
L’installation est assez sommaire, il faut définir sa carte réseau, son fournisseur dns, on laisse par défaut les 2 listes de blocages ads, et on installe un serveur lighttp auquel on rajoutera un certificat Let’s encrypt pour l’interface web.
|
|
|
|
|
|
|
|
|
|
|
|
L’installation prend quelques minutes
-------------------------------------------------------------------------------- [✓] Supported OS detected [i] SELinux not detected [i] Using upstream DNS: Cloudflare (1.1.1.1, 1.0.0.1) [i] Static IP already configured ... Syntax OK Installation Complete!
L’installation terminé, il génère un mot de passe aléatoire que l’on peut changer facilement en cli avec la commande ci dessous
$ pihole -a -p
Génération du certificat UP
Récupération du script Cerbot et génération du certificat (se référer a cette doc si besoin)
$ wget https://dl.eff.org/certbot-auto
$ chmod +x certbot-auto
$ sudo mv certbot-auto /usr/local/sbin
$ sudo certbot-auto certonly
Une fois le certificat généré, concaténer la private key et le certificat pour en faire un fichier combined.pem
$ sudo cat /etc/letsencrypt/live/machine.domaine.tld/privkey.pem /etc/letsencrypt/live/machine.domaine.tld/cert.pem | sudo tee /etc/letsencrypt/live/machine.domaine.tld/combined.pem
Ajouter la configuration ssl dans le fichier external.conf
$ sudo vim /etc/lighttpd/external.conf
$HTTP["host"] == "machine.domaine.tld" { # Ensure the Pi-hole Block Page knows that this is not a blocked domain setenv.add-environment = ("fqdn" => "true") # Enable the SSL engine with a LE cert, only for this specific host $SERVER["socket"] == ":443" { ssl.engine = "enable" ssl.pemfile = "/etc/letsencrypt/live/machine.domaine.tld/combined.pem" ssl.ca-file = "/etc/letsencrypt/live/machine.domaine.tld/fullchain.pem" ssl.honor-cipher-order = "enahttps://discourse.pi-hole.net/t/enabling-https-for-your-pi-hole-web-interface/5771ble" ssl.cipher-list = "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH" ssl.use-sslv2 = "disable" ssl.use-sslv3 = "disable" } # Redirect HTTP to HTTPS $HTTP["scheme"] == "http" { $HTTP["host"] =~ ".*" { url.redirect = (".*" => "https://%0$0") } } }
Sans oublier d’ajouter le module mod_openssl dans le fichier lighttpd.conf
$ sudo vim /etc/lighttpd/lighttpd.conf
server.modules = ( "mod_access", "mod_accesslog", "mod_auth", "mod_expire", "mod_compress", "mod_redirect", "mod_setenv", "mod_openssl", "mod_rewrite" )
Normalement on est OK, on peut tester son fichier de conf
$ sudo /usr/sbin/lighttpd -t -f /etc/lighttpd/lighttpd.conf
Syntax OK
Et redémarrer le service
$ sudo systemctl restart lighttpd
Mise en route UP
Le serveur est opérationnel en https, on peut se connecter a l’interface web
Voici un screenshot après quelques heures d’utilisation sur quelques appareils
Administration UP
En cli
Vérifier le bon fonctionnement
$ pihole status
[✓] DNS service is running [✓] Pi-hole blocking is Enabled
Mise a jour
$ pihole -up
[i] Checking for updates... [i] Pi-hole Core: up to date [i] Web Interface: up to date [i] FTL: up to date [✓] Everything is up to date!
Pour suivre en temps réel l’activité
$ pihole tail
Oct 3 21:05:29: reply all.huodonghylivecdn.sched.ovscdns.net is 87.245.210.91 Oct 3 21:05:29: query[A] pull-hls-f1-ab.tiktokcdn.com from 192.168.3.178 Oct 3 21:05:29: forwarded pull-hls-f1-ab.tiktokcdn.com to 1.1.1.1 Oct 3 21:05:30: query[A] www.google.com from 192.168.3.178 Oct 3 21:05:30: forwarded www.google.com to 1.1.1.1 Oct 3 21:05:30: reply www.google.com is 216.58.204.100 Oct 3 21:05:44: query[A] incoming.telemetry.mozilla.org from 192.168.3.247 Oct 3 21:05:44: gravity blocked incoming.telemetry.mozilla.org is 0.0.0.0 Oct 3 21:05:44: query[AAAA] incoming.telemetry.mozilla.org from 192.168.3.247 Oct 3 21:05:44: gravity blocked incoming.telemetry.mozilla.org is :: Oct 3 21:05:47: query[A] incoming.telemetry.mozilla.org from 192.168.3.247 Oct 3 21:05:47: gravity blocked incoming.telemetry.mozilla.org is 0.0.0.0
Blacklisté/whitlisté un nom de domaine
$ pihole -w nom.domaine.tld
[i] Adding nom.domaine.tld to the whitelist...
[✓] Reloading DNS lists
$ pihole -b nom.domaine.tld
[i] Adding nom.domaine.tld to the blacklist...
[✓] Reloading DNS lists
Avoir un état général de Pi-hole
$ pihole -c
Mettre a jour les listes de blocages
$ pihole updateGravity
Changer le mot de passe admin
$ pihole -a -p
Enter New Password (Blank for no password):
Confirm Password:
[✓] New password set
Toute les options
$ pihole
Usage: pihole [options] Example: 'pihole -w -h' Add '-h' after specific commands for more information on usage Whitelist/Blacklist Options: -w, whitelist Whitelist domain(s) -b, blacklist Blacklist domain(s) --regex, regex Regex blacklist domains(s) --white-regex Regex whitelist domains(s) --wild, wildcard Wildcard blacklist domain(s) --white-wild Wildcard whitelist domain(s) Add '-h' for more info on whitelist/blacklist usage Debugging Options: -d, debug Start a debugging session Add '-a' to enable automated debugging -f, flush Flush the Pi-hole log -r, reconfigure Reconfigure or Repair Pi-hole subsystems -t, tail View the live output of the Pi-hole log Options: -a, admin Web interface options Add '-h' for more info on Web Interface usage -c, chronometer Calculates stats and displays to an LCD Add '-h' for more info on chronometer usage -g, updateGravity Update the list of ad-serving domains -h, --help, help Show this help dialog -l, logging Specify whether the Pi-hole log should be used Add '-h' for more info on logging usage -q, query Query the adlists for a specified domain Add '-h' for more info on query usage -up, updatePihole Update Pi-hole subsystems Add '--check-only' to exit script before update is performed. -v, version Show installed versions of Pi-hole, Web Interface & FTL Add '-h' for more info on version usage uninstall Uninstall Pi-hole from your system status Display the running status of Pi-hole subsystems enable Enable Pi-hole subsystems disable Disable Pi-hole subsystems Add '-h' for more info on disable usage restartdns Full restart Pi-hole subsystems Add 'reload' to update the lists and flush the cache without restarting the DNS server Add 'reload-lists' to only update the lists WITHOUT flushing the cache or restarting the DNS server checkout Switch Pi-hole subsystems to a different GitHub branch Add '-h' for more info on checkout usage arpflush Flush information stored in Pi-hole's network tables
Depuis l’interface web
Dans l’onglet Tools/network on peut lister les machines utilisant le dns de pi-hole et avoir quelques infos
Depuis Settings/DNS on retrouve le(s) dns utilisé(s) par pi-hole
Toujours dans l’onglet Settings et DHCP, il faut configurer son serveur dhcp et désactiver celui de son routeur afin que les devices se connecte directement au Pi-hole. (Je n’utilise pas de serveur dhcp)
L’ajout de nouvelle règle de blocage dans l’onglet Groupe Management/Adlist
Il ‘y a juste a taper “liste pi-hole” et on trouve rapidement de quoi personnalisé son Pi-hole
Ne pas oublier de faire un update, je suis passé de 83811 a 324482 unique domains bloqué
$ pihole updateGravity
Il y a également une application Android qui permet d’accéder au contenu de l’interface web; il faut juste récupérer un token depuis l’onglet Settings/Api web interface et de renseigné ce token sur le profil de l’appli
Quelques liens
https://discourse.pi-hole.net/t/enabling-https-for-your-pi-hole-web-interface/5771
https://docs.pi-hole.net/core/pihole-command/
https://docs.pi-hole.net/main/prerequisites/
Édit: Un p’tit article intéressant sur la collecte des donnees
https://www.pixeldetracking.com/fr/le-bon-coin-donnees-personnelles-rgpd