PJSIp and Dynamic Public IP Address Changes


When the public ip changes, a script is used to update the “externerip” value in the kvstore database.
This update, correctly refected in the GUI sip settings, is followed by a “fwconsole reload”.

But the trunk using the PJSIP driver is not updated : SIP/SDP is still using previous IP.

My current workaround is a full “fwconsole restart”.

What’s the best way to manage public ip change with PJSIP trunk ?

That’s for your help,

You’re there. Asterisk won’t update the internal versions of the IP addresses without a restart.

You could use a hostname instead of an IP address.
Asterisk DNS manager resolves that FQDN periodically without the need for a restart.

Then you would need some dynamic DNS mechanism that updates the name to your correct external IP address.
You could use the hostname that comes with the commercial version of sysadmin, but the GUI won’t allow you to set it to update it more often than every 15 minutes.
Maybe this can be tweaked.

An IP address change will drop all external calls in progress anyhow, so an Asterisk restart is not a big deal.

First, if you have any control over the changes, try to reduce their frequency. For example, if caused by a DSL modem losing sync, try to get the noisy pair fixed. If not possible, set up your modem and router so a sync loss does not result in an address change.

If you are in a country where dynamic IP addresses are changed daily, rig a script that forces a change at 3 AM, so they don’t happen during business hours.

If you have a connection where frequent changes are unavoidable e.g. via an LTE router, consider putting your PBX in the cloud. If the office internet has just been hit with an IP change, it can send calls to mobile phones, have the caller wait in a queue, or take a message.

If you are absolutely stuck on a system with frequent IP changes, you need a script that quickly detects the change and updates Asterisk.
updateip.tgz (2.1 KB)

Dynamic DNS is avoided here; it involves a third party, is slow and also a potential point of failure. However, if you have external extensions, you can have it update a DDNS name as well.

To use this perl script, edit /etc/hosts, adding a line like public-ip
(replace with your actual public IPv4 address).
Use the name ‘public-ip’ (without the quotes) as External Address in Asterisk SIP settings.

Run the script in the background. Any actions taken are logged to updateip.log in the current directory.

Then, when the script detects a change, it will update /etc/hosts and either let dnsmgr find it, or restart Asterisk immediately. An address change is typically detected in 6 seconds (15 seconds max) and Asterisk is ready to go again within a minute.

If you use dnsmgr to handle the change, extensions do not lose connectivity, but your trunks will not reregister until the old registration expires. Alternatively, uncomment the line to restart Asterisk immediately, and set up your extensions with e.g. 60 second registration expiry.

Let me know of any bugs, or any improvements you make.

Hi All

Thanks for your reply: quite helpfull.

I updated with this temporary work-around:

(1) In dnsmgr.conf, manually set the enable value to yes and the refreshinterval value the same as the Asterisk SIP Settings -> ‘Dynamic Host Refresh’ value.
(2) Manually set the Asterisk SIP Settings -> External Address value the same as the Asterisk SIP Settings -> ‘Dynamic Host’ value and DO NOT CLICK the ‘Detect Network Settings’ button, followed by Submit and Apply Config.

My next step will be to use a local host name (hosts file) updated by script. So no dependancy anymore on the DNS update done by the router.

Let’s wait for the next IP change.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.