Incoming call failures with Twilio

I’m running FreePBX 16 behind a firewall with Twilio as my provider. 10% of incoming calls are failing with a 401 Unauthorized in Twilio logs.

Often when people hit this issue and try again right away, they get through. Other times, they have to try a third time.

I know that over the years this has been an issue with Twilio that other people have raised, but I wonder if anybody has any modern tips for how to eliminate this issue. The last info I can find is from 2020 and I haven’t found any solution.

Thanks in advance!

It likely means you do not have all of their IPs listed in your Match field. The ones you have listed are matched to the trunk and allowed in, and the ones that are not listed are challenged for auth.

I swear I checked that, but I bet I accidentally found a successful Termination rather than Origination call via the same IP address as one of the failed origination IP addresses.

I just looked through two pages of logs and it appears that none of the calls from their Oregon gateway are getting through.

Now I just need to figure out if it is my network firewall or the Freepbx firewall.

Thanks!

Apparently I need a separate trunk for each data center they have? Not sure how I missed that!

No, you only need to list all of the IPs or IP ranges in the Match field on a single Twilio trunk.

e.g. if you are expecting calls from Virginia and Oregon, per IP Addresses for Elastic SIP Trunking Services | Twilio ,

then put in your Match field: (trunk - pjsip Settings - Advanced)

Interesting. The latest setup guide I could find tells me to use two different trunks with different SIP addresses: mycustom.pstn.ashburn.twilio.com and mycustom.pstn.umatilla.twilio.com.

Is there a generic one I should be using? Or can I just use the closest one to me for the single trunk?

We were talking about incoming calls and putting all the IPs in the Match field is the way to do that.

If you want to have failover trunks for outbound calling then yes you would have to make a trunk for each.

That was a limitation of chan_sip; you should be using chan_pjsip.

1 Like

Thanks all. I’ll watch the logs and see what happens. I’m pretty sure this will fix my problem.

1 Like

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