Twilio Inbound Suddenly stops working

The funny thing causing confusion here is that there is really no such thing as an outgoing-only trunk in Asterisk. FreePBX breaks it down as “outgoing” and “incoming” but it is a bit misleading.

What has happened is that you have effectively defined two SIP trunks (“peers”) with the same host= information. One you have configured by DNS name and the other by IP address, and they are equivalent. When you configure trunks in FreePBX and then click Apply Changes, the SIP Peers are written out to config files and this is what Asterisk actually cares about.

In the config files the peers appear in a certain order. When a call comes in, lacking any other matching information, Asterisk works its way down from top to bottom in its list of peers to find one that matches the host/IP. It uses the first one it finds.

In your case, it found your “outgoing” trunk, and your outgoing trunk did not have insecure=port,invite set, so Asterisk sent a 401 challenge.

I believe the solution here is to review all your “outgoing” Twilio trunks. If they are all the same hosts/IPs as the ones you set up for incoming, do this:

  • Remove your incoming trunks
  • Add insecure=port,invite to the outgoing Twilio trunks, allowing them to receive calls from Twilio
  • properly set the context, or remove the context= line altogether and let FreePBX set the default

Use type=peer for this kind of setup.

1 Like