VoIP

How to set up a SIP trunk with FreePBX and Twilio

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.
The GrimmChester

View Comments

    • Hi, try to change the remote extension “nat option” to yes in the Extension module from Applications menu.

  • 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 ?

    • Hey Surfer Boy, you are absolutely right. You probably found the solution by the time I saw your comment :D, sorry...

  • 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 ?

Share
Published by
The GrimmChester

Recent Posts

Automated Web Hosting Solution (AWHS)Panel

Requirements For now, AWHSPanel only supports Debian 8 but its architecture allows easy new implementations.…

9 years ago

How to install ioncube on Debian & Ubuntu

ionCube installation What is ionCube: ionCube helps you to protect your PHP code from being…

10 years ago

Comment rediriger un site HTTP vers HTTPS

RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

10 years ago

How To Install Linux, Nginx, MySQL, PHP (LEMP) on Debian 8

Files Structure: /srv /mydomain.com /.socks /www /cgi-bin /logs /public_html /ssl /tmp /blog /cgi-bin /logs /public_html…

10 years ago

How To automate Horde Groupware Webmail installation

Prerequisites: - 1 database (mysql) - 1 user associated with the database - Follow this…

10 years ago

How To install the latest version of phpMyAdmin automatically on Linux

1. Virtual Host If you need to create a Virtual Host on Apache2 I recommend…

10 years ago