fb

Asterisk PJSIP with authorization by IP adress

Setting up Asterisk PJSIP with Zadarma by authorizing an IP address

If the server running Asterisc is using a "white" IP address (not behind a router, but, for example, in a data center), outgoing calls can be made without a sip login and password, with IP authorization. Incoming calls can be received without registration with SIP URI.

Data given in example:

  • 15555555555 - Your Zadarma phone number.
  • 2.20.190.41 - IP address of your Asterisk server.
  • 101 Asterisk's extension number to which softphone/IP-phone is connected in order to receive incoming calls and to make outgoing calls.
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

Adding SIP-trunk:

In your personal account, under "Settings - SIP-settings", click on "Add SIP-trunk" (appears at the bottom of the page).

Set a name for the SIP-trunk and choose one of the exisiting sip logins. This will become the SIP-trunk identifier and will be unavailable for registration (receiving incoming calls ).

Add your static IP address or several IP addresses (for example if your PBX is connected to 2 Internet channels: main and reserve).

In order to verify your IP address, it is necessary to route a call to the server sip.zadarma.com through the number 8888

After your IP address verification, you will be able to make outgoing calls by sending INVITE to us with your desired CallerID number in From: field. This makes the setup with multiple numbers significantly easier, and simplifies the understanding of the outgoing routing process.

Edit pjsip.conf

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

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

[zadarma]
type=endpoint
transport=udp-transport
context=zadarma-in
disallow=all
allow=alaw
allow=ulaw
aors=zadarma
from_domain=sip.zadarma.com
direct_media=no

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

Extension number 101 to which softphone/IP-phone will be connected to receive incoming and to make 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
Calls routing is set in file extensions.conf

[zadarma-in]
;incoming calls are routed on extension number 101
exten => 15555555555,1, Dial(PJSIP/101)                 

[zadarma-out]

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

;CallerID setup 15555555555
exten => _XXX.,1,Set(CALLERID(num)=15555555555)         
same => n,Dial(PJSIP/${EXTEN}@zadarma)

Setup is finished.