FreePBX Server Requirements
- FreePBX 14.0
- Asterisk 13
- 1 Twilio Number
Mine will be (579)123-1234
Notes:
- My setup is behind a router.
- The private (internal) IP address of my FreePBX server is 192.168.10.160.
- FreePBX by default uses port 5160 for chan_sip but I changed it to 5060.
- FreePBX by default uses ports from 10000 to 20000 for RTP but I changed them from 10000 to 10500.
- The public (external) IP address is 123.123.123.123.
Twilio Account Setup
Elastic SIP Trunking
General
Option | Value |
---|---|
TRUNK NAME | testing |
Call Recording | No |
Secure Trunking | Disabled |
Termination
Option | Value |
---|---|
Termination URI | testing.pstn.twilio.com (Choose whatever you want) |
IP Access Control Lists | Choose what IP will be granted to communicate with your trunk. In this tutorial I will use my public IP address: 123.123.123.123 |
Creditentiel Lists | Create a username and password that will be used to connect to our trunk later. In this tutorial I will use: Username: MY_USERNAME123 Password: MY_PASSWORD123 |
Origination
Option | Value |
---|---|
Origination SIP URI | sip:123.123.123.123 |
Priority | 10 |
Weight | 10 |
Numbers
Setting UP Outgoing Calls
Trunks
For now, we will need to create 1 truck for outgoing calls.
Let’s begin by creating a SIP trunk of type chan_sip.
General Tab
Option | Value |
---|---|
Trunk Name | twilio0 |
Hide CallerID | No |
Outbound CallerID | +15791231234 (Twilio number in E.164 format) |
CID Options | Allow Any CID (if your are using Twilio Trial, use Force Trunk CID) |
Asterisk Trunk Dial Options | T |
Dialed Number Manipulation Rules Tab
Preprend | Prefix | Match pattern |
---|---|---|
+1579xxxxxxx (I will only accept calls to local numbers starting with +1579 and followed by 7 other numbers) |
sip Settings
Outgoing
Option | Value |
---|---|
Trunk Name | twilio0 |
PEER Details | host=testing.pstn.twilio.com username=MY_USERNAME123 secret=MY_PASSWORD123 type=peer dtmfmode=rfc2833 canreinvite=no disallow=all allow=ulaw insecure=port,invite context=from-trunk nat=yes |
Incoming
Leave empty
Outbound Routes
Route Settings
Option | Value |
---|---|
Route Name | PBX to Twilio Trunk (whatever you want it to be called) |
Route Password | Set this only if you want this route to be password protected, so only a few users could use it. |
Trunk Sequence for Matched Routes | twilio0 |
Dial Patterns
Preprend | Prefix | Match pattern | CallerID |
---|---|---|---|
+1579xxxxxxx | |||
+ | 1579xxxxxxx | ||
+1 | 579xxxxxxx |
That’s it! You should now be able to place outbound calls! We can now begin we the configuration of incoming calls.
Setting UP Incoming Calls
Trunks
For now, we will need to create 4 trucks for incoming calls.
Why do we need to create 4 trunks?
Because we have to create one for each Twilio’s IP addresses.
I used NORTH AMERICA VIRGINIA Twilio’s IP addresses:
54.172.60.0, 54.172.60.1, 54.172.60.2 and 54.172.60.3
https://www.twilio.com/console/sip-trunking/your-network
Let’s begin by creating an SIP trunk of type chan_sip and you will have to do the same for all other Twilio’s IP addresses.
General Tab
Option | Value |
---|---|
Trunk Name | twilio1 |
Hide CallerID | No |
Outbound CallerID | |
CID Options | Allow Any CID |
Asterisk Trunk Dial Options | T |
sip Settings
Outgoing
Option | Value |
---|---|
Trunk Name | twilio1 |
PEER Details |
Incoming
Option | Value |
---|---|
USER Context | twilioin1 |
USER Details | host=54.172.60.0 (first Twilio’s IP) type=peer insecure=port,invite canreinivite=no |
Follow the routine for the next three IP addresses.
Inbound Routes
General Tab
Option | Value |
---|---|
Description | Twilio Trunk to PBX |
Set Destination | Choose where you want inbound calls to be routed in your PBX server. You could route them to a group of extensions (All Desks) or one extension (Office Desk). |
You should now be able to receive calls!
Common Problems
Remote extension can’t register:
- Verify that your ports are opened (5060, 10000-10500) on the server.
- Verify that your client have opened port 5060.
- Try to change the remote extension “nat option” to yes in the Extension module from Applications menu.
9 Comments
Kumar Ullal · 22 December 2017 at 16 h 03 min
Do I have to open the ports 5060 and 10000-20000 on my router as well?
The GrimmChester · 22 December 2017 at 16 h 15 min
Yes! Do not hesitate if you have any other questions.
The GrimmChester · 22 December 2017 at 17 h 44 min
If you have problem with match patterns, put everything in lowercase.
Chris · 26 December 2017 at 13 h 07 min
I am having a one-way audio issue. I can hear incoming audio, but not outgoing sound. Any suggestions?
The GrimmChester · 26 December 2017 at 13 h 29 min
Hi, try to change the remote extension “nat option” to yes in the Extension module from Applications menu.
Surfer Boy · 26 March 2018 at 12 h 57 min
Hi Chris,
For your implementation as described above –
My setup is behind a router.
The private (internal) IP address of my FreePBX server is 192.168.10.160.
FreePBX by default uses port 5160 for chan_sip but I changed it to 5060.
FreePBX by default uses ports from 10000 to 20000 for RTP but I changed them from 10000 to 10500.
The public (external) IP address is 123.123.123.123.
Did you have to forward External IP (123.123.123.123) call on ports 5060, 10000 and 10500 to Internal IP (192.168.10.60) ports 5060, 10000 and 10500 ?
The GrimmChester · 4 April 2018 at 8 h 53 min
Hey Surfer Boy, you are absolutely right. You probably found the solution by the time I saw your comment :D, sorry…
dingo johanssen · 24 February 2019 at 0 h 27 min
thanks for this! finally got inbound calls to ring but still working to get bi-directional audio.
roberworpresser · 27 September 2019 at 18 h 24 min
i have freepbx 14 asterisk 13 and i created the twilio trunk as you did but i got this warning chan_sip.c: Section ‘TwilioVirginia-54.172.60.0-out’ lacks type . what does this mean ?