DNS & SSL Local - bind9 + mkcert
Vue d’ensemble
Section intitulée « Vue d’ensemble »Pas de HTTP, même en local. On habitue les devs à gérer des certificats dès le départ. Cette documentation couvre :
- bind9 : Serveur DNS local pour résoudre les domaines
*.local - mkcert : Génération de certificats SSL de développement
Pourquoi cette stack ?
Section intitulée « Pourquoi cette stack ? »| Besoin | Solution | Alternative |
|---|---|---|
| Résolution DNS wildcard | bind9 | Fichiers hosts (limité) |
| Certificats SSL locaux | mkcert | Let’s Encrypt (impossible en local) |
| HTTPS en dev | CA locale | Ignorer les warnings (mauvaise pratique) |
1. bind9 - Serveur DNS Local
Section intitulée « 1. bind9 - Serveur DNS Local »1.1 Architecture
Section intitulée « 1.1 Architecture »graph LR subgraph NETWORK["Réseau Local"] subgraph CLIENTS["Clients DNS"] WIN[Windows
DNS Client] WSLC[WSL
DNS Client] end subgraph VM["VM 192.168.56.10"] BIND9[bind9
DNS Server] ZONE["*.domaine.local"] TRAEFIK[Traefik
Reverse Proxy] CONTAINERS[Containers] end end WIN -->|"DNS :53"|BIND9 WSLC -->|"DNS :53"|BIND9 BIND9 --> ZONE ZONE -->|"192.168.56.10"|TRAEFIK TRAEFIK --> CONTAINERS style NETWORK fill:#1a1a2e,stroke:#16213e,color:#fff style CLIENTS fill:#0f3460,stroke:#16213e,color:#fff style VM fill:#533483,stroke:#16213e,color:#fff style BIND9 fill:#e94560,stroke:#16213e,color:#fff style TRAEFIK fill:#00c853,stroke:#16213e,color:#fff
1.2 Installation (Ubuntu/Debian)
Section intitulée « 1.2 Installation (Ubuntu/Debian) »# Installation de bind9sudo apt updatesudo apt install -y bind9 bind9utils bind9-doc
# Vérifier l'installationnamed -v# BIND 9.18.x1.3 Configuration de la zone
Section intitulée « 1.3 Configuration de la zone »Créer le répertoire des zones :
sudo mkdir -p /etc/bind/zonesZone file (/etc/bind/zones/db.domaine.local) :
$TTL 604800@ IN SOA ns1.domaine.local. admin.domaine.local. ( 2024120701 ; Serial (YYYYMMDDNN) 604800 ; Refresh (7 jours) 86400 ; Retry (1 jour) 2419200 ; Expire (28 jours) 604800 ) ; Negative Cache TTL (7 jours)
; Serveurs de noms@ IN NS ns1.domaine.local.
; Enregistrements A@ IN A 192.168.56.10ns1 IN A 192.168.56.10
; Wildcard - TOUS les sous-domaines pointent vers l'IP* IN A 192.168.56.10Note : Le wildcard
*permet de résoudre automatiquementapp.domaine.local,cv.domaine.local,api.domaine.local, etc. sans configuration supplémentaire.
Configuration named (/etc/bind/named.conf.local) :
zone "domaine.local" { type master; file "/etc/bind/zones/db.domaine.local";};1.4 Configuration des options
Section intitulée « 1.4 Configuration des options »Modifier /etc/bind/named.conf.options :
options { directory "/var/cache/bind";
// Écouter sur l'IP de la VM et localhost listen-on { 192.168.56.10; 127.0.0.1; }; listen-on-v6 { none; };
// Autoriser les requêtes depuis n'importe où allow-query { any; };
// Forwarders pour les domaines externes forwarders { 8.8.8.8; 8.8.4.4; };
// Sécurité dnssec-validation auto; recursion yes;};1.5 Validation et démarrage
Section intitulée « 1.5 Validation et démarrage »# Vérifier la configurationsudo named-checkconf# (pas de sortie = OK)
# Vérifier la zonesudo named-checkzone domaine.local /etc/bind/zones/db.domaine.local# zone domaine.local/IN: loaded serial 2024120701# OK
# Activer et démarrer le servicesudo systemctl enable bind9sudo systemctl restart bind9
# Vérifier le statutsudo systemctl status bind91.6 Tests DNS
Section intitulée « 1.6 Tests DNS »# Test local (dans la VM)dig @127.0.0.1 domaine.localdig @127.0.0.1 app.domaine.localdig @127.0.0.1 nimportequoi.domaine.local
# Tous doivent retourner 192.168.56.102. Configuration des clients DNS
Section intitulée « 2. Configuration des clients DNS »2.1 Windows
Section intitulée « 2.1 Windows »- Ouvrir Paramètres > Réseau et Internet > Modifier les options d’adaptateur
- Clic droit sur l’adaptateur réseau actif > Propriétés
- Sélectionner Protocole Internet version 4 (TCP/IPv4) > Propriétés
- Cocher Utiliser l’adresse de serveur DNS suivante :
| Champ | Valeur |
|---|---|
| DNS préféré | 192.168.56.10 |
| DNS auxiliaire | 8.8.8.8 |
Vérification :
nslookup app.domaine.local# Server: 192.168.56.10# Address: 192.168.56.10# Name: app.domaine.local# Address: 192.168.56.10Méthode temporaire :
sudo nano /etc/resolv.conf
# Contenu :nameserver 192.168.56.10nameserver 8.8.8.8Méthode persistante :
WSL régénère /etc/resolv.conf à chaque démarrage. Pour persister :
# Créer/éditer /etc/wsl.confsudo nano /etc/wsl.conf
# Contenu :[network]generateResolvConf = falsePuis redémarrer WSL :
# PowerShell Windowswsl --shutdownwslEt recréer /etc/resolv.conf :
sudo rm /etc/resolv.confsudo nano /etc/resolv.conf# nameserver 192.168.56.10# nameserver 8.8.8.82.3 Fichiers hosts (Fallback)
Section intitulée « 2.3 Fichiers hosts (Fallback) »Si vous ne souhaitez pas modifier la configuration DNS système :
Windows (C:\Windows\System32\drivers\etc\hosts) :
192.168.56.10 domaine.local192.168.56.10 app.domaine.local192.168.56.10 cv.domaine.local192.168.56.10 api.domaine.local192.168.56.10 dokploy.domaine.localLinux/WSL (/etc/hosts) :
192.168.56.10 domaine.local192.168.56.10 app.domaine.local192.168.56.10 cv.domaine.local192.168.56.10 api.domaine.local192.168.56.10 dokploy.domaine.localLimitation : Pas de wildcard possible avec les fichiers hosts. Chaque sous-domaine doit être ajouté manuellement.
3. mkcert - Certificats SSL Locaux
Section intitulée « 3. mkcert - Certificats SSL Locaux »3.1 Installation
Section intitulée « 3.1 Installation »WSL/Linux :
# Debian/Ubuntusudo apt install mkcert
# Ou via Homebrew (si installé)brew install mkcertmacOS :
brew install mkcertWindows :
# Via Chocolateychoco install mkcert
# Ou télécharger depuis GitHub# https://github.com/FiloSottile/mkcert/releases3.2 Initialisation de la CA locale
Section intitulée « 3.2 Initialisation de la CA locale »# Installer la CA racine dans le systèmemkcert -install
# Vérifier l'emplacement de la CAmkcert -CAROOT# /home/user/.local/share/mkcert (Linux)# C:\Users\User\AppData\Local\mkcert (Windows)Important : Cette commande installe un certificat racine dans le trust store du système. Les certificats générés seront automatiquement reconnus comme valides.
3.3 Génération de certificats
Section intitulée « 3.3 Génération de certificats »Certificat wildcard pour un domaine :
# Créer un dossier pour les certificatsmkdir -p certscd certs
# Générer le certificat wildcardmkcert -key-file key.pem -cert-file cert.pem domaine.local "*.domaine.local"Output attendu :
Created a new certificate valid for the following names: - "domaine.local" - "*.domaine.local"
The certificate is at "cert.pem" and the key at "key.pem"
It will expire on 7 March 2027Certificat pour plusieurs domaines :
mkcert -key-file multi.key -cert-file multi.crt \ localhost \ 127.0.0.1 \ ::1 \ domaine.local \ "*.domaine.local" \ dev.local \ "*.dev.local"3.4 Structure des fichiers
Section intitulée « 3.4 Structure des fichiers »certs/├── cert.pem # Certificat public├── key.pem # Clé privée└── rootCA.pem # CA racine (optionnel, pour partage)Copier la CA racine (pour la partager) :
cp "$(mkcert -CAROOT)/rootCA.pem" ./certs/3.5 Utilisation dans Traefik/Dokploy
Section intitulée « 3.5 Utilisation dans Traefik/Dokploy »Pour injecter le certificat dans Dokploy, voir : Dokploy - Configuration
Afficher le contenu pour copier/coller :
# Certificatcat certs/cert.pem
# Clé privéecat certs/key.pem4. Sécurité
Section intitulée « 4. Sécurité »4.1 Gitignore obligatoire
Section intitulée « 4.1 Gitignore obligatoire »# Certificats SSL - JAMAIS dans Gitcerts/*.pem*.key*.crt
# CA mkcertrootCA.pemrootCA-key.pem4.2 Bonnes pratiques
Section intitulée « 4.2 Bonnes pratiques »| Action | Risque si ignoré |
|---|---|
| Ne pas commiter les certificats | Fuite de clés privées |
| Regénérer régulièrement | Certificats expirés |
| Utiliser des wildcards | Moins de fichiers à gérer |
| Séparer CA locale de prod | Confusion entre environnements |
5. Troubleshooting
Section intitulée « 5. Troubleshooting »bind9 ne démarre pas
Section intitulée « bind9 ne démarre pas »# Vérifier les erreurs de configurationsudo named-checkconfsudo named-checkzone domaine.local /etc/bind/zones/db.domaine.local
# Voir les logssudo journalctl -u bind9 -f
# Erreurs courantes :# - Oubli du point final après les noms de domaine (ns1.domaine.local.)# - Permissions incorrectes sur les fichiers de zonesudo chown bind:bind /etc/bind/zones/*DNS ne répond pas depuis Windows/WSL
Section intitulée « DNS ne répond pas depuis Windows/WSL »# Vérifier que bind9 écoute sur la bonne IPsudo ss -tlnp | grep :53
# Vérifier le firewallsudo ufw status# Si actif, autoriser DNSsudo ufw allow 53/udpsudo ufw allow 53/tcp
# Tester depuis la VM elle-mêmedig @127.0.0.1 domaine.localCertificat non reconnu
Section intitulée « Certificat non reconnu »# Réinstaller la CAmkcert -uninstallmkcert -install
# Sur Windows, installer manuellement :# 1. Ouvrir mkcert -CAROOT# 2. Double-clic sur rootCA.pem# 3. Installer > Autorités de certification racine de confianceWSL ne résout pas les domaines
Section intitulée « WSL ne résout pas les domaines »# Vérifier /etc/resolv.confcat /etc/resolv.conf
# Si régénéré automatiquement, désactiversudo nano /etc/wsl.conf# [network]# generateResolvConf = false
# Puis redémarrer WSLwsl --shutdown6. Résumé des commandes
Section intitulée « 6. Résumé des commandes »| Action | Commande |
|---|---|
| bind9 : Status | sudo systemctl status bind9 |
| bind9 : Restart | sudo systemctl restart bind9 |
| bind9 : Check config | sudo named-checkconf |
| bind9 : Check zone | sudo named-checkzone domaine.local /etc/bind/zones/db.domaine.local |
| bind9 : Logs | sudo journalctl -u bind9 -f |
| DNS : Test | nslookup app.domaine.local 192.168.56.10 |
| mkcert : Install CA | mkcert -install |
| mkcert : Generate cert | mkcert -key-file key.pem -cert-file cert.pem domain.local "*.domain.local" |
| mkcert : CA location | mkcert -CAROOT |
7. Ressources
Section intitulée « 7. Ressources »Voir aussi :
Dernière mise à jour : 2025-12-07