Setting up the Asterisk with Zadarma.
Information used in the example:
- 111111 - Your sip-number from the personal account.
- Password - You sip password found in 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 to which a softphone/IP phone is connected for receiving incoming and making outgoing calls.
Standard setup example
Outgoing calls from the extension number 101 are routed to the trunk 111111. Incoming calls are received by registration and are routed to extension number 101.
Editing sip.conf
[general] srvlookup=yes [111111] host=sip.zadarma.com insecure=invite,port type=peer fromdomain=sip.zadarma.com disallow=all allow=alaw allow=ulaw dtmfmode=auto secret=password defaultuser=111111 trunkname=111111 fromuser=111111 callbackextension=111111 context=zadarma-in qualify=400 directmedia=no nat=force_rport,comedia [101] ;the Asterisk extension secret=password host=dynamic type=peer context=zadarma-out
[general] srvlookup=yes [1234-100] host=pbx.zadarma.com insecure=invite,port type=peer fromdomain=pbx.zadarma.com disallow=all allow=alaw allow=ulaw dtmfmode=auto secret=password defaultuser=1234-100 trunkname=1234-100 fromuser=1234-100 callbackextension=1234-100 context=zadarma-in qualify=400 directmedia=no nat=force_rport,comedia [101] ;the Asterisk extension secret=password host=dynamic type=peer context=zadarma-out
Incoming and outgoing routing can be set up in the extensions.conf file
[zadarma-in] exten => 111111,1, Dial(SIP/101) ; all incoming calls from trunk 111111 are routed to extension 101 [zadarma-out] exten => _XXX,1,Dial(SIP/${EXTEN}) ; calls to 3-digit extension numbers of Asterisk exten => _XXX.,1,Dial(SIP/${EXTEN}@111111) ; calls to numbers with 4 digits or more using the trunk 111111
[zadarma-in] exten => 1234-100,1, Dial(SIP/101) ; all incoming calls from trunk 1234-100 are routed to extension 101 [zadarma-out] exten => _XXX,1,Dial(SIP/${EXTEN}) ; calls to 3-digit extension numbers of Asterisk exten => _XXX.,1,Dial(SIP/${EXTEN}@1234-100) ; calls to numbers with 4 digits or more using the trunk 1234-100
The 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,SIPAddHeader(P-Asserted-Identity: )
exten => _XXX.,n,Dial(SIP/${EXTEN}@111111)
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" is displayed in theCALLERID(name) parameter.
In the following example, calls from the number named manchester 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)}" = "manchester"]?2:3)
exten => _X.,2,Dial(SIP/101)
exten => _X.,3,GotoIf($["${CALLERID(name)}" = "london"]?4:5)
exten => _X.,4,Dial(SIP/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 number 102 and all other calls will be declined by the Asterisk with a "Busy" tone.
[zadarma-in]
exten => _X.,1,GotoIf($["${SIP_HEADER(CALLED_DID)}" = "442045770077"]?2:3)
exten => _X.,2,Dial(SIP/101)
exten => _X.,3,GotoIf($["${SIP_HEADER(CALLED_DID)}" = "442037691880"]?4:5)
exten => _X.,4,Dial(SIP/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 a 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 - Virtual phone numbers" and route the calls from the virtual number to the external server (SIP URI) using this format: 15555555555@2.20.190.41
Editing sip.conf
[zadarma]
host=sipurifr.zadarma.com
type=peer
insecure=port,invite
context=zadarma-in
disallow=all
allow=alaw
allow=ulaw
dtmfmode = auto
directmedia=no
nat=force_rport,comedia
[zadarma2]
host=sipde.zadarma.com
type=peer
insecure=port,invite
context=zadarma-in
disallow=all
allow=alaw
allow=ulaw
dtmfmode = auto
directmedia=no
nat=force_rport,comedia
[zadarma3]
host=sipurifr.zadarma.com
type=peer
insecure=port,invite
context=zadarma-in
disallow=all
allow=alaw
allow=ulaw
dtmfmode = auto
directmedia=no
nat=force_rport,comedia
Incoming route is in the extensions.conf file
[zadarma-in]
exten => 15555555555,1, Dial(SIP/101)
The setup is complete.