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
1 |
$ 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
|
Installation en cours, des fenêtres de dialogue apparaîtront pour personnaliser le serveur..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
[✓] Root user check <span style="color: #00ff00;"> .;;,. .ccccc:,. :cccclll:. ..,, :ccccclll. ;ooodc 'ccll:;ll .oooodc .;cll.;;looo:.</span> <span style="color: #ff0000;"> .. ','. .',,,,,,'. .',,,,,,,,,,. .',,,,,,,,,,,,.... ....''',,,,,,,'....... ......... .... ......... .......... .......... .......... .......... ......... .... ......... ........,,,,,,,'...... ....',,,,,,,,,,,,. .',,,,,,,,,'. .',,,,,,'. ..'''.</span> [<span style="color: #00ff00;">✓</span>] Update local cache of available packages [<span style="color: #00ff00;">✓</span>] Disk space check [<span style="color: #00ff00;">✓</span>] Checking apt-get for upgraded packages... up to date! [i] Installer Dependency checks... [<span style="color: #00ff00;">✓</span>] Checking for dhcpcd5 [<span style="color: #00ff00;">✓</span>] Checking for git [<span style="color: #00ff00;">✓</span>] Checking for iproute2 [<span style="color: #00ff00;">✓</span>] 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
1 2 3 4 5 6 7 8 9 |
-------------------------------------------------------------------------------- <span style="font-size: 8pt;"> [<span style="color: #00ff00;">✓</span>] <span style="color: #00ff00;">Supported OS detected</span> [i] SELinux not detected [i] Using upstream DNS: Cloudflare (1.1.1.1, 1.0.0.1) [i] Static IP already configured ... Syntax OK </span><span style="color: #00ff00;"><span style="font-size: 8pt;">Installation Complete!</span> </span> |
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
1 |
$ 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)
1 |
$ wget https://dl.eff.org/certbot-auto |
1 |
$ chmod +x certbot-auto |
1 |
$ sudo mv certbot-auto /usr/local/sbin |
1 |
$ 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
1 |
$ sudo cat /etc/letsencrypt/live/<strong>machine.domaine.tld</strong>/privkey.pem /etc/letsencrypt/live/<strong>machine.domaine.tld</strong>/cert.pem | sudo tee /etc/letsencrypt/live/<strong>machine.domaine.tld</strong>/combined.pem |
Ajouter la configuration ssl dans le fichier external.conf
1 |
$ sudo vim /etc/lighttpd/external.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$HTTP["host"] == "<strong>machine.domaine.tld</strong>" { # 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/<strong>machine.domaine.tld</strong>/combined.pem" ssl.ca-file = "/etc/letsencrypt/live/<strong>machine.domaine.tld</strong>/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
1 |
$ sudo vim /etc/lighttpd/lighttpd.conf |
1 2 3 4 5 6 7 8 9 10 11 |
server.modules = ( "mod_access", "mod_accesslog", "mod_auth", "mod_expire", "mod_compress", "mod_redirect", "mod_setenv", <strong> "mod_openssl",</strong> "mod_rewrite" ) |
Normalement on est OK, on peut tester son fichier de conf
1 |
$ sudo /usr/sbin/lighttpd -t -f /etc/lighttpd/lighttpd.conf |
1 |
Syntax OK |
Et redémarrer le service
1 |
$ 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
1 |
$ pihole status |
1 2 |
[<span style="color: #00ff00;">✓</span>] DNS service is running [<span style="color: #00ff00;">✓</span>] Pi-hole blocking is Enabled |
Mise a jour
1 |
$ pihole -up |
1 2 3 4 5 6 |
[i] Checking for updates... [i] Pi-hole Core: <span style="color: #00ff00;">up to date</span> [i] Web Interface: <span style="color: #00ff00;">up to date</span> [i] FTL: <span style="color: #00ff00;">up to date</span> [<span style="color: #00ff00;">✓</span>] Everything is up to date! |
Pour suivre en temps réel l’activité
1 |
$ pihole tail |
1 2 3 4 5 6 7 8 9 10 11 12 |
Oct 3 21:05:29: <span style="color: #999999;">reply all.huodonghylivecdn.sched.ovscdns.net is 87.245.210.91</span> Oct 3 21:05:29: query[A] pull-hls-f1-ab.tiktokcdn.com from 192.168.3.178 <span style="color: #999999;">Oct 3 21:05:29: forwarded pull-hls-f1-ab.tiktokcdn.com to 1.1.1.1</span> <span style="color: #000000;">Oct 3 21:05:30: query[A] www.google.com from 192.168.3.178</span> <span style="color: #999999;">Oct 3 21:05:30: forwarded www.google.com to 1.1.1.1</span> <span style="color: #999999;">Oct 3 21:05:30: reply www.google.com is 216.58.204.100</span> Oct 3 21:05:44: query[A] incoming.telemetry.mozilla.org from 192.168.3.247 <span style="color: #ff0000;">Oct 3 21:05:44: gravity blocked incoming.telemetry.mozilla.org is 0.0.0.0</span> Oct 3 21:05:44: query[AAAA] incoming.telemetry.mozilla.org from 192.168.3.247 <span style="color: #ff0000;">Oct 3 21:05:44: gravity blocked incoming.telemetry.mozilla.org is ::</span> Oct 3 21:05:47: query[A] incoming.telemetry.mozilla.org from 192.168.3.247 <span style="color: #ff0000;">Oct 3 21:05:47: gravity blocked incoming.telemetry.mozilla.org is 0.0.0.0</span> |
Blacklisté/whitlisté un nom de domaine
1 |
$ pihole -w <strong>nom.domaine.tld</strong> |
1 2 |
[i] Adding nom.domaine.tld to the whitelist... [<span style="color: #00ff00;">✓</span>] Reloading DNS lists |
1 |
$ pihole -b <strong>nom.domaine.tld</strong> |
1 2 |
[i] Adding nom.domaine.tld to the blacklist... [<span style="color: #00ff00;">✓</span>] Reloading DNS lists |
Avoir un état général de Pi-hole
1 |
$ pihole -c |
Mettre a jour les listes de blocages
1 |
$ pihole updateGravity |
Changer le mot de passe admin
1 |
$ pihole -a -p |
1 2 3 |
Enter New Password (Blank for no password): Confirm Password: [<span style="color: #00ff00;">✓</span>] New password set |
Toute les options
1 |
$ pihole |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
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é
1 |
$ 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
Pour fixer les adresses mac / ip dans le serveur dhcp cela se fait dans /etc/dnsmasq.d/04-pihole-static-dhcp.conf sous la forme
dhcp-host=00:00:00:00:00:00,192.168.3.201,pc1
dhcp-host=11:11:11:11:11:11,192.168.3.202,pc2
dhcp-host=22:22:22:22:22:22,192.168.3.203,pc3
…
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