This is a good and straightforward solution with one catch. If you are using FreePBX’s NAT handling (most people do), then FreePBX needs to know about its external IP.
If failover is infrequent and not “flappy” then a simple script[1] can periodically check the external IP, check it against what FreePBX knows, and if different, update FreePBX and reload. Any outage time would be reduced to the amount of time between checks (you could put the script in crontab for every minute).
Another possible way to deal with this, if you have a smart enough router, is to use SIP ALG on the router and let it handle NAT fixing for you. The benefit of this is that it knows the WAN IP address all the time and should seamlessly fix your SIP traffic going to the internet without you having to do anything.
[1] sample script:
#!/bin/bash
CURR_EXT_IP=$( /usr/sbin/fwconsole kvstore --action get --key externip Sipsettings )
REAL_EXT_IP=\"$( curl -s http://whatismyip.akamai.com )\"
if ! [[ $REAL_EXT_IP =~ ^\"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\"$ ]] ; then
# don't do anything; got a bad response from the curl
exit
fi
MAILMSG="Current known IP is $CURR_EXT_IP\n"
MAILMSG+="New IP is $REAL_EXT_IP\n"
if [ $CURR_EXT_IP == $REAL_EXT_IP ] ; then
# echo "No change in IP"
exit
else
# echo "External IP changed"
MAILMSG+="Updating PBXact:\n"
MAILMSG+=$( /usr/sbin/fwconsole kvstore --action set --key externip --value $REAL_EXT_IP Sipsettings )
MAILMSG+="\n"
MAILMSG+=$( /usr/sbin/fwconsole r )
MAILMSG+="\n"
# do the following if you have PJSIP transport reload disabled - need to restart asterisk
MAILMSG+="Need to restart Asterisk for this change:\n"
MAILMSG+=$( /usr/sbin/asterisk -rx "core restart when convenient" )
MAILMSG+="\n"
# notify
echo -e "$MAILMSG" | mail -s "PBX IP address change" [email protected]
fi