First you must enable insecure updates on your Windows DNS server as follows:
- Click Start, point to Administrative Tools, and then click DNS.
- Under DNS, double-click the applicable DNS server, double-click Forward Lookup Zones
- Right-click the applicable zone.
- Click Properties.
- In the Dynamic updates box, click to allow insecure updates
- Repeat the above for the associated reverse lookup zone
- Click OK.
Next, you need to add some code to your Asterisk pre-start event handler to update the DNS entries:
#!/bin/bash
# Update DNS server with this IP 192.x.x.x address
HOST=pbx.mydomain.local
IP=$(ip addr | grep 192 | awk ‘{print $2}’ | cut -f 1 -d/)
TTL=600
SERVER1=192.168.0.2
SERVER2=192.168.1.2
#—————————————————————————-
NSU=/tmp/nsupdate.data
echo “server ${SERVER1}” > ${NSU}
echo “update delete $HOST A” >> ${NSU}
echo “update add $HOST ${TTL} A ${IP}” >> ${NSU}
echo “update delete $HOST PTR” >> ${NSU}
echo “update add $HOST ${TTL} PTR ${IP}” >> ${NSU}
echo “send” >> ${NSU}
logger “asterisk.start.pre updating DNS for host ${HOST} to IP ${IP} on server ${SERVER1}”
nsupdate -v ${NSU}
echo “server ${SERVER2}” > ${NSU}
echo “update delete $HOST A” >> ${NSU}
echo “update add $HOST ${TTL} A ${IP}” >> ${NSU}
echo “update delete $HOST PTR” >> ${NSU}
echo “update add $HOST ${TTL} PTR ${IP}” >> ${NSU}
echo “send” >> ${NSU}
logger “asterisk.start.pre updating DNS for host ${HOST} to IP ${IP} on server ${SERVER2}”
nsupdate -v ${NSU}
rm -f ${NSU}