fb

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-settings" section of your personal account.
  • 101 - the Asterisk extension number that is 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 number 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:5060

[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

Extension number 101 to which the softphone/IP phone is connected.

[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 number 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

Standard setup is complete.

If you have several active virtual phone numbers, you can "name" each number (for example Moscow 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 Moscow are routed to the extension number 101, and calls from the number named London are routed to the extension number 102. All other calls will be declined by the Asterisk with a "Busy" tone.


[zadarma-in]

exten => _X.,1,GotoIf($["${CALLERID(name)}" = "moscow"]?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 74957776675 are routed to extension number 101, calls from the number 442037691880 are routed to extension number 102. The Asterisk will decline all other calls with a "Busy" tone.


[zadarma-in]

exten => _X.,1,GotoIf($["${PJSIP_HEADER(read,CALLED_DID)}" = "74957776675"]?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:5060

[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

Incoming route is in the extensions.conf file

[zadarma-in]

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

The setup is complete.

Setup example using the authorization by IP address.