SIP Trunking and Fax - Digium SIP Trunking-Asterisk Configuration
This article provides sample channel driver and dialplan configurations that can be used as a guide to connect Asterisk with Digium SIP Trunking service.
PJSIP-based SIP Channel Driver (chan_pjsip)
The Asterisk PJSIP-based SIP channel driver is included with Asterisk versions 12, 13, and newer. For use with Digium SIP Trunking service, configure the following objects in the chan_pjsip configuration file, pjsip.conf, which is typically located on your filesystem in /etc/asterisk:
transport
auth
aor
endpoint
registration
identify
For more information on each chan_pjsip object type, refer to the PJSIP Configuration Sections and Relationships wiki page.
Transport Configuration
The chan-pjsip transport object defines protocol options and the local binding address. The following is a sample transport object for use with Digium SIP Trunking:
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0
In this sample (transport-udp), transport is declared using the UDP protocol and it is bound to all local interfaces.
NOTE: If you've already configured a transport object within chan_pjsip for use with SIP phones, you may use that transport object rather than adding another.
Auth Configuration
The chan-pjsip auth object holds options and credentials related to outbound authentication. In this case, that is your Digium SIP Trunking username and password. The following is a sample auth for use with Digium SIP Trunking:
[digium-siptrunk-auth]
type=auth
auth_type=userpass
username=your_digium_username
password=your_digium_password
In this sample (digium-siptrunk-auth), userpass is declared the authentication type, then username and password are set for it. When using this sample, replace the sample username and password values with your Digium SIP Trunking username and password.
Address of Record (aor) Configuration
The chan-pjsip aor object informs Asterisk where to contact the Digium SIP Trunking service. The following is a sample aor object for use with Digium SIP Trunking:
[digium-siptrunk-aor]
type=aor
contact=sip:sip.digiumcloud.net:5060
In this object (digium-siptrunk-aor), the contact address for Digium SIP Trunking is declared as sip.digiumcloud.net on port 5060.
Endpoint Configuration
The chan-pjsip endpoint object is a profile for the configuration of a remote server (or a SIP endpoint) that ties together the other sections we've created. Declaring an endpoint object is necessary so Asterisk can maintain a proper identifier for the SIP entity with which it will be communicating. The following is a sample endpoint object for use with the Digium SIP Trunking service, considering the other sample objects we've already defined:
[digium-siptrunk]
type=endpoint
context=from-digium-siptrunk
disallow=all
allow=g722
allow=ulaw
allow=g729
outbound_auth=digium-siptrunk-auth
aors=digium-siptrunk-aor
In this object (digium-siptrunk), an endpoint is declared that operates in Asterisk Dialplan context from-digium-siptrunk (discussed in Asterisk Dialplans), that allows, by first disallowing all, the G.722, G.711 u-law, and G.729a audio codecs, which use the authentication object (digium-siptrunk-auth), and which is associated with the address of record object ( digium-siptrunk-aor ).
NOTE: G.729a is typically only allowed if you've installed Digium's G.729 Add-on for Asterisk. G.729 is a licensed algorithm that cannot be distributed or used freely without this add-on.
Registration Configuration
The chan-pjsip registration object type contains information used when registering your system with another system, such as the Digium SIP Trunking service. The following is a sample registration for use with Digium SIP Trunking:
[digium-siptrunk-registration]
type=registration
transport=transport-udp
outbound_auth=digium-siptrunk-auth
server_uri=sip:sip.digiumcloud.net
client_uri=sip:your_digium_username@sip.digiumcloud.net
contact_user=your_digium_username
retry_interval=60
In this object (digium-siptrunk-registration), a registration is declared that uses our transport object (transport-udp), which uses the digium-siptrunk-auth authentication information for outbound authentication, which sets the outbound server URI as sip.digiumcloud.net, which specifies our client URI as your_digium_username at sip.digiumcloud.net, which sets our contact user to your_digium_username and that will retry failed registrations every 60 seconds.
Identify Configuration
The chan-pjsip identify object type helps route incoming packets inside of Asterisk, so Asterisk knows to which endpoint an incoming call should be associated. The following is a sample identify object for use with Digium SIP Trunking:
In this object (digium-siptrunk-identify), inbound calls from sip.digiumcloud.net (the Digium SIP Trunking server) are matched to the digium-siptrunk endpoint (the one we've created here).
Complete PJSIP Configuration Example
The following is a complete PJSIP example configuration. It requires input of your Digium SIP Trunking username and password in thedigium-siptrunk-authobject, your username in thedigium-siptrunk-registrationobject, and a valid incoming dialplan context. You need to createfrom-externalor supply your own:
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0
[digium-siptrunk-auth]
type=auth
auth_type=userpass
username=your_digium_username
password=your_digium_password
[digium-siptrunk-aor]
type=aor
contact=sip:sip.digiumcloud.net:5060
[digium-siptrunk]
type=endpoint
context=from-external
disallow=all
allow=ulaw
allow=g729
outbound_auth=digium-siptrunk-auth
aors=digium-siptrunk-aor
[digium-siptrunk-registration]
type=registration
transport=transport-udp
outbound_auth=digium-siptrunk-auth
server_uri=sip:sip.digiumcloud.net
client_uri=sip:your_digium_username@sip.digiumcloud.net
retry_interval=60
[digium-siptrunk-identify]
type=identify
match=sip.digiumcloud.net
endpoint=digium-siptrunk
SIP Channel Driver (chan_sip)
To configure the older Asterisk chan_sip-based SIP channel driver for use with the Digium SIP Trunking service, configure the following objects in the chan_sip configuration file sip.conf, which is typically located on your filesystem in /etc/asterisk:
Outbound Registration (chan_sip Register Configuration)
An outbound registration establishes connectivity with the Digium SIP Trunking servers. In chan_sip, outbound registrations are configured in the [general] section of sip.conf. The following is a sample register for use with Digium SIP Trunking:
In this sample register object, we configure 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 our digium username.
SIP Peer Configuration (chan_sip Peer Configuration)
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 Asterisk can maintain a proper identifier for the SIP entity with which it will be communicating. The following is a sample sip peer for use with Digium SIP Trunking:
In this sample, sip peer object, our host is set to sip.digiumcloud.net, and the defaulter and the fromuser options are set to our Digium username; secret is set to our Digium password, and an option called insecure is set to invite (because the Digium SIP Trunking servers do not reverse authenticate when sending you calls); trustrpid and sendrpid are enabled for Caller ID forwarding, and the inbound Dialplan context is set to from-digium-siptrunk, We have explicitly disabled directmedia, and, by first disallowing first, we've enabled the G.722, G.711 u-law and G.729a audio codecs.
NOTE: G.729a should typically only be allowed if you have installed Digium's G.729 Add-on for Asterisk. G.729 is a licensed algorithm that cannot be distributed or used freely without this add-on.
Asterisk Dialplans
To determine what to do with incoming calls, Asterisk uses a configuration of numbers and patterns matched with specific actions called a dialplan and configured in extensions.conf, which is typically located in /etc/asterisk. To complete your Digium SIP Trunking service setup, you need to configure your Asterisk dialplan. To learn more about the Asterisk dialplan, refer to the Dialplan wiki page and its children, available on the Asterisk wiki.
Inbound Dialplan (dialplan incoming call context)
Outbound Dialplan (dialplan outgoing call context)
Inbound Dialplan (dialplan incoming call context)
Domestic calls that are inbound from the Digium SIP Trunking servers are delivered with full 10-digit DID. A sample incoming context for use with Digium SIP Trunking resembles the following:
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 it will finally be hung up. Users of chan_sip, in lieu of chan_pjsip, may dial using the SIP technology instead of PJSIP.
Outbound Dialplan (dialplan outgoing call context)
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 in whatever dialing context your SIP endpoints are otherwise configured. The following is a sample outgoing context for use with Digium SIP Trunking:
In this example, 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 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 need to replace your_digium_caller_id_number with your DID number as received from Digium: e.g., 8005551234.
NOTE: By default, Digium SIP Trunking accounts are able to dial US48 numbers. For extended North American dialing as well as International Dialing capabilities, contact Digium Cloud Services Customer Service.
If your account is not authorized for International dialing, International call attempts will return the following message:
If your account is not authorized for US50 dialing, call attempts to Alaska or Hawaii will return the following message: