Projektarbeit-MYP/backend/docs/DNS_KONFIGURATION.md
2025-05-31 22:40:29 +02:00

392 lines
8.7 KiB
Markdown

# DNS-Konfiguration und Netzwerk-Optimierung
## Übersicht
Das MYP Kiosk-System implementiert eine intelligente DNS-Konfiguration mit automatischer Router-Erkennung, Fallback-Mechanismen und IPv6-Deaktivierung für optimale Netzwerk-Performance.
## Funktionen
### 🎯 Intelligente DNS-Prioritäten
1. **Router-DNS** (Höchste Priorität)
- Automatische Erkennung via DHCP, systemd-resolved, NetworkManager
- Route-basierte Fallback-Erkennung
- Funktionalitätstest vor Verwendung
2. **Google DNS** (Fallback 1)
- `8.8.8.8` und `8.8.4.4`
- Zuverlässig und schnell
3. **Cloudflare DNS** (Fallback 2)
- `1.1.1.1` und `1.0.0.1`
- Privacy-fokussiert
4. **Custom DNS** (Fallback 3)
- `163.116.178.73` und `163.116.178.74`
- Benutzerdefinierte Server
### 🚫 IPv6-Deaktivierung
- **Kernel-Level**: Systemweite IPv6-Deaktivierung
- **Boot-Level**: GRUB und cmdline.txt Parameter
- **Network-Level**: NetworkManager und DHCP-Konfiguration
### 🔄 Automatische Aktualisierung
- **Alle 30 Minuten**: DNS-Prioritäten neu bewerten
- **Alle 10 Minuten**: DNS-Gesundheitscheck
- **Wöchentlich**: Root Hints aktualisieren
## Architektur
```
┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
│ MYP Kiosk │───▶│ Unbound │───▶│ Router DNS │
│ Application │ │ Resolver │ │ (Priorität 1) │
└─────────────────┘ │ 127.0.0.1 │ └─────────────────┘
│ │ ┌─────────────────┐
│ │───▶│ Google DNS │
│ │ │ (Fallback 1) │
│ │ └─────────────────┘
│ │ ┌─────────────────┐
│ │───▶│ Cloudflare DNS │
│ │ │ (Fallback 2) │
│ │ └─────────────────┘
│ │ ┌─────────────────┐
│ │───▶│ Custom DNS │
│ │ │ (Fallback 3) │
└──────────────┘ └─────────────────┘
```
## Konfigurationsdateien
### Unbound Hauptkonfiguration
```bash
/etc/unbound/unbound.conf
```
**Wichtige Einstellungen:**
- IPv6 deaktiviert (`do-ip6: no`)
- Lokale Netzwerke erlaubt
- DNSSEC aktiviert
- Performance-optimiert (64MB Cache)
### DNS-Prioritätsskript
```bash
/usr/local/bin/configure-dns-priority
```
**Funktionen:**
- Router-DNS automatisch erkennen
- DNS-Server-Funktionalität testen
- Unbound-Konfiguration dynamisch aktualisieren
- Logging aller Änderungen
### Systemd-Services
```bash
/etc/systemd/system/dns-priority-config.service
```
**Abhängigkeiten:**
- Nach `network-online.target`
- Nach `unbound.service`
- Vor `myp-druckerverwaltung.service`
## Router-DNS-Erkennung
### Methode 1: DHCP Lease-Datei
```bash
grep "domain-name-servers" /var/lib/dhcp/dhclient.leases
```
### Methode 2: systemd-resolved
```bash
systemd-resolve --status | grep "DNS Servers"
```
### Methode 3: NetworkManager
```bash
nmcli dev show | grep "IP4.DNS"
```
### Methode 4: Route-basierte Erkennung
```bash
# Gateway als DNS-Server testen
gateway=$(ip route | grep default | awk '{print $3}')
nslookup google.com "$gateway"
```
## IPv6-Deaktivierung
### Kernel-Parameter
```bash
# /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
```
### Boot-Parameter
```bash
# /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 ..."
# /boot/cmdline.txt (Raspberry Pi)
... ipv6.disable=1
```
### NetworkManager
```bash
# /etc/NetworkManager/conf.d/dns-priority.conf
[connection]
ipv6.method=ignore
```
## DHCP-Schutz
### dhclient-Konfiguration
```bash
# /etc/dhcp/dhclient.conf
supersede domain-name-servers 127.0.0.1;
```
### resolv.conf-Schutz
```bash
# Schreibschutz aktivieren
chattr +i /etc/resolv.conf
```
## Monitoring und Wartung
### DNS-Status prüfen
```bash
myp-maintenance dns-status
```
**Zeigt an:**
- Unbound Service-Status
- Aktuelle DNS-Server
- Erkannte Router-DNS
- DNS-Statistiken
- Letzte Logs
### DNS-Test durchführen
```bash
myp-maintenance dns-test
```
**Testet:**
- google.com
- github.com
- debian.org
- cloudflare.com
### DNS-Konfiguration neu laden
```bash
myp-maintenance dns-reconfigure
```
### IPv6-Status prüfen
```bash
myp-maintenance ipv6-status
```
## Automatische Überwachung
### Cron-Jobs
```bash
# /etc/cron.d/dns-priority-update
# DNS-Priorität alle 30 Minuten aktualisieren
*/30 * * * * root /usr/local/bin/configure-dns-priority
# Root Hints wöchentlich aktualisieren
0 3 * * 0 root curl -s -o /var/lib/unbound/root.hints https://www.internic.net/domain/named.cache
# DNS-Gesundheitscheck alle 10 Minuten
*/10 * * * * root /usr/local/bin/dns-health-check
```
### Gesundheitscheck
```bash
/usr/local/bin/dns-health-check
```
**Prüft:**
- Unbound Service-Status
- DNS-Auflösung für Test-Domains
- Automatischer Neustart bei Fehlern
- Konfiguration neu laden bei kritischen Fehlern
## Log-Dateien
### DNS-Konfiguration
```bash
/var/log/dns-configuration.log
```
**Enthält:**
- Router-DNS-Erkennungen
- Konfigurationsänderungen
- DNS-Server-Tests
- Unbound-Neustarts
### DNS-Gesundheit
```bash
/var/log/dns-health.log
```
**Enthält:**
- Regelmäßige Gesundheitschecks
- DNS-Auflösungsfehler
- Service-Neustarts
- Kritische Fehler
### Unbound-Logs
```bash
/var/log/unbound.log
```
**Enthält:**
- Unbound Service-Logs
- DNS-Anfragen (optional)
- Fehler und Warnungen
## Troubleshooting
### DNS-Auflösung funktioniert nicht
1. **Service-Status prüfen:**
```bash
systemctl status unbound
```
2. **DNS-Test durchführen:**
```bash
nslookup google.com 127.0.0.1
```
3. **Konfiguration neu laden:**
```bash
/usr/local/bin/configure-dns-priority
```
### Router-DNS wird nicht erkannt
1. **DHCP-Lease prüfen:**
```bash
cat /var/lib/dhcp/dhclient.leases | grep domain-name-servers
```
2. **Gateway-Test:**
```bash
gateway=$(ip route | grep default | awk '{print $3}')
nslookup google.com "$gateway"
```
3. **Manuelle Konfiguration:**
```bash
# Router-DNS manuell in Unbound eintragen
echo "forward-addr: 192.168.1.1" >> /etc/unbound/unbound.conf
systemctl reload unbound
```
### IPv6 noch aktiv
1. **Kernel-Parameter prüfen:**
```bash
sysctl net.ipv6.conf.all.disable_ipv6
```
2. **Boot-Parameter prüfen:**
```bash
cat /proc/cmdline | grep ipv6.disable
```
3. **Neustart erforderlich:**
```bash
sudo reboot
```
### Unbound startet nicht
1. **Konfiguration testen:**
```bash
unbound-checkconf /etc/unbound/unbound.conf
```
2. **Berechtigungen prüfen:**
```bash
chown -R unbound:unbound /var/lib/unbound
```
3. **Port-Konflikt prüfen:**
```bash
netstat -tulpn | grep :53
```
## Performance-Optimierung
### Cache-Einstellungen
```bash
# Unbound Cache-Konfiguration
msg-cache-size: 64m
rrset-cache-size: 128m
cache-max-ttl: 86400
cache-min-ttl: 300
```
### Thread-Konfiguration
```bash
# Optimiert für Raspberry Pi
num-threads: 2
msg-cache-slabs: 4
rrset-cache-slabs: 4
```
### Netzwerk-Puffer
```bash
# Erhöhte Puffer für bessere Performance
so-rcvbuf: 4m
so-sndbuf: 4m
outgoing-range: 4096
```
## Sicherheit
### Zugriffskontrolle
```bash
# Nur lokale Netzwerke erlaubt
access-control: 127.0.0.0/8 allow
access-control: 192.168.0.0/16 allow
access-control: 10.0.0.0/8 allow
access-control: 172.16.0.0/12 allow
```
### DNSSEC
```bash
# Automatische Trust-Anchor-Verwaltung
auto-trust-anchor-file: "/var/lib/unbound/root.key"
```
### Private Adressen
```bash
# Verhindert DNS-Rebinding-Angriffe
private-address: 192.168.0.0/16
private-address: 172.16.0.0/12
private-address: 10.0.0.0/8
private-address: 127.0.0.0/8
```
---
**Status**: ✅ Produktionsreif
**Letzte Aktualisierung**: $(date +%Y-%m-%d)
**Version**: 1.0 (DNS-Optimiert)
## Referenzen
- [Unbound DNS Resolver](https://nlnetlabs.nl/projects/unbound/about/)
- [DNS-over-HTTPS RFC 8484](https://tools.ietf.org/html/rfc8484)
- [IPv6 Deaktivierung Best Practices](https://wiki.debian.org/DebianIPv6)
- [DNSSEC Validation](https://tools.ietf.org/html/rfc4033)