11{ config , lib , pkgs , ... } :
22
33{
4- # PowerDNS Recursor configuration
4+ # PowerDNS Recursor
55 # This acts as a local DNS cache and forwards queries to 172.16.50.1
6+ # sudo lsof -i :53
7+ # systemctl status pdns-recursor
68 services . pdns-recursor = {
79 enable = true ;
810
911 # Bind to localhost only for security
1012 dns . address = [ "::1" "127.0.0.1" ] ;
1113
1214 # Allow queries from localhost only
13- dns . allowFrom = [ "127.0.0.0/8" "::1/128 " ] ;
15+ dns . allowFrom = [ "::1/128" " 127.0.0.0/8" ] ;
1416
1517 # API configuration (for monitoring)
1618 api . address = "::1" ;
1719 api . port = 8082 ;
1820 api . allowFrom = [ "127.0.0.1" "::1" ] ;
1921
20- # Forward all zones to the upstream DNS server
21- forwardZones = {
22- "." = "172.16.50.1" ; # Forward all queries to upstream DNS
22+ # Configure DNS settings for proper DNSSEC validation
23+ settings = {
24+ # Enable DNSSEC validation
25+ dnssec = "validate" ;
26+ # Set query local address to enable IPv6 for outgoing queries
27+ query-local-address = "::" ;
28+ # Disable security polling to avoid external queries
29+ security-poll-suffix = "" ;
30+ # Configure forward zones for specific domains if needed
31+ # forward-zones = "example.com=172.16.50.1";
2332 } ;
2433
25- # DNSSEC validation
26- dnssecValidation = "validate" ;
27-
2834 # Export /etc/hosts entries
2935 exportHosts = true ;
3036
3137 # Serve RFC1918 reverse zones locally
3238 serveRFC1918 = true ;
3339 } ;
3440
41+ # Systemd service configuration for pdns-recursor with resource limits
42+ systemd . services . pdns-recursor = {
43+ serviceConfig = {
44+ # Resource limits - conservative for DNS service
45+ MemoryMax = "100M" ;
46+ MemoryHigh = "90M" ;
47+ CPUQuota = "15%" ;
48+ TasksMax = 50 ;
49+
50+ # Process limits
51+ LimitNPROC = 100 ;
52+
53+ # Nice priority
54+ Nice = 15 ;
55+ } ;
56+ } ;
57+
3558 # Firewall rules for pdns-recursor
3659 networking . firewall . allowedUDPPorts = [ 53 ] ;
3760 networking . firewall . allowedTCPPorts = [ 53 8082 ] ;
3861
3962 # Configure system to use local pdns-recursor
40- networking . nameservers = [ "::1" "127.0.0.1" ] ;
63+ #networking.nameservers = [ "::1" "127.0.0.1" ];
64+ networking . nameservers = [ "172.16.50.1" ] ;
4165 networking . resolvconf . useLocalResolver = true ;
66+
67+ environment . etc . "resolv.conf" . text = ''
68+ # pdns
69+ nameserver ::1
70+ nameserver 127.0.0.1
71+ # emergency cloudflare
72+ nameserver 2606:4700:4700::1111
73+ nameserver 1.1.1.1
74+ '' ;
4275}
0 commit comments