Contact Sales

All fields are required

How to Connect Asterisk to SignalWire CLOUD for SIP… | SignalWire
Product

How to Connect Asterisk to SignalWire CLOUD for SIP Connectivity

Connect to the future of telecom: SignalWire's elastic global real-time communications network

SignalWire

Connecting Asterisk to a cloud SIP trunk lets your PBX place and receive calls over the public switched telephone network (PSTN) without running carrier infrastructure yourself. This article explains how to configure SignalWire as a SIP trunk for Asterisk using PJSIP, including creating a SIP endpoint and routing a purchased phone number to it in SignalWire, then setting up pjsip.conf and dialplan handling in Asterisk so inbound calls match the correct endpoint and outbound calls route through SignalWire reliably.

Connecting Asterisk to SignalWire CLOUD

Just one of the things that SignalWire can do is act as a SIP trunk, providing inbound and outbound calling for your PBX or hosted PBX infrastructure.

The first thing to do is to create a SignalWire account. This is straightforward, and you are even given a $5.00 credit to do things like buy DID numbers. A single US DID costs just 8 cents per month. SIP connectivity is metered per minute/per call leg at just $0.0007, and that includes SRTP and TLS encryption that many providers charge extra for.

Next, create a new resource and choose a SIP endpoint, as this is how your Asterisk will connect with SignalWire. You will notice that you need to give the endpoint a name and that the full SIP URI for it includes the name you chose for your Space URL as well as a multi-character unique ID.

You can leave all of the settings for the SIP endpoint at their defaults, so now you just need to set a (very strong) password.

Then you will add a phone number. When you configure it you will see that there are a number of settings – the only one you need to change at this point is "handle calls using" – set this to be SIP endpoint. This, in turn, will require you to choose an endpoint.

That is all your work done at the SignalWire end.

Asterisk PJSIP trunk configuration for SignalWire

Now let’s configure Asterisk. You should be using at least version 13.x.x and this post will show the PJSIP and dialplan settings.

First, here are the relevant entries for PJSIP:

/etc/asterisk/pjsip.conf

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0


[signalwire]
type=auth
auth_type=userpass
username=asterisk ; Your username
password=<very-strong-password>

[signalwire]
type=aor
contact=sip: duffett-113115cf718e.sip.signalwire.com

[signalwire]
type=endpoint
transport=transport-udp
outbound_auth=signalwire ; Note that there is only an outbound_auth, as we do not challenge when a call arrives inbound
aors=signalwire
disallow=all
allow=ulaw
from_user=asterisk
from_domain=duffett-113115cf718e.sip.signalwire.com
media_encryption=sdes ; Note that we are using encryption
context=from-signalwire

[signalwire]
type=registration
server_uri=sip: duffett-113115cf718e.sip.signalwire.com
client_uri=sip:asterisk@duffett-113115cf718e.sip.signalwire.com ; Your full SIP URI
outbound_auth=signalwire

[signalwire]
type=identify
endpoint=signalwire
match=duffett-113115cf718e.sip.signalwire.com


Now your SIP connection is made. Asterisk should register with SignalWire using the registration section, which in turn used the information in your auth section to authenticate.

Inbound calls are matched to the SignalWire endpoint using the identify section, and then handled in the from-signalwire context in the dialplan.

Outbound calls are sent out through the SignalWire endpoint to the host which is identified in the aor section.

In the from-signalwire context, you will notice that the number 1 priority of the s extension sets a variable called numb to a CUT() of a CUT() of the result of a read of the PJSIP_HEADER function, looking at the To field.

This is because as far as Asterisk is concerned, the call has arrived without any dialed digits (that is why we have to run with the s extension).

The dialed number is actually contained in the To field of the SIP header, and so that first line is just to obtain the dialed number.

/etc/asterisk/extensions.conf

[outbound]
exten => _1NXXNXXXXXX,1,Dial(PJSIP/${EXTEN}@signalwire)

[from-signalwire]
exten => s,1,Set(numb=${CUT(CUT(PJSIP_HEADER(read,To),@,1),:,2)})
same => n,Goto(${numb:1},1) ; Using ${numb:1} simply strips away the first character or number, in this case a‘+’

exten => 12563840002,1,Playback(tt-monkeys)

Next steps after your trunk is working

If you have an endpoint connected to your Asterisk that can get into the outbound context, you should be able to send calls out to US numbers using the pattern shown.

However, when your SignalWire account is first created, it will be in "Trial Mode" with a $5.00 credit, but you cannot send outbound calls until you add some credit to bring the account out of Trial Mode. Without doing this, outbound calls will be greeted with a 404 error.

Learn about our disruptive pricing here and bring your questions to our community on Discord.

Frequently asked questions

What is SIP trunking for Asterisk?

SIP trunking connects your Asterisk PBX to a carrier or cloud provider using Session Initiation Protocol (SIP), so you can send and receive PSTN calls while keeping your existing extensions, routing, and dialplan logic.

How do you connect Asterisk to SignalWire CLOUD for SIP connectivity?

You create a SignalWire account, create a SIP endpoint, buy a phone number, and configure that number to “handle calls using” the SIP endpoint. Then you configure Asterisk PJSIP registration, authentication, and routing so Asterisk registers to SignalWire and can place and receive calls through the endpoint.

Why does this guide use PJSIP instead of chan_sip?

The configuration shown is built around Asterisk PJSIP settings and dialplan routing, which is the modern, supported SIP stack in Asterisk and is the approach the guide demonstrates for connecting to SignalWire.

Why do inbound calls sometimes arrive on the s extension in Asterisk, and how do you route them?

In this setup, Asterisk can treat an inbound trunk call as arriving without dialed digits, which is why the dialplan uses the s extension. The guide routes calls by extracting the dialed number from the SIP To header, then using that value for the next routing step.

Why do outbound calls return a 404 error in Trial Mode?

The guide notes that new SignalWire accounts start in Trial Mode, and outbound calling is blocked until you add additional credit to move the account out of Trial Mode, otherwise outbound calls can receive a 404 error.

Related Articles