Technitium
Technitium provides a convenient DNS server in a package with a nice web UI with DoT & DoH support out of the box, it can act not only as a caching recursive resolver, but as an authoritative server with zone management. Use the docker compose file and follow the instructions:
Docker
In this deployment, created a ./tls and ./config folder in the same directory as the compose yaml in which to store the PKCS12 export of the LE cert and to make configuration data easy to back up.
version: "3"
services:
dns-server:
container_name: technitium
hostname: dns-server
image: technitium/dns-server:latest
# Use "host" network mode for DHCP deployments
# network_mode: "host"
ports:
- "5380:5380/tcp" #DNS http web console
- "53443:53443/tcp" #DNS https web console
- "53:53/udp" #DNS service
- "53:53/tcp" #DNS service
# - "67:67/udp" #DHCP service
- "853:853/tcp" #DNS-over-TLS service
# - "443:443/tcp" #DNS-over-HTTPS service
# - "80:80/tcp" #DNS-over-HTTPS service certbot certificate renewal
- "8053:8053/tcp" #DNS-over-HTTPS using reverse proxy
environment:
- DNS_SERVER_DOMAIN=dns.zcyph.cc #The primary domain name used by this DNS Server to identify itself.
# - DNS_SERVER_ADMIN_PASSWORD=password #DNS web console admin user password.
# - DNS_SERVER_ADMIN_PASSWORD_FILE=password.txt #The path to a file that contains a plain text password for the DNS web console admin user.
# - DNS_SERVER_PREFER_IPV6=false #DNS Server will use IPv6 for querying whenever possible with this option enabled.
# - DNS_SERVER_OPTIONAL_PROTOCOL_DNS_OVER_HTTP=false #Enables DNS server optional protocol DNS-over-HTTP on TCP port 8053 to be used with a TLS terminating reverse proxy like nginx.
# - DNS_SERVER_RECURSION=AllowOnlyForPrivateNetworks #Recursion options: Allow, Deny, AllowOnlyForPrivateNetworks, UseSpecifiedNetworks.
# - DNS_SERVER_RECURSION_DENIED_NETWORKS=1.1.1.0/24 #Comma separated list of IP addresses or network addresses to deny recursion. Valid only for `UseSpecifiedNetworks` recursion option.
# - DNS_SERVER_RECURSION_ALLOWED_NETWORKS=127.0.0.1, 192.168.1.0/24 #Comma separated list of IP addresses or network addresses to allow recursion. Valid only for `UseSpecifiedNetworks` recursion option.
# - DNS_SERVER_ENABLE_BLOCKING=false #Sets the DNS server to block domain names using Blocked Zone and Block List Zone.
# - DNS_SERVER_ALLOW_TXT_BLOCKING_REPORT=false #Specifies if the DNS Server should respond with TXT records containing a blocked domain report for TXT type requests.
# - DNS_SERVER_BLOCK_LIST_URLS= #A comma separated list of block list URLs.
# - DNS_SERVER_FORWARDERS=1.1.1.1, 8.8.8.8 #Comma separated list of forwarder addresses.
# - DNS_SERVER_FORWARDER_PROTOCOL=Tcp #Forwarder protocol options: Udp, Tcp, Tls, Https, HttpsJson.
# - DNS_SERVER_LOG_USING_LOCAL_TIME=true #Enable this option to use local time instead of UTC for logging.
volumes:
- ./config:/etc/dns/config
- ./tls:/tls
restart: unless-stopped
sysctls:
- net.ipv4.ip_local_port_range=1024 65000
volumes:
config:
Nginx
This deployment uses a native nginx with the following conf:
server {
index index.html index.htm;
server_name dns.zcyph.cc;
location / {
proxy_pass http://127.0.0.1:8053/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
}
listen [::]:443 ssl;
listen 443 ssl http2;
ssl_certificate /etc/letsencrypt/live/dns.zcyph.cc/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/dns.zcyph.cc/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = dns.zcyph.cc) {
return 301 https://$host$request_uri;
}
listen 80;
listen [::]:80;
server_name dns.zcyph.cc;
return 404; # managed by Certbot
}
Certbot
Start with the 80 portion then run sudo certbot --nginx -d dns.zcyph.cc and it'll add the rest then restart nginx.
Be sure to do docker compose pull before turning off the existing DNS on the machine.
Systemd-resolved
Then turn off systemd-resolved:
sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved
Back up existing resolv.conf and edit current one:
sudo cp /etc/resolv.conf /etc/resolvconf.bak
sudo rm /etc/resolv.conf
sudo echo "nameserver 127.0.0.1" > /etc/resolv.conf
If the echo command doesn't work just use nano.
If /etc/NetworkManager/NetworkManager.conf exists, put this in it:
[main]
dns=default
PKCS12
Now create a script to export the LE cert to PKCS12 format in /etc/letsencrypt/renewal-hooks/post/pkcs12convert.sh:
#!/bin/sh
openssl pkcs12 -export -out /home/md/docker/technitium/tls/cert.pfx -inkey /etc/letsencrypt/live/dns.zcyph.cc/privkey.pem -in /etc/letsencrypt/live/dns.zcyph.cc/cert.pem -certfile /etc/letsencrypt/live/dns.zcyph.cc/chain.pem -passout pass:wKKXktLZKsz9Pqz9RsEc2Ptk
echo "pkcs#12 generated!"
Make it executable: sudo chmod +x /etc/letsencrypt/renewal-hooks/post/pkcs12convert.sh
Run it to export the cert: sudo /etc/letsencrypt/renewal-hooks/post/pkcs12convert.sh
Verify that /home/md/docker/technitium/tls/cert.pfx was created.
PKCS12 & Traefik
ns1.zcyph.cc sits alongside AnonAddy with Traefik, instead of NGINX. Traefik will automatically renew certs, but they need to be exported and certed into PKCS12 for use with Technitium's web UI on 53443.
First, to export the cert from Traefik, use traefik-cert-dumper:
traefik-certs-dumper --version v2 file ./acme.json --domain-subdir
Then export the PKCS12 and move it into Technitium:
openssl pkcs12 -export -out /home/md/docker/technitium/tls/cert.pfx -inkey /home/md/docker/anonaddy/dump/ns1.zcyph.cc/privatekey.key -in /home/md/docker/anonaddy/dump/ns1.zcyph.cc/certificate.crt -passout pass:wKKXktLZKsz9Pqz9RsEc2Ptk
Configuration
Make sure 5380 is open then log in to web UI at 154.12.241.58:5380. Go to Settings - Web Service - enable HTTPS and redirect to 53443 and specify the cert path /tls/cert.pfx along with the pass. Enable Optional Protocols - DNS-over-HTTP and DNS-over-TLS and add the same cert path and creds. Go to recursion and allow recursion.
Users can use dns.zcyph.cc for DNS-over-TLS (may or may not need to specify dns.zcyph.cc:853, depends on client)
And https://dns.zcyph.cc/dns-query for DNS-over-HTTPS
Updates
To update Technitium do docker compose pull && docker compose down && docker compose up -d
If name resolution fails, you may need to temporarily comment out nameserver 127.0.0.1 and uncomment nameserver 127.0.0.53 from /etc/resolv.conf then sudo systemctl enable systemd-resolved to pull the changes while the DNS server is down and then reverse the changes and restart it again.
Backup
Have installed CLI version of Send with: snap install ffsend.
If configuration volume wasn't already mounted, it can be copied from /var/lib/docker/volumes/technitium_config/_data/.
Export to send instance with: ffsend upload -h https://send.zcyph.cc fileOrFolderPath.
Dynamic DNS with ddclient
To get ddclient to update records in Technitium, first create a TSIG key in Technitium at Settings > TSIG > Add. Name the key, leave Shared Secret blank, use HMAC-SHA256 for algorithm and then Save Settings. Take note of the key name and the generated Shared Secret.
Go to the zone you want updated and then Options > Dynamic Updates (RFC 2136) > Security Policy > Add > TSIG Key Name - ddclient > Domain Name > .domain.tld > Allowed Record Types > A, CNAME, etc > Save*.
In /etc/ddclient, create a new file called technitium.key:
key ddclient {
algorithm "HMAC-SHA256";
secret "paste the TSIG key / Shared Secret here";
};
The key name in technitium.key has to match the Key Name in Technitium. Then make sure your ddclient.conf looks something like this:
# Configuration file for ddclient
#
# /etc/ddclient.conf
daemon=600
syslog=yes
ssl=yes
use=web
web=checkip.dyndns.org
pid=/run/ddclient.pid
protocol=nsupdate
server=ns1.yourDNSserver.tld
password=/etc/ddclient/technitium.key
zone=domain.tld
subdomain.domain.tld
ttl=5
Clear ddclient cache and restart it:
sudo rm /var/cache/ddclient/ddclient.cache && sudo systemctl restart ddclient
Confirm results with sudo systemctl status ddclient:
Feb 19 10:26:25 server systemd[1]: Starting Dynamic DNS Update Client...
Feb 19 10:26:25 server systemd[1]: Started Dynamic DNS Update Client.
Feb 19 10:26:26 server ddclient[1036962]: SUCCESS: updating subdomain.domain.tld: 1: IP address set to 1.2.3.4
ACME-DNS
RFC 2136 is used here for Traefik to perform DNS challenges and add/change DNS records in Technitium. First, make sure a TSIG keypair is created in Technitium and the zone options allows that key to make the desired changes.
Add TSIG key:
Settings > TSIG > Add - HMAC-SHA256
Then go to the domain/zone:
Options > Dynamic Updates (RFC 2136) > Security Policy > Add > key
create one record for domain.tld and one for *.domain.tld with the needed record types.
Then make sure appropriate Traefik settings are matching.