Random incoming call 401 unauthorized errors with Twilio

Try setting “Allow SIP Guests” to yes on the “Asterisk SIP Settings” page and see if that works. Everybody else: Any problem running with that setting? If so, I’ll need re re-evaluate my setup for Twilio…

@cvsjmabbott I already have that enabled.

I believe I have resolved the issue with failed originating
calls. It appears that quite a few customers (using Asterisk + FreePBX
servers) were having the same exact issue whereby random (first or first few)
inbound calls were being rejected with a 401 unauthorized error.
Unfortunately, none of these customers’ were able to resolve the issue with the
exception of one customer: Twilio Inbound Suddenly stops working

The above customer noticed in the debug logs that the initial
originating call actually was connecting to an outbound Twilio trunk
instead of the inbound trunk; and failing (obviously) since no incoming
settings were configured. When the customer removed all Twilio outbound
trunks, he no longer received the originating call failed entries in the log
within the Twilio console. He then proceeded to make an inbound and
outbound single main Twilio trunk which took care of both incoming and outgoing
calls without failed inbound calls.

Since the above resolution was far from ideal, I researched why
Twilio’s originating calls would utilize an outbound trunk (initially).
The answer was that FreePBX configured trunk settings alphabetically by trunk
name and asterisk would read the configuration file from top to bottom.
Moreover, if there were duplicate host IPs in the trunk configurations,
asterisk (1.6 and later versions) would use the first trunk (from top to
bottom) with the duplicate host IP.

So as per the FreePBX Interconnect guide, I have 4 inbound (US
VA) trunks using IPs 54.172.60.0-3, 4 inbound (US OR) trunks using IPs
54.244.51.0-3, and 5 (1 master + 4 subaccount) outbound Twilio trunks using
FQDN termination sip uri. A few of the outbound trunks were
alphabetically ordered before the inbound trunks. I renamed all outbound
trunks, starting with a ‘z’ so that FreePBX would put the outbound Twilio
trunks at the end of the configuration file. That did the trick and
resolved the inbound ‘failed’ calls.

I just found this post and I am hoping if will solve a problem I’ve wrestled with for days now.

Honestly this sounds more like an Asterisk issue than a Twilio issue. Does anyone know if Twilio or FreePBX (Digium, etc) ever fixed this?