Bind & DDNS & PowerShell

Den Key erstellt Ihr euch über SSH mit folgendem Befehl
Achtung: Domainname natürlich mit eurem ersetzen!

ddns-confgen -a hmac-sha512 -z Domainname

Beispiel: Named.conf

//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
	listen-on port 53 {
			any;
		};
	// listen-on-v6 port 53 { ::1; };
    // filter-aaaa-on-v4 yes;
	directory 	"/var/named";
	dump-file 	"/var/named/data/cache_dump.db";
	statistics-file "/var/named/data/named_stats.txt";
	memstatistics-file "/var/named/data/named_mem_stats.txt";
	secroots-file	"/var/named/data/named.secroots";
	recursing-file	"/var/named/data/named.recursing";
	allow-query {
		any;
		};
	allow-transfer {
		EDITED;
		};
	notify yes;
	also-notify {
		EDITED;
		};
	/* 
	 - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
	 - If you are building a RECURSIVE (caching) DNS server, you need to enable 
	   recursion. 
	 - If your recursive DNS server has a public IP address, you MUST enable access 
	   control to limit queries to your legitimate users. Failing to do so will
	   cause your server to become part of large scale DNS amplification 
	   attacks. Implementing BCP38 within your network would greatly
	   reduce such attack surface 
	*/
	recursion yes;

	dnssec-validation auto;

	managed-keys-directory "/var/named/dynamic";
	geoip-directory "/usr/share/GeoIP";

	pid-file "/run/named/named.pid";
	session-keyfile "/run/named/session.key";

	/* https://fedoraproject.org/wiki/Changes/CryptoPolicy */
	include "/etc/crypto-policies/back-ends/bind.config";
	forwarders {
		EDITED;
		8.8.8.8;
		8.8.4.4;
		};
	// dnssec-enable yes;
	// dnssec-enable yes;
};

logging {
	channel default_debug {
		file "/var/log/named.run";
		};
};

zone "." IN {
	type hint;
	file "named.ca";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

key rndc-key {
	algorithm hmac-sha256;
	secret "EDITED";
	};

key "ddns-key.dyndns.datateam.center" {
        algorithm hmac-sha512;
        secret "Euer generierter Key";
};

controls {
	inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { rndc-key; };
};

server EDITED {
};

zone "datateam.center" {
	type master;
	file "/var/named/datateam.center.hosts";
	also-notify {
		EDITED;
		};
	notify yes;
    update-policy {
          grant ddns-key.dyndns.datateam.center zonesub ANY;
    };
	allow-transfer {
		127.0.0.1;
		EDITED;
		};
};

Manches habe ich editiert und durch EDITED ersetzt – also aufpassen

Was eigentlich nur eingefügt wird ist folgendes:

key "ddns-key.dyndns.datateam.center" {
        algorithm hmac-sha512;
        secret "Euer generierter Key";
};

Unter der Zone kommt folgendes:    
    update-policy {
          grant ddns-key.dyndns.datateam.center zonesub ANY;
    };

Was genau eingegeben wird erhaltet Ihr wenn Ihr euren Key generiert.

Beispiel: Key Datei

key "ddns-key.dyndns.datateam.center" {
        algorithm hmac-sha512;
        secret "Euer generierter Key";
};

PowerShell Script

<#
Get full info:
$providerinfo = Invoke-RestMethod http://ipinfo.io/json
#>

Param (
    [String]$KeyPath = "C:\dyndns\dyndns.datateam.center.key",
    [String]$NSScriptPath = "c:\dyndns\nsupdate.txt",
    [String]$NSUpdatePath = "C:\dyndns"
)

begin {
    #Gather status of system IP Addresses, DNS Servers, and domains
$myip = (Invoke-WebRequest -uri "https://api.ipify.org/").Content
$servername = "ns1.datateam.center"
$dnszone = "datateam.center"
$hostname = "holodeck.$dnszone"

}

process {
                    $script = "update delete $hostname
update add $hostname. 60 A $myip

"
        }

end {
    $script | Out-File -FilePath $NSScriptPath -Encoding "ascii" -Force
    Start-Process -FilePath (Join-Path -Path $NSUpdatePath -ChildPath "nsupdate.exe") -ArgumentList "-d -k `"$KeyPath`" `"$NSScriptPath`"" -Wait -NoNewWindow -RedirectStandardError "c:\dyndns\nsstderr.log" -RedirectStandardOutput "c:\dyndns\nsstdout.log" -WorkingDirectory $NSUpdatePath | Out-Null
    
}

Hier habe ich auf einem Windows Rechner auf C: das Verzeichnis dyndns erstellt.

Darunter habe ich die DLL Dateien und nsupdate.exe aus der ZIP Datei vom Bind DNS Server kopiert.

Ich habe Bind auch in meinen Downloads hier auf diesem Server.

dyndns.datateam.center.key ist die Datei mit dem generierten Key. Ihr könnt sie so nennen wie Ihr wollt müsst halt dann nur die PowerShell Datei anpassen 🙂