Skip to content

IP PBX Configuration - Asterisk

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 11
  • Asterisk 13

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.

Complete set of Asterisk configuration files described below can be found at https://github.com/GoTrunk/asterisk-config/

Static IP address

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

Figure 8.1 Asterisk SIP Trunk - static IP address.


  1. Static IP address (a.b.c.d in our example above) of your Asterisk server will be added to GoTrunk service IP ACL (Access Control List) and outbound calls coming from that IP address will be accepted without requiring any further authentication (SIP username and password). This is the most efficient way of authenticating SIP calls.

  2. Inbound calls to one of Telephone Numbers on your GoTrunk account will be sent directly to Asterisk PBX public IP address. 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 IP authentication the following changes are required:


1. Add [trunk] peer definition to sip.conf file:

[trunk]
type=peer
host=eu.st.ssl7.net    ; Europe POP
; host=amn.st.ssl7.net ; North America POP
context=from-trunk


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

[from-internal]
; internal calls between extensions
exten => 201,1,Dial(SIP/201)
exten => 201,n,Hangup()
exten => 202,1,Dial(SIP/202)
exten => 202,n,Hangup()
; send all other numbers to outbound trunk
exten => _[0-9].,1,NoOp(#### [from-internal] ####)
exten => _[0-9].,n,Set(CALLERID(num)=442036427900) ; set Caller ID
exten => _[0-9].,n,Dial(SIP/+${EXTEN}@trunk)       ; send call to trunk peer defined in sip.conf
exten => _[0-9].,n,Hangup()


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

[from-trunk] ; <- 'from-trunk' context defined in sip.conf
exten => _[0-9].,1,NoOp(#### [from-trunk] ####)
exten => _[0-9].,n,Dial(SIP/201) ; 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.

Dynamic IP address

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

Figure 8.2 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 register and [trunk] peer definition to sip.conf file:

[general]
; ...
; ...
; replace INBOUND_SIP_USERNAME and INBOUND_SIP_PASSWORD
; with your Inbound SIP Registration credentials
register => INBOUND_SIP_USERNAME:INBOUND_SIP_PASSWORD@trunk
[trunk]
type=peer
host=eu.st.ssl7.net  ; Europe POP
;host=amn.st.ssl7.net ; North America POP
context=from-trunk
qualify=yes
defaultuser=OUTBOUND_SIP_USERNAME   ; <- replace with your Outbound SIP Username
remotesecret=OUTBOUND_SIP_PASSWORD  ; <- replace with your Outbound SIP Password


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

[from-internal]
; internal calls between extensions
exten => 201,1,Dial(SIP/201)
exten => 201,n,Hangup()
exten => 202,1,Dial(SIP/202)
exten => 202,n,Hangup()
; send all other numbers to outbound trunk
exten => _[0-9].,1,NoOp(#### [from-internal] ####)
exten => _[0-9].,n,Set(CALLERID(num)=442036427900) ; set Caller ID
exten => _[0-9].,n,Dial(SIP/+${EXTEN}@trunk)       ; send call to trunk peer defined in sip.conf
exten => _[0-9].,n,Hangup()


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

[from-trunk] ; <- 'from-trunk' context defined in sip.conf
exten => _[0-9].,1,NoOp(#### [from-trunk] ####)
exten => _[0-9].,n,Dial(SIP/201) ; 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.