# PowerDNS R&D ## Zones CRUD - Add ```pdnsutil create-zone home.local``` - Delete ```pdnsutil delete-zone home.local``` - Update ```pdnsutil edit-zone home.local``` - this provides a file to edit, file holds the resource records, we can skip this option (as it requires an editor) and use resource records CRUD. - List All Zones ```pdnsutil list-all-zones``` - From Here We Can Create Logic To Check If Zone Exists - List Specific Zone(lists all records of the zone) ```pdnsutil list-zone home.local``` - As There are no direct way to check if resource exists we can use it to check. Otherwise duplicacy may arise. - Check All Zones If Any Error ```pdnsutil check-all-zones``` - Check Single Zone If Any Error ```pdnsutil check-zone home.local``` - After adding/updating any record we can check for error ## Records CRUD - Add ``` pdnsutil add-record home.local ea A 300 10.0.0.72``` - Delete ```pdnsutil delete-rrset home.local ea A``` - Update ```pdnsutil replace-rrset home.local ea A 3600 10.0.0.1``` ## List Structure ### List All ``` $ pdnsutil list-all-zones Jul 06 12:48:28 [bindbackend] Done parsing domains, 0 rejected, 0 new, 0 removed example.com abc.local ``` #### Structure ```go= type ListAll struct{ Remark Remark ZoneNames []string } type Remark struct{ Date string IsParsingDomainDone bool RejectedCount int NewCount int RemovedCount int .... } ``` ### List Single ``` $ pdnsutil list-zone abc.local Jul 06 13:13:06 [bindbackend] Done parsing domains, 0 rejected, 0 new, 0 removed $ORIGIN . abc.local 3600 IN SOA a.misconfigured.dns.server.invalid hostmaster.abc.local 0 10800 3600 604800 3600 www.abc.local 3600 IN A 10.0.0.71 ``` #### Structure ```go= type SingleZone struct{ Remark Remark Origin string Records []Record } type Record struct { // similiar exists in insfmt Name string Owner string TTL int ClassField // (IN) is the class field that represents the protocol family, which is almost always IN, for Internet class. Type string Data string } type Remark struct{ Date string IsParsingDomainDone bool RejectedCount int NewCount int RemovedCount int .... } ``` ## Golang Map For CRUD ### Zone ```go= // Need to think on how to sync with modifyas as we need // List,ListAll, Check And Check All var zoneCRUD = map[string]string{ "Create": "pdnsutil create-zone %v", "Delete": "pdnsutil delete-zone %v", "List": "pdnsutil list-zone %v", "ListAll": "pdnsutil list-all-zones", "Check": "pdnsutil check-zone %v", "CheckAll": "pdnsutil check-all-zones", } ``` ### ResourceRecords ```go= var resourceRecordCRUD = map[string]string{ // order zone, name, type , ttl, data "Create": "pdnsutil add-record %v %v %v %v %v", // order zone, name, type "Delete": "pdnsutil delete-rrset %v %v %v", // order zone, name, type , ttl, data "Update": "pdnsutil replace-rrset %v %v %v %v %v", } ``` ## Install-Instruction - Will Not Work Directly On Current Insexec - I have commented out codes locally To Make Installation Work, As there are changes on other packages - Sample Main Function : ```go= func main() { testInstallPowerDNS() } func testInstallPowerDNS() { pterm.EnableDebugMessages() errW := insapply.ApplyInstallFromJSON("assets/testdata/installinstructions/powerdns.json") errW.HandleError() } ``` ### Json : ```json= { "UpdateApt": { "IsUpdateApt": true, "IsUpdateAptGet": true, "IsAptUpgrade": true }, "SymbolicLinksApply": { }, "InstallMethods": { "InstallUsingOsPackages": { "PreScriptLinesWithType": { "ScriptLines": [ "ufw enable", "ufw app list", "systemctl stop systemd-resolved", "systemctl disable --now systemd-resolved", "rm -rf /etc/resolv.conf", "echo \"nameserver 8.8.8.8\" > /etc/resolv.conf" ] }, "IsAptGet": true, "PackageNames": [ "sqlite3", "pdns-server", "pdns-backend-$backend", "pdns-backend-sqlite3", "net-tools" ], "PostScriptLinesWithType": { "ScriptLines": [ "systemctl stop pdns", "mkdir -p /var/lib/powerdns", "sqlite3 /var/lib/powerdns/pdns.sqlite3 < /usr/share/doc/pdns-backend-sqlite3/schema.sqlite3.sql", "chown -R pdns:root /var/lib/powerdns", "chown -R pdns:root /etc/powerdns", "find /var/lib/powerdns -type d -print0 | xargs -0 chmod 0755", "find /etc/powerdns -type d -print0 | xargs -0 chmod 0755", "find /var/lib/powerdns -type f -print0 | xargs -0 chmod 0644", "find /etc/powerdns -type f -print0 | xargs -0 chmod 0644" ] } } } } ``` ### Output : ``` $ systemctl status pdns ● pdns.service - PowerDNS Authoritative Server Loaded: loaded (/lib/systemd/system/pdns.service; enabled; vendor preset: enabled) Active: inactive (dead) since Tue 2021-07-06 14:34:09 UTC; 22min ago Docs: man:pdns_server(1) man:pdns_control(1) https://doc.powerdns.com Process: 91768 ExecStart=/usr/sbin/pdns_server --guardian=no --daemon=no --disable-syslog --log-timestamp=no --write-pid=no (code=killed, > Main PID: 91768 (code=killed, signal=TERM) Jul 06 14:34:08 a pdns_server[91768]: PowerDNS comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute i>Jul 06 14:34:08 a pdns_server[91768]: Creating backend connection for TCP Jul 06 14:34:08 a pdns_server[91768]: [bindbackend] Parsing 0 domain(s), will report when done Jul 06 14:34:08 a pdns_server[91768]: [bindbackend] Done parsing domains, 0 rejected, 0 new, 0 removed Jul 06 14:34:08 a pdns_server[91768]: About to create 3 backend threads for UDP Jul 06 14:34:08 a systemd[1]: Started PowerDNS Authoritative Server. Jul 06 14:34:08 a pdns_server[91768]: Done launching threads, ready to distribute questions Jul 06 14:34:09 a systemd[1]: Stopping PowerDNS Authoritative Server... Jul 06 14:34:09 a systemd[1]: pdns.service: Succeeded. Jul 06 14:34:09 a systemd[1]: Stopped PowerDNS Authoritative Server. lines 1-19/19 (END) ``` ### Next Steps (After Installation) : 1. ```bash= cd /var/lib/powerdns && ls -la && \ cd /etc/powerdns && ls -la && \ echo "\n ---------------------------------- ps aux | grep pdns \n\n" && \ ps aux | grep pdns && \ echo "\n ---------------------------------- netstat -tpln | egrep '((Local|:53)|(Local|:5300))' \n\n" && \ netstat -tpln | egrep '((Local|:53)|(Local|:5300))' ``` 2. ```bash= vim /etc/powerdns/pdns.conf launch=gsqlite3 gsqlite3-database=/var/lib/powerdns/pdns.sqlite3 ``` 3. ```bash= systemctl enable pdns && \ systemctl restart pdns && \ ufw allow from 192.168.0.0/16 to any port 53 proto udp && \ systemctl status pdns ``` ### Output : ```bash= $ systemctl status pdns ● pdns.service - PowerDNS Authoritative Server Loaded: loaded (/lib/systemd/system/pdns.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2021-07-06 15:03:14 UTC; 16s ago Docs: man:pdns_server(1) man:pdns_control(1) https://doc.powerdns.com Main PID: 92380 (pdns_server) Tasks: 8 (limit: 4547) Memory: 42.5M CGroup: /system.slice/pdns.service └─92380 /usr/sbin/pdns_server --guardian=no --daemon=no --disable-syslog --log-timestamp=no --write-pid=no Jul 06 15:03:14 a pdns_server[92380]: TCP server bound to [::]:53 Jul 06 15:03:14 a pdns_server[92380]: PowerDNS Authoritative Server 4.4.1 (C) 2001-2020 PowerDNS.COM BV Jul 06 15:03:14 a pdns_server[92380]: Using 64-bits mode. Built using gcc 10.2.1 20210130. Jul 06 15:03:14 a pdns_server[92380]: PowerDNS comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute i>Jul 06 15:03:14 a pdns_server[92380]: Creating backend connection for TCP Jul 06 15:03:14 a pdns_server[92380]: [bindbackend] Parsing 0 domain(s), will report when done Jul 06 15:03:14 a pdns_server[92380]: [bindbackend] Done parsing domains, 0 rejected, 0 new, 0 removed Jul 06 15:03:14 a pdns_server[92380]: About to create 3 backend threads for UDP Jul 06 15:03:14 a systemd[1]: Started PowerDNS Authoritative Server. Jul 06 15:03:14 a pdns_server[92380]: Done launching threads, ready to distribute questions ``` ## Verify 1. ```pdns_server --no-config --daemon=no --local-port=5300 --launch=gsqlite3 --gsqlite3-database=/var/lib/powerdns/pdns.sqlite3``` 2. ```pdns_server --config-dir=/etc/powerdn``` 3. Run Followings ``` sudo -u pdns bash whoami pdnsutil create-zone example.com ns1.example.com && \ pdnsutil add-record example.com '' MX '25 mail.example.com' && \ pdnsutil add-record example.com. www A 192.0.2.1 && \ dig +short www.example.com @127.0.0.1 && \ dig +short example.com MX @127.0.0.1 && \ pdnsutil list-zone example.com ``` ### Links : - [Duplicacy](https://github.com/PowerDNS/pdns/issues/4727) - [pdnsutil](https://doc.powerdns.com/authoritative/manpages/pdnsutil.1.html#zone-manipulation-commands)