I have been running a php script via cron for many years (PIAF forum) to alert me when a trunk is not registered.
One of the trunks (from Voipfone in UK) occasionally fails and the only way to get it back is to disable the trunk for 2+ minutes and then enable it again.
I want to modify the script to disable the trunk, sleep for 130 seconds and then enable it again.
I would like to avoid hard-coding the exact IDs as these may change.
As far as I know I need to use “fwconsole trunks --disable x” to temporarily disable the trunk but for that I need to know the value of x for the trunk that has failed.
asterisk -rx “sip show registry” shows the Host which includes the name Voipfone but then I need a way to determine the trunk ID.
In short, I need to determine which Trunk ID has failed to register.
This is usually caused by a ‘poisoned’ NAT association in the router or firewall that is being kept alive by aggressive retries by Asterisk.
If you have a static IP address and Voipfone supports ‘IP authentication’, set that up and don’t use registration at all. That’s most robust and you can still use qualify to detect trunk outages.
Next, if your router/firewall has separate UDP timeouts for ‘unreplied’ and ‘assured’ states, set the unreplied timeout shorter than the retry interval and recovery should be automatic.
Otherwise, assuming a reasonably updated system (FreePBX 15, Asterisk 16), switch to pjsip trunks. Set all three Retry Intervals to e.g. 180 seconds.
If none of the above are applicable or don’t help, please provide some details: Router/firewall make/model? Does it have a public IP on WAN interface? If not, why (ISP supplied gateway, ISP does NAT, etc.)? FreePBX and Asterisk versions? Why do you have / how do you use multiple trunks with the same provider?
IMO you should implement a recovery script only if you understand what is wrong when registration stays lost and why changing router/firewall or Asterisk timing parameters can’t fix it.
Thank you for your prompt and detailed response. Your diagnosis of the problem is spot on.
I have spoken in the past to Voipfone and they did ‘blame’ Asterisk for the issue - too many retries.
(They did suggest using IP authentication but we have a backup line so did not want to go down that route).
I did look for some settings that would make Asterisk back-off from retries for two minutes but did not find any. So your suggestion to use pjsip with its extra options is the obvious thing to try. I have never used it for trunks, but will give it a go now.
I have created the pjsip trunk. I cannot find any up to date meaningful guidance in the wiki. I found a couple contradictory ones from some providers but it actually looked quite simple to set up.
The trunk is showing as registered. I have disabled the old sip trunk and tried an incoming call. It goes straight to voicemail at the trunk provider. So I am a bit stuck. Have I forgotten something?
In the Advanced section I changed some of the default numbers and set Contact User and From User to same as Username and From Server to Sip Server and left all else unchanged.
Listing the trunks gives the ID number and the Channel ID (name of the trunk).
“sip show registry” shows Host (domain/IP + port) and Username.
There is nothing in common between the two to allow me to obtain the trunk’s ID from the registry list. This leaves me with the only option of hard-coding the script to a specific Host entry - unless there is something else that can link the two.
Hopefully @Stewart1’s suggestion of using pjsip will work, in which case there is no need for the script.
Your NAT association may be timing out – try setting Expiration to e.g. 120 and retest. If it still fails:
If something appears in the Asterisk log for an attempted incoming call, post that.
If not, but something appears in sngrep on an attempt, post that.
If also nothing in sngrep, at the Asterisk command prompt, type pjsip set logger on
and wait for the next registration. Paste the section of the Asterisk log showing both a REGISTER request and the 200 OK response at pastebin.freepbx.org and post the link here.
Yet there is a one to one relation ship between trunks and sip show peers the absence of OK for the peer would show a problem and allow you to fwconsole trunks --disable=badone for 130 seconds
I did see an old post of yours making this suggestion and I tried it. I have changed a character in the password so it fails to register - registries shows No authentication.
Despite that ‘sip show peers’ shows Status as: OK (96 ms)
Does not make sense but I have tried several times.
Did you get the pjsip trunk working? If not, what have you found so far?
Alternatively, for the chan_sip trunk, have you tried changing Registration Timeout to 180 and Registration Attempts to 0 in Asterisk SIP Settings-> SIP Legacy Settings?
Last night I sent an email to Voipfone. They responded with a query - apparently not actually changed anything. However, trying it out again this morning - it is all working on pjsip!
That sounds like what I was looking for and assumed it would be an attribute of the trunk. I do have an other system still running an old version before pjsip. I will definitely try it there. Thank you.
Writing to confirm that your suggestion seems to have worked. I got a single warning email and then the trunk got registered without any manual intervention. Thanks again.
LesD thanks for your efforts and reporting this, I was going to request a trunk monitoring addon but found your post here.
same issues, forever!
Stewart1 thank you for your two awesome insides of the issue!
‘IP authentication’, trick which I can easily do, and firewall UDP state timeouts. Not sure how to shorten unreplied timeout on UFW.