Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Poor man's ddns in AD environment for Linux

Somewhere, something is busted and my sssd is not keeping the dynamic dns entries for my statically assigned IP addresses in Microsoft DNS. So I threw together a cronjob for this script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#!/bin/sh
# Poor man's ddns
# Because AD keeps losing the dns record for my dhcp ip address
# reference: /posts/2018/04/15/wrapper-script-for-ansible-to-use-nsupdate-with-gsstsig/

IPADDR=$( ip -o a s | awk '$1 !~ /lo/ && $2 !~ /lo/' | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}\/[0-9]+' | awk -F'/' '{print $1}' )
RR=$( echo ${IPADDR} | tr '.' '\n' | tac | tr '\n' '.' )in-addr.arpa

$( which kinit-host )

nsupdate <<EOF
update add ${HOSTNAME}. 86400 A ${IPADDR}
send
gsstsig
update add ${RR} 300 IN PTR ${HOSTNAME}.
send
EOF

Obviously this depends on kinit- host (from bgscripts package)

Comments