Changing NAT IP on SIP Settings through script or api?

Hi all,

I have a FreePBX 12 implementation on a site with a main Fibre link and a backup DSL connection, each connection with it’s own public IP configured on a firewall that handles the multi-wan failover, the FreePBX box sitting behind the firewall using NAT.

Our SIP provider has also 2 trunks (one with each IP) and will send calls on the main one unless unavailable in which case it sends the calls on the other trunk, we can make outgoing calls using either trunk. on the FreePBX there’s only 1 trunk as the destination IP is always the same.

The main problem is that when a fail over happens, calls cannot be placed as the External IP (NAT) address configured in the SIP settings is still the main one. I can fire a script from the firewall when a failover happens but I am unsure of how could I change this IP in the freepbx configuration and reload from a script, maybe using SSH? or is there an API for this? I would love to hear what would you guys recommend, or maybe this setup is not the right way to approach having a backup internet connection?