Created
February 27, 2025 16:26
-
-
Save psitem/f84e9c5997ca86daa9c89976f710ebd3 to your computer and use it in GitHub Desktop.
Create PTRs from dnsmasq's -dhcp-script command. Very quick-n-dirty, Works on My Active Directory™ tested.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$dnsServer = '10.10.10.10' # Replace with a DNS server accepting insecure updates. | |
$dnsDomain = 'home.mydomain.com' # Replace with your domain name. | |
$dhcpCmd = $args[0] | |
$dhcpMac = $args[1] | |
$dhcpIp = $args[2] | |
if ( $args.count -eq 4 ) { | |
$dhcpHostname = $args[3] -replace '[^a-zA-Z0-9-]', '-' | |
} else { | |
$dhcpHostname = $dhcpMac -replace ':','-' | |
} | |
$ptr = ($dhcpIp -replace '^(\d+)\.(\d+)\.(\d+).(\d+)$','$4.$3.$2.$1') + '.in-addr.arpa.' | |
$nsupdateCmd = @" | |
server $($dnsServer) | |
update delete $($ptr) PTR | |
$(if ($dhcpCmd -ne 'del') {"update add $($ptr) 300 PTR $($dhcpHostname).$($dnsDomain)."} ) | |
send | |
quit | |
"@ | |
$nsupdateCmd | nsupdate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dnsmasq sends output like:
Where
cmd
can beadd
(lease added),old
(lease update), ordel
(lease removed). Hostname is optional, if provided by the client. See the dnsmasq man page for more information on what gets passed as environmental variables.Requires
nsupdate
, which is commonly installed by default on Linux distros.