Asterisk

Setting up Asterisk with Zadarma

Key to the information which appears in the example:

  • 111111 Your sip-number from personal account.
  • Password You sip password found under "SIP-settings" in personal account.
  • 101 Asterisk's internal number to which the softphone/IP phone is connected in order to receive incoming calls and to make outgoing calls.

Standard variant

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

Edit sip.conf


[general]
srvlookup=yes

[111111]
host=sip.zadarma.com
insecure=invite,port
type=friend
fromdomain=sip.zadarma.com
disallow=all
allow=alaw&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]                                                  ;extension of Your Asterisk
secret=password
host=dynamic
type=friend
context=zadarma-out

Incoming and outgoing routing is set in file extensions.conf


[zadarma-in]

exten => 111111,1, Dial(SIP/101)                       ; all incoming calls from trunk 111111
                                                       ; are routed on internal number 101

[zadarma-out]

exten => _XXX,1,Dial(SIP/${EXTEN})                     ; calls on 3-digit internal numbers
                                                       ; of Asterisk

exten => _XXX.,1,Dial(SIP/${EXTEN}@111111)             ; calls on numbers with 4 digits
                                                       ; or more via trunk 111111

Standard setup is done.

If you have several active DID numbers, you can set a "name" to each number (for example, Moscow and London) and set incoming routing based on this parameter. "Name" of DID number is set in parameter CALLERID(name).

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


[zadarma-in]

exten => _X.,1,GotoIf($["${CALLERID(name)}" = "moscow"]?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 DID to which the call was received, is passed to the header CALLED_DID. It is possible to configure inbound routing based on this parameter.

In the following example, calls from the number 74957776675 are routed to internal number 101, calls from the number 442037691880 are routed to internal number 102 and all other calls will be declined by Asterisk with a "Busy" tone.


[zadarma-in]

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


Setup is finished.

Example №2 (SIP URI)

If 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.

Key to the information which appears in the example:

  • 15555555555 - Your DID number connected to Zadarma.
  • 2.20.190.41 - IP of your Asterisk server.
In your personal account, under "Settings - Direct phone number" route calls from DID number to an external server (SIP URI) using the format 15555555555@2.20.190.41

Edit sip.conf

[zadarma]
host=sipde.zadarma.com
type=friend
insecure=port,invite
context=zadarma-in
disallow=all
allow=alaw&ulaw
dtmfmode = auto
directmedia=no
nat=force_rport,comedia

[zadarma2]
host=siplv.zadarma.com
type=friend
insecure=port,invite
context=zadarma-in
disallow=all
allow=alaw&ulaw
dtmfmode = auto
directmedia=no
nat=force_rport,comedia

[zadarma3]
host=sipfr.zadarma.com
type=friend
insecure=port,invite
context=zadarma-in
disallow=all
allow=alaw&ulaw
dtmfmode = auto
directmedia=no
nat=force_rport,comedia
Incoming route in file extensions.conf

[zadarma-in]

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

Setup is finished.

Example configuration with authorization by IP address.