Bring Your Own Carrier: Telnyx & Asterisk
The Telnyx network offers unparalleled security, reliability and call quality. That’s because we’re a true carrier, and unlike many CPaaS providers, we don’t rely on middlemen to provide core communications functionality and routing.
We built our SIP services so that you can easily integrate Telnyx with any platform to get your business communications set up quickly. Whether you’re looking to integrate with hardware or cloud-based solutions we want to empower you to make and receive calls globally with the network built for reliable, enterprise-grade voice services.
This guide shows you how to connect your Telnyx numbers to Asterisk. Asterisk is an open source framework for building communications applications. Asterisk turns any computer into a communications server. Asterisk powers IP PBX systems, VoIP gateways, conference servers and other custom solutions. It’s a PBX solution suitable for small businesses, large businesses, call centers, carriers and government agencies anywhere in the world.
What you’ll need to get started with Asterisk:
- A Telnyx account - Sign up with your email address, or register with your Google, Facebook or GitHub account - it only takes a few seconds.
- A download of Asterisk Version 16.
How it works
A Telnyx Elastic SIP Trunk is used to connect your IP-based communications infrastructure to the PSTN, so you can make and receive calls globally with our private IP network. We handle all the complexity in routing calls and delivering crystal clear conversations. To connect your Telnyx numbers to your Asterisk platform we need to establish a SIP interface which is completed in these steps:
- Set up your Telnyx SIP Trunk Connection.
- Authenticate your SIP Trunk with Asterisk.
- Configure your Asterisk profile for Inbound and Outbound calling.
Getting Started with Your Telnyx Mission Control Portal
There are four steps needed to set up your Telnyx Mission Control Portal account so that it’s ready to be configured to your PBX phone system, softphone client or softswitch of your choice.
Level 1 Verification:
To complete the below steps, you'll need to be Level 1 verified. Most users will already be Level 1 verified following email confirmation on signup. To check, visit the ‘My Account’ section of your portal account, and navigate to ‘Verifications’. More information on account verification can be found here.
Connection Setup
Next, you need to set up a connection to authenticate your client (Asterisk) with our sip proxy (sip.telnyx.com). We have two authentication types on the portal: Credentials and IP Address.
These steps will walk through the setup of a credentials based connection. For information on IP based connections, check out the instructions here.
- Go to ‘Connections’ from the side navigation
- Click the "+ Add Connection" button near the top right corner of the page.
- Enter the name you wish to have for your connection.
- Select "Credentials" as the "Connection Type". Click here for IP setup.
- A username and password will automatically be generated but you change the credentials by clicking the "edit" button to the left. Please make sure you use strong credentials.
- Click "Set Credentials".
- Click "Done"
Note: Once your Credential connection is created, you can display the username and password by clicking the eye icon under the "Auth Detail" column.
DIDs
A DID is required in order to receive inbound calls to your client. After you purchase a DID on your account, you'll have to assign the connection you wish to receive inbound calls to. Information on assigning DIDs to a connection and DID features can be found here. More details on our number search feature can be found here.
Outbound Profile
An outbound profile is required in order to make outbound calls. More information on creating an outbound profile and its features are explained here.
Need additional support to get started?
Check out our support guide. Supplementary information for configuring your client, such as the signaling and media IP’s to our SIP proxy can be found at sip.telnyx.com.
Setup Asterisk for Your Telnyx Connection
Setting up SIP Trunk configurations on the Asterisk platform is pretty simple. To connect a SIP Trunk, we need to specify inbound and outbound signaling for Telnyx, set up authentication, add our numbers and set up some headers.
Configuring Asterisk requires copy and pasting some lines of code into the configuration files. Everything can be completed with an editor capable of modifying .conf files. The configuration files are located in the folder where you installed Asterisk.
Telnyx SIP Trunk Setup
Open /etc/asterisk/pjsip_wizard.conf with your preferred editor. Copy and paste the lines below into your editor. Replace “username” and “password” with your username and password for the installation in /etc/asterisk/pjsip_wizard.conf.
trunk_defaults
type = wizard
telnyx
endpoint/transport=0.0.0.0-udp
endpoint/allow = !all,ulaw,alaw,G729,G722
endpoint/rewrite_contact=yes
endpoint/dtmf_mode=rfc4733
endpoint/context = from-pstn
endpoint/force_rport = yes
aor/qualify_frequency = 60
sends_auth = yes
sends_registrations = yes
remote_hosts = sip.telnyx.com:5060
outbound_auth/username = username
outbound_auth/password = password
registration/expiration = 600
NoteAfter pasting the above content, Kindly check and remove any new line added
Note: For this configuration to work, the module res_pjsip_config_wizard.so must be installed and loaded, available from Asterisk 13.2.0.
Add Configuration to Make and Accept Calls
Modify /etc/asterisk/pjsip_wizard.conf to add global configurations for the extensions. These lines of code setup extension 1001 to make and accept calls. The extension, 1001, and the password in these lines should be replaced with your preferred extension and password.
Copy and paste these lines into /etc/asterisk/pjsip_wizard.confwithin your editor:
user_defaults
type = wizard
accepts_registrations = yes
sends_registrations = no
accepts_auth = yes
sends_auth = no
endpoint/context = from-internal
endpoint/allow = !all,ulaw,alaw,G729,G722
endpoint/dtmf_mode = rfc4733
endpoint/rewrite_contact = yes
endpoint/force_rport = yes
aor/max_contacts = 1
aor/remove_existing = yes
aor/minimum_expiration = 30
1001
endpoint/callerid = Test User <1001>
inbound_auth/username = 1001
inbound_auth/password = strong@pass123$
NoteAfter pasting the above content, Kindly check and remove any new line added
Complete the Basic PJSIP Configuration
pjsip_wizard.conf is great for setting up PJSIP endpoints. However, global configurations, or anything else that might be needed can be added in /etc/asterisk/pjsip.conf.
In the basic setup, copy and paste these lines into pjsip.conf for installations behind NAT:
[global]
type=global
[transport-udp-nat]
type=transport
protocol=udp
bind=0.0.0.0:5060
local_net=X.X.X.X/24
external_media_address=X.X.X.X
external_signaling_address=X.X.X.X
allow_reload=no
NoteAfter pasting the above content, Kindly check and remove any new line added
If your PBX is not in a NAT network, you can safely remove these parameters:
- external_media_address
- external_signaling_address
Once these configurations are added to the correct files, your PBX should be registered to Telnyx. The extension 1001 in your IP phone/softphone will be registered to your PBX.
There’s just one last step needed to make calls.
Set Up the Dialplan
Asterisk uses the dialplans saved in /etc/asterisk/extensions.conf to route calls between endpoints, among other tasks. To allow our extension 1001 to make calls through Telnyx and receive inbound calls to the Telnyx DID assigned to the respective trunk, you must open extension.conf.
Copy and paste these lines into your editor:
[from-pstn]
exten => _+1NXXXXXXXXX,1,Dial(PJSIP/1001)
exten => _NXXXXXXXXX,1,Dial(PJSIP/1001)
[from-internal]
exten = _NXXNXXXXXX,1,Dial(PJSIP/+1${EXTEN}@telnyx)
same = n,Hangup()
exten = _X.,1,Dial(PJSIP/+${EXTEN}@telnyx)
same = n,Hangup()
NoteAfter pasting the above content, Kindly check and remove any new line added
- from-pstn is the context that captures inbound calls from Telnyx and sends calls to extension 1001. With these lines, it will capture every call to CLDs in the US (10 digit) or +E164 and send it to extension 1001.
- from-internal routes outbound calls through Telnyx. In the lines above, it captures calls to US national numbers, converts the number to +E164, or prepends “+”, and sends the call to Telnyx. That's it, you've configured Asterisk and can make and receive calls with Telnyx as your SIP provider!
A little disclaimer: This guide has been developed by our product team to help you get started on the Telnyx platform. It isn’t necessarily supported or verified by the other platform and may vary based on platform version but we are confident in its accuracy.
Support and Additional Resources:
- Check out Asterisk's help section for extra support!
- Looking for additional help? Click the Live Chat icon at your lower right-hand corner and start a chat.