Setting up a Twilio SIP trunk on FreePBX


I tried to set up a Twilio SIP trunk on my FreePBX. I have some issues with placing calls.

Once I call any number from my Zoiper which is registered with the FreePBX, it shows that it is dialing. I hear ringing tone after one minute. But it never rings the recipient’s phone.

Here is my VOIP architecture:
Server operating system: CentOS 7 hosted on AWS EC2 instance
FreePBX 13.0.169
Asterisk 13.10.0
SIP Phone: Zoiper 3.9

Here is my FreePBX configuration:

Trunk Settings:

Trunk Name: Twilio_SIP_Trunk
Hide CallerID: No
Outbound CallerID: Not set
CID Options: Allow Any CID
Maximum Channels: Not set
Asterisk Trunk Dial Options: System
Continue if Busy: No
Disable Trunk: No
Dial Number Manipulation Rules: Not set

SIP Setting - Outgoining
Trunk Name: TwilioOut
PEER Details

SIP Setting - Incoming
USER Context : TwilioIn
USER Details:

Inbound Route Settings

Description: TwilioInbound
DID Number: +myDIDNumber
CallerID Number : Not Set
CID Priority Route: No
Alert Info: Not Set
CID name prefix : Not Set
Music On Hold: Default
Set Destination : Extension: 101
Signal RINGING: Yes
Reject Reverse Charges: No
Pause Before Answer: Not Set
Privacy Manager: No
Max attempts: 3
Min Length: 10
Call Recording: Force

Outbound Route

Route Name: TwilioOut
Route CID: Not Set
Override Extension: No
Route Password: Not Set
Route Type: Not Set
Music On Hold?: Default
Route Position : No Change
Trunk Sequence for Matched Routes: Twilio_SIP_Trunk
Optional Destination on Congestion: Not set
Dial Patterns:
prepend() prefix(+) match patern (X.) CallerID ()
prepend() prefix(00) match patern (X.) CallerID ()
Call Recording: Force

Zoiper Account Settings

Username: 101
Password: secret
Selected Audio Codec: u-law

I appreciate it if somebody can help me to correct my settings and make my outbound calls working properly.

Your /var/log/asterisk/full log should have the results of trying to place an outbound call.

We’ve been talking about Twilio quite a bit over the past few weeks. It seems to me that they are one of the ITSPs that will only place calls for you if your outbound Caller ID matches the information they are handling for you. As such, you might want to set the Trunk Caller ID information to override the extension settings and hard code this for your Twilio account.

Note that this is one place where your Twilio tech support can help you. If they allow “foreign” caller ID information, this might not be necessary.

These should be set so that, no matter what your PBX passes to Twilio, it is what Twilio is expecting. While it is reasonable to assume that Twilio will “just do the right thing”, we know from experience that most ITSPs are pretty inflexible about what they are willing to accept as user input. Obvious things include stripping country codes, adding country codes, “+” signs, etc.

To avoid DNS complications, I recommend you replace this with either an actual IP address or add “” to your /etc/hosts file and make sure your system refers to the hosts file for name resolution.

Until you get the system working, I’d leave the DID Number “Not Set”. This way, whatever number Twilio sends to you, you will answer. It also allows you to see what DID numbers they are actually passing and lets you set up incoming routes based on what they are sending, versus what they say they are sending.

These prefix settings are saying to remove “+” and “00” from any numbers that come in. That’s probably good. On the other hand, I don’t know if the match pattern “X.” is going to work. Normally, the outbound route pattern like to see it’s own format for those patterns. In other words, I expect to see “NXXNXXXXXX” as the matching pattern for the United States (which is implied, since you are using “U-Law” as your only codec.)

Those are some things to look at.