Instructions on how to configure VoIP equipment Asterisk PJSIP

Setting up the Asterisk PJSIP with Zadarma.

Information used in the example:

  • 111111 - your sip-number from your personal account.
  • Password - you sip-number password from the "SIP Connection" section of your personal account.
  • 1234-100 - Your PBX extension from your personal area
  • Password - your PBX extension password from your personal area
  • 101 - the Asterisk extension connected to the softphone/IP phone.

Standard setup example

Outgoing calls from extension number 101 are routed to the trunk 111111. Incoming calls are received by registration and are routed to the extension 101.

Outgoing calls from extension 101 are routed to the trunk 1234-100. Incoming calls are received by registration and are routed to the extension 101.

Edit pjsip.conf


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

[111111]
type=registration
transport=udp-transport
outbound_auth=111111_auth
server_uri=sip:sip.zadarma.com
client_uri=sip:111111@sip.zadarma.com
retry_interval=60
expiration=120
contact_user=111111

[111111_auth]
type=auth
auth_type=userpass
password=Password
username=111111

[111111]
type=aor
contact=sip:sip.zadarma.com

[111111]
type=endpoint
transport=udp-transport
context=zadarma-in
disallow=all
allow=alaw
allow=ulaw
outbound_auth=111111_auth
aors=111111
from_user=111111
direct_media=no

[111111]
type=identify
endpoint=111111
match=sip.zadarma.com




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

[1234-100]
type=registration
transport=udp-transport
outbound_auth=1234-100_auth
server_uri=sip:pbx.zadarma.com
client_uri=sip:1234-100@pbx.zadarma.com
retry_interval=60
expiration=120
contact_user=1234-100

[1234-100_auth]
type=auth
auth_type=userpass
password=Password
username=1234-100

[1234-100]
type=aor
contact=sip:pbx.zadarma.com

[1234-100]
type=endpoint
transport=udp-transport
context=zadarma-in
disallow=all
allow=alaw
allow=ulaw
outbound_auth=1234-100_auth
aors=1234-100
from_user=1234-100
direct_media=no

[1234-100]
type=identify
endpoint=1234-100
match=pbx.zadarma.com


Extension 101 to which the softphone/IP phone will be connected for receiving incoming and making outgoing calls.


[101]
type=endpoint
transport=udp-transport
context=zadarma-out
disallow=all
allow=alaw
allow=ulaw
auth=101
aors=101

[101]
type=auth
auth_type=userpass
password=101
username=101

[101]
type=aor
max_contacts=10

Incoming and outgoing routing is set in the extensions.conf file



[zadarma-in]
exten => 111111,1, Dial(PJSIP/101)                     ; all incoming calls from the trunk 111111 are routed to the extension 101

[zadarma-out]
exten => _XXX,1,Dial(PJSIP/${EXTEN})                   ; calls to 3-digit extension numbers of Asterisk
exten => _XXX.,1,Dial(PJSIP/${EXTEN}@111111)           ; calls to numbers with 4 digits or more via trunk 111111





[zadarma-in]
exten => 1234-100,1, Dial(PJSIP/101)                   ; all incoming calls from the trunk 1234-100 are routed to the extension 101

[zadarma-out]
exten => _XXX,1,Dial(PJSIP/${EXTEN})                   ; calls to 3-digit extension numbers of Asterisk
exten => _XXX.,1,Dial(PJSIP/${EXTEN}@1234-100)         ; calls to numbers with 4 digits or more via trunk 1234-100


Standard setup is complete.

P-Asserted-Identity (for experienced users).

When making outgoing calls, you can use the SIP header P-Asserted-Identity to select the Caller ID from a list of connected numbers within the service.

The number from the P-Asserted-Identity header will be used as a priority. If the header is not provided or contains an incorrect/unconnected number, the default number will be used instead.



[zadarma-out]
exten => _XXX.,1,Set(_SET_PAI=)
exten => _XXX.,n,Dial(PJSIP/${EXTEN}@111111,,b(add_header_pai^add^1))
[add_header_pai]
exten => add,1,Set(PJSIP_HEADER(add,P-Asserted-Identity)=${SET_PAI})
exten => add,n,Return()


If you have several active virtual phone numbers, you can "name" each number (for example manchester and London), and set the incoming routing based on this parameter. The virtual phone number "Name" can be set in the CALLERID(name) parameter.

In the following example, calls from the number named manchester are routed to the extension 101, and calls from the number named London are routed to the extension 102. All other calls will be declined by the Asterisk with a "Busy" tone.



[zadarma-in]

exten => _X.,1,GotoIf($["${CALLERID(name)}" = "manchester"]?2:3)
exten => _X.,2,Dial(PJSIP/101)
exten => _X.,3,GotoIf($["${CALLERID(name)}" = "london"]?4:5)
exten => _X.,4,Dial(PJSIP/102)
exten => _X.,5,Busy


Your virtual phone number that received the call will be displayed in the CALLED_DID header. It is possible to configure incoming routing based on this parameter.

In the following example, calls from the number 442045770077 are routed to extension number 101, calls from the number 442037691880 are routed to extension 102. The Asterisk will decline all other calls with a "Busy" tone.



[zadarma-in]

exten => _X.,1,GotoIf($["${PJSIP_HEADER(read,CALLED_DID)}" = "442045770077"]?2:3)
exten => _X.,2,Dial(PJSIP/101)
exten => _X.,3,GotoIf($["${PJSIP_HEADER(read,CALLED_DID)}" = "442037691880"]?4:5)
exten => _X.,4,Dial(PJSIP/102)
exten => _X.,5,Busy



The setup is complete.

Example №2 (SIP URI)

If the Asterisk is located on a "white" IP address (not behind a router, for example in a data centre), incoming calls can be received without registration by SIP URI scheme.

Information used in the example:

  • 15555555555 - Your virtual phone number connected to Zadarma.
  • 2.20.190.41 - your Asterisk server IP address.

Go to your personal account, "Settings - Direct phone number" and route the calls from the virtual number to the external server (SIP URI) using this format 15555555555@2.20.190.41

Edit pjsip.conf


[15555555555]
type=aor
contact=sip:sip.zadarma.com

[15555555555]
type=endpoint
transport=udp-transport
context=zadarma-in
disallow=all
allow=alaw
allow=ulaw
aors=15555555555
direct_media=no

[15555555555]
type=identify
endpoint=15555555555
match=sip.zadarma.com
match=sipurifr.zadarma.com
match=sipde.zadarma.com
match=sipuriny.zadarma.com


Incoming route is in the extensions.conf file


[zadarma-in]

exten => 15555555555,1, Dial(PJSIP/101)


The setup is complete.

Enabling encryption

1.In the file pjsip.conf add the following

[transport-z]

type=transport

protocol=tls

verify_server=no

bind=0.0.0.0:7065

method=tlsv1_2

2.In server_uri after the server address add :5061

Setup example using the authorization by IP address.