Open Source - How to configure a Digium SIP Trunking account with Asterisk using chan_sip

Depending on the version of Asterisk that you are using, You may have two channels drivers that you could use in order to create a peer that you could use to place and receive calls

Digium SIP trunking with chan_sip

To configure Asterisk's older chan_sip-based SIP channel driver, to work with Digium's SIP Trunking service, you should configure two objects:

  • Outbound Registration

  • SIP Peer

These objects will be configured in the chan_sip configuration file sip.conf, typically located on your filesystem in /etc/asterisk

Outbound Registration

An outbound registration establishes connectivity with Digium's SIP Trunking servers.  In chan_sip, outbound registrations are configured in the [general] section of sip.conf.  A sample register for use with Digium SIP Trunking would resemble:
 

[general]
register => your_digium_username:your_digium_password@sip.digiumcloud.net:5060/your_digium_username

Here, in the register object, we're configuring a registration using our digium username, followed by a colon, followed by our digium password at sip.digium.cloud.net on port 5060 followed by a forward slash, followed by your digium username.

 

SIP Peer

The sip peer object is a profile for the configuration of a remote server (or a SIP endpoint).  Declaring a sip peer object is necessary so that Asterisk can maintain a proper identifier for the SIP entity with which it'll be communicating.  A sample sip peer for use with Digium's SIP Trunking would resemble:
 

[digium-siptrunk]
type=peer
host=sip.digiumcloud.net
defaultuser=your_digium_username
fromuser=your_digium_username
secret=your_digium_password
insecure=invite
trustrpid=yes
sendrpid=pai
context=from-digium-siptrunk
directmedia=no
disallow=all
allow=g722
allow=ulaw
allow=g729

 

Here, in the sip peer object, we're setting our host to sip.digiumcloud.net, we're setting the default user and the fromuser options to our Digium username, secret is set to our Digium password, we've set an option called insecure to invite (because the Digium's SIP Trunking servers don't reverse authenticate when sending calls to you), we've enabled trustrpid and sendrpid for Caller ID forwarding, we've set the inbound Dialplan context to from-digium-siptrunk, we've explicitly disabled directmedia, and, by virtue of disallowing first, we've enabled the G.722, G.711 u-law and G.729a audio codecs (if you have purchase the G.729 codec license and have installed on your Asterisk system)

Asterisk Dialplan Configuration

Asterisk uses a configuration of numbers and patterns matched with specific actions, called dialplan, and configured in extensions.conf, typically located in /etc/asterisk in order to determine what to do with incoming calls.  In order to complete your setup with Digium's SIP Trunking service, you will need to properly configure your Asterisk dialplan.  To learn more about Asterisk's dialplan, please see the Dialplan wiki page, as well as its children, available on the Asterisk wiki.

Inbound Dialplan
Domestic calls that are inbound from Digium's SIP Trunking servers are delivered with full 10-digit DID.  A sample incoming context for use with Digium's SIP Trunking, would resemble:
 

[from-digium-siptrunk]
exten => 8005551234,1,NoOp()
same => n,Answer()
same => n,Background(demo-congrats)
same => n,Dial(PJSIP/sample_endpoint,,25) 
same => n,Hangup()

Here, because we earlier configured our Digium SIP Trunking PJSIP endpoint or SIP peer to attach to context from-digium-siptrunk, calls to our hypothetical inbound DID 8005551234 will first perform No Operation, then will be Answered, then will have the sound file demo-congrats played to them, will be connected via the Dial application (which will try for 25 seconds) to a hypothetical PJSIP endpoint local to your system called sample_endpoint, and will finally be hung up upon.  Users of chan_sip, in lieu of chan_pjsip, may dial using the "SIP" technology instead of "PJSIP"
 

Outbound Dialplan
Outbound dialing should be handled by a separate context and should include pattern matches for local and long-distance calling.  And, this context should be included into whatever dialing context your SIP endpoints are otherwise configured.  A sample outgoing context for use with Digium's SIP Trunking would resemble:
 

[sip-phones]
; The context that your SIP phones are configured to use
include => outbound-digium-siptrunk
 
[outbound-digium-siptrunk]
; Pattern matching 1 + 10-digit North American dialing
exten => _1NXXNXXXXXX,1,NoOp()
same => n,Set(CALLERID(num)=your_digium_caller_id_number)
same => n,Dial(PJSIP/${EXTEN}@digium-siptrunk,,25)
same => n,Hangup()
 
; Pattern matching 10-digit North American dialing that prefixes 1 to the dialed number
exten => _NXXNXXXXXX,1,NoOp()
same => n,Set(CALLERID(num)=your_digium_caller_id_number)
same => n,Dial(PJSIP/1${EXTEN}@digium-siptrunk,,25)
same => n,Hangup()
 
; Pattern matching International dialing using 011 as the access code
exten => _011.,1,NoOp()
same => n,Set(CALLERID(num)=your_digium_caller_id_number)
same => n,Dial(PJSIP/${EXTEN}@digium-siptrunk,,25)
same => n,Hangup() 

Here, we have configured pattern matches for 1+ 10-digit North American dialing, 10-digit North American dialing, and International Dialing.  Users of chan_sip, in lieu of chan_pjsip, may dial using the SIP technology instead of PJSIP.  The ,,25 in each of the Dial statements means that Asterisk will attempt the dial for no more than 25 seconds before jumping to the next step - a Hangup() as we have configured here.  You will need to replace your_digium_caller_id_number with your DID number as received from Digium, e.g. 8005551234.

Return to Documentation Home I Return to Sangoma Support