Last active 2 weeks ago

Das ist die Zusammenfassung, für einen Hetzner VPS mit Adguard Home und Unbound

Revision 8cded6e82ccc13b31949319574054df8341a1eb7

walkthrough.md Raw

AdGuard Home + Wireguard + UDM pro

Nach einer Anleitung von TheMorpheus https://www.youtube.com/watch?v=0cBZR4wy3ec https://www.patreon.com/posts/157177525

Server config

  • CX 23
  • 2 VCPU
  • 4 GB RAM
  • Ubuntu 24.04

Walkthrough

apt update && apt install -y ufw
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp   comment "SSH"
ufw allow 80/tcp   comment "HTTP-01 ACME (Cert-Erneuerung)"
ufw allow 443/tcp  comment "DoH"
ufw --force enable
ufw status verbose
apt install -y unbound dns-root-data
nano /etc/unbound/unbound.conf.d/custom.conf
server:
  # Nur auf Loopback lauschen, auf einem nicht-Standard-Port (NICHT 5353 — das ist mDNS).
  interface: 127.0.0.1
  port: 5335
  do-ip4: yes
  do-ip6: no            # nur auf yes, wenn dein VPS funktionierendes IPv6 hat, dann echt geil, kann nochmal deutlich schneller sein
  do-udp: yes
  do-tcp: yes
  # Nur Anfragen von localhost akzeptieren
  access-control: 127.0.0.0/8 allow
  access-control: 0.0.0.0/0 refuse
  access-control: ::0/0 refuse
  hide-identity: yes
  hide-version: yes
  # Hardening
  harden-glue: yes
  harden-dnssec-stripped: yes
  harden-below-nxdomain: yes
  harden-referral-path: yes
  qname-minimisation: yes
  use-caps-for-id: no   # yes für 0x20-Randomisierung; bricht ein paar Sites
  # Der DNSSEC-Trust-Anchor wird vom Default-Snippet des Pakets gesetzt,
  # auto-trust-anchor-file hier NICHT erneut deklarieren.
  # Schutz gegen DNS-Rebinding / Antworten mit privaten Adressen.
  # Für eigene interne Zonen zusätzlich local-zone / private-domain konfigurieren.
  private-address: 10.0.0.0/8
  private-address: 172.16.0.0/12
  private-address: 192.168.0.0/16
  private-address: 169.254.0.0/16
  private-address: fd00::/8
  private-address: fe80::/10
  # Cache (auf VPS-RAM anpassen; das hier ist konservativ für ~1 GB)
  msg-cache-size: 64m
  rrset-cache-size: 128m
  msg-cache-slabs: 4
  rrset-cache-slabs: 4
  infra-cache-slabs: 4
  key-cache-slabs: 4
  # Performance
  prefetch: yes
  prefetch-key: yes
  num-threads: 2        # an deine vCPU-Anzahl anpassen
  so-rcvbuf: 1m
  unwanted-reply-threshold: 10000000
  edns-buffer-size: 1232  # vermeidet Fragmentierung auf den meisten Pfaden
remote-control:
  # Aktiviert "unbound-control" (für Stats und Live-Befehle, später nützlich)
  control-enable: yes
  control-interface: 127.0.0.1
unbound-control-setup
unbound-checkconf
systemctl restart unbound
systemctl enable unbound
systemctl status systemd-resolved --no-pager
resolvectl status 2>/dev/null | head -5
ss -tulpen | grep ':53'
mkdir -p /etc/systemd/resolved.conf.d
cat > /etc/systemd/resolved.conf.d/disable-stub.conf <<EOF
[Resolve]
DNSStubListener=no
EOF
ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
systemctl restart systemd-resolved
curl -s -S -L https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh | sh -s -- -v
ssh -i ~/.ssh/dns_hurler -L 3000:localhost:3000 root@128.140.58.16

Ab durch den Wizard, danach

nano /opt/AdGuardHome/AdGuardHome.yaml
http:
  adress:
    - 127.0.0.1:3000
apt install -y certbot
certbot certonly --standalone --non-interactive --agree-tos --email du@example.com -d dns.example.com

Datei Pfad hat nicht geklappt, deshalb in den AdGuard Settings den Inhalt aus den fullchain und privkey kopieren

/etc/letsencrypt/live/dns.example.com/fullchain.pem
/etc/letsencrypt/live/dns.example.com/privkey.pem

Weiter in den Settings

  • Upstream DNS servers: 127.0.0.1:5335 (das andere löschen, damit zeigt AdGuard auf lokales Unbound)
  • Boostrap DNS: Adguard möchte da was deshalb
1.1.1.1
9.9.9.9
  • Rest erstmal so lassen Encryptions Settings
  • Encryption anschalten
  • server name: dns.example.com
  • https port lassen
  • DNS-over-TLS port: 853 löschen
  • certificate mit fullchain.pem füllen
  • private key mit privkey.pem füllen
apt install -y caddy

nano /opt/AdGuardHome/AdGuardHome.yaml

tls
  port_https: 8443

systemctl restart AdGuardHome

nano /etc/caddy/Caddyfile

dns.example.com {
    @doh {
        path /dns-query*
        method GET POST
    }
    handle @doh {
        reverse_proxy 127.0.0.1:8443 {
            transport http {
                tls
                tls_server_name dns.example.com
            }
            header_up X-Real-IP {remote_host}
        }
    }
    handle {
        respond "Not found" 404
    }
}
systemctl disable --now certbot.timer
wget https://raw.githubusercontent.com/Angristan/wireguard-install/master/wireguard-install.sh
chmod +x wireguard-install.sh
./wireguard-install.sh

durch den wizard klicken, dabei port merken

ufw allow in on wg0
ufw allow 49777/udp
ufw reload
  • nano /etc/default/ufw
  • DEFAULT_FORWARD_POLICY="ACCEPT"
  • nano /root/wg0-client-udm.conf
  • credentials offen lassen und ui von der udm öffnen
ip route add 10.66.66.0/24 dev wgclt1
dig @10.66.66.1 google.com

UniFi Konsole Settings -> Routing policy -> new route

Name:        VPS WireGuard
Destination: 10.66.66.0/24
Interface:   wgclt1
Distance:    1