Update DNS record to point to active PBX

Configuring synchronization, sensors, and optimizations
Post Reply
User avatar
CRM User
Posts: 136
Joined: Sun Nov 27, 2016 3:41 pm

Update DNS record to point to active PBX

Post by CRM User » Sun Jun 24, 2018 7:24 pm

I have 2 DNS servers (192.168.0.2 and 192.168.1.2) and I would like them to automatically resolve 'pbx.mydomain.com' to the IP of the active cluster member.

As well, I would like reverse (PTR) resolution to also reflect the active server.

And I use Windows Server 2016 for my DNS services.

How can I do this?
Account for questions transferred from CRM system
User avatar
Telium Support
Posts: 180
Joined: Sun Nov 27, 2016 3:27 pm

Re: Update DNS record to point to active PBX

Post by Telium Support » Mon Jun 25, 2018 5:46 am

First you must enable insecure updates on your Windows DNS server as follows:
  1. Click Start, point to Administrative Tools, and then click DNS.
  2. Under DNS, double-click the applicable DNS server, double-click Forward Lookup Zones
  3. Right-click the applicable zone.
  4. Click Properties.
  5. In the Dynamic updates box, click to allow insecure updates
  6. Repeat the above for the associated reverse lookup zone
  7. Click OK.
Next, you need to add some code to your Asterisk pre-start event handler to update the DNS entries:

Code: Select all

#!/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}
Post Reply