Skip to content

IP PBX Configuration - AsteriskPJSIPv18

Asterisk is a popular and versatile telephony software which can be used to deploy advanced PBX systems. SIP Trunk configuration instructions below apply to the following Asterisk versions:

  • Asterisk 18

Note current instructions refer to PJSIP communication library as latest Asterisk release binaries are ready to use PJSIP by default. Previous well stablished and widely tested CHAN SIP is not installed by default under recent Asterisk releases. Please refer to our previous release documentation to look for CHAN SIP set up instructions.

Documentation is provided for scenario where Asterisk server uses Static IP address on the public Internet and when Asterisk server is on Dynamic IP address.

Dynamic IP address

asterisk-sip-trunking-diagram-dynamic-ip.png

Figure 8.1 Asterisk SIP Trunk - dynamic IP address.


  1. For outbound calls from Asterisk PBX to GoTrunk SIP Credentials (SIP username and password) authentication is used.

  2. For inbound calls to one of Telephone Numbers on your GoTrunk account to work Asterisk PBX needs to Register with GoTrunk service (and periodically refresh registration in case IP address changes). Calls will be sent to IP address which was sent in the most recent Asterisk Registration. Since the calls will be coming from known peer (IP address of SIP Trunking service q.x.y.z in our example above) Asterisk will accept them without requiring any further authentication.

To configure Asterisk server to work with GoTrunk SIP Trunk using SIP Credentials authentication the following changes are required:


1. Add transport, Registration, trunk endpoint and extensions definitions to pjsip.conf file:


;=====DEFINE BASIC UDP TRANSPORT=====
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0;
;=====DEFINE OUTBOUND REGISTRATION WITH OUTBOUND AUTHENTICATION=====
[gotrunk]
type=registration;
transport=transport-udp
outbound_auth=gotrunk_auth
server_udi=sip:eu.st.ssl7.net:5060
contact_user=OUTBOUND_SIP_USERNAME   ; <- replace with your Outbound SIP Username
retry_interval=60
forbiden_retry_interval=600
expiration=3600
[gotrunk_auth]
type=auth
auth_type=userpass
password=OUTBOUND_SIP_PASSWORD  ; <- replace with your Outbound SIP Password
ser=OUTBOUND_SIP_USERNAME   ; <- replace with your Outbound SIP Username
username=ser=OUTBOUND_SIP_USERNAME   ; <- replace with your Outbound SIP Username
;=====ENDPOINT CONFIGURED AS A TRUNK, OUTBOUND AUTHENTICATION=====
[gotrunk]
type=aor
contact=sip:eu.st.ssl7.net:5060
[gotrunk]
type=endpoint
transport=transport-udp
context=from-external
disallow=all
allow=all
outbound_auth=gotrunk_auth
aors=gotrunk
[gotrunk]
type=identify
endpoint=gotrunk
match=eu.st.ssl7.net
;=====CONFIGURE 2 EXTENSIONS FOR USE WITH SIP PHONE=====
[202]
type=endpoint
transport=transport-udp
context=from-internal
callerid= +44203xxxxxxx<+44203xxxxxxx> ; optional to set custom CID on Extension
disallow=all
allow=all
auth=202
aor=202
[202]
type=auth
auth_type=userpass
password=****
username=202
[202]
type=aor
mac_contacts=5
[203]
type=endpoint
transport=transport-udp
context=from-internal
disallow=all
allow=all
auth=203
aor=203
[203]
type=auth
auth_type=userpass
password=****
username=203
[203]
type=aor
mac_contacts=5


2. To send outbound calls to GoTrunk SIP Trunk update extensions.conf file:

[from-external]
; internal calls between extensions
exten => 202,1,Dial(PJSIP/202)
exten => 203,1,Dial(PJSIP/203)
exten => _XXX,1,Dial(PJSIP/${EXTEN})
; send all other numbers to outbound trunk
exten => _XXX.,1,Dial(PJSIP/${EXTEN}@gotrunk)


3. To accept incoming calls from Telephone Numbers assigned to your GoTrunk account update extensions.conf file:

[from-internal] ; <- 'from-internal' context defined in pjsip.conf
exten => _[0-9].,1,NoOp(#### [from-trunk] ####)
exten => _[0-9].,n,Dial(PJSIP/202) ; send all incoming calls from trunk to extension 201
exten => _[0-9].,n,Hangup()

Note: example above is provided for illustration purposes only. Your actual dialplan will depend on specific PBX configuration.

Troubleshooting

Under this section you will find some basic commands that may be useful to deploy and troubleshoot SIP trunk.

# netstat -lntpeu | grep 5060 ; to check ports status

# asterisk -vvc ; to log into asterisk CLI, check for error messages and warnings

# asterisk -r -x "core show channeltypes" ; to check for PJSIP state

# asterisk -r -x "pjsip reload" ; to reload PJSIP when editing configuration file

# asterisk -r -x "pjsip show endpoints" ; to check for endpoint registration status

# asterisk -r -x "dialplan reload" ; to reload PJSIP when editing extensions file

# asterisk -r -x "dialplan show" ; to show applied dialplan

# sipsak -v -s sip:test@eu.st.ssl7.net ; tool to test connectivity to trunk service, reply should be 200 OK

# ngep -t -d any -W byline port 5060 ; to capture and display traffic under port 5060