Pjsip with a dynamic IP address

I am not sure if anyone can help, I have been testing some pjsip trunks and extensions

I have two Freepbx’s (A) Running on 12.0.76.2 asterisk 13.5.0 and (B) Running on 13.0.30 asterisks 13.5.0

Both are running on dynamic IP address using no-ip dns.

The problem is when one of the connections gets anew IP address, let’s say Server (A) gets a new external IP Address.

On server (A) all pjsip end points (extensions and trunks) become unavailable, phones cannot register with the extension status becoming unknown and the trunks show as unavailable.

They will not come back until I restart the asterisk service (service asterisk restart) when all is well again.

At the same time server (B) will now show the trunk to server (A) as available again and allow outbound calls, however the “Match: xxx.xxx.xx.xxx/32 on the trunk does not update so no inbound calls are coming through.

Are there any settings I can apply to force the two trunks to update all their settings when an IP address is updated.

Both servers are running behind a router and using NAT with static port forwarding.

My chan_sip trunks update fine and recover in around five minutes of an IP address with the following settings:-

[general]
enable=yes ; enable creation of managed DNS lookups
; default is 'no’
refreshinterval=300 ; refresh managed DNS lookups every seconds
; default is 300 (5 minutes)

Applied in dnsmgr.comf

None of the chan_sip extensions are effected by an external IP address change.

Any help anyone can provide would be gratefully received.

I have managed to make some progress with this problem.

Having modified a script I found on the internet as follows (/scripts/ipchange.sh)


#!/bin/sh
# Script that restarts asterisk when the external IP address has changed

# 1. check if IP changed since last update
# 2. If not, die
# 3. if it has, restart asterisk.

# RUN IN FOLDER WHERE PERSISTENT DATA CAN BE STORED.
cd /scripts

echo $(wget http://ipecho.net/plain -O - -q ; echo | grep inet) > newip

NEWIP=$(cut -f2 -d’ ’ newip)
NEWIP=${NEWIP##addr:}
OLDIP=$(cut -f2 -d’ ’ oldip)
OLDIP=${OLDIP##addr:}

if [ ! “$NEWIP” == “$OLDIP” ] ; then
service asterisk restart
fi
rm oldip
mv newip oldip


and set it run every five minutes as a cron job the PBX can now recover from an IP change without any user intervention.

However I am still struggling to work out how to change the “Match: xxx.xxx.xx.xxx/32" section of the remote trunk to reflect the the new address.

Again, any assistance would be gratefully received.