📜 ⬆️ ⬇️

How to connect two asterisk servers (part one. SIP)

image So, we have two asterisks.
The task is to organize direct dialing through the prefix there and back.
Initial data:
Asterisk 1.4 at both ends
kazan.asterisk.ru is the name of the first asterisk.
volgograd.asterisk.ru - the name of the second asterisk.
It is assumed that both asterisks have direct access to the Internet (otherwise, there should be no problems, you need to configure NAT and use the nat = yes parameter)

Let the 1st asterisk be in Kazan, the other in Volgograd. Let us turn to the car codes of the regions.
Then dialing from Volgograd will be 9-16- <number>.
From Kazan 9-34- <number>.

sip.conf 1st Asterisk:
[general]
context=default
allowguest=no
bindport=5060
bindaddr=0.0.0.0

; -
register => kazan:kazan_password@volgograd.asterisk.ru:5060

[volgograd]
;
username=volgograd
secret=volgograd_password
;
type=friend

; INVITE
canreinvite=no
; .
insecure=very
;
qualify=yes

;
; (www.voip-info.org): If you want the phone to register itself, use the keyword dynamic instead of Host IP.
; deny,permit
host=dynamic

;DTMF
dtmfmode=rfc2833

;
disallow=all
allow=alaw
allow=ulaw

;
context=office_rules


extension.conf 1 st asterisk:
;
[office]
exten => _934.,1,Set(CALLERID(all)="Kazan <16>")
exten => _934.,n,Dial(SIP/${EXTEN:3}@volgograd,60,r)
exten => _934.,n,HangUp
..

include => office_rules

;
; 1XX 2XX
[office_rules]
exten => _[12]XX,1,Dial(SIP/${EXTEN},60,tTr)
exten => _[12]XX,n,HangUp()


')
sip.conf 2nd Asterisk:
[general]
context=default
allowguest=no
bindport=5060
bindaddr=0.0.0.0

; -
register => volgograd:volgograd_password@kazan.asterisk.ru:5060

[kazan]
type=friend

; credentials for registration
username=kazan
secret=kazan_password

;
; (www.voip-info.org): If you want the phone to register itself, use the keyword dynamic instead of Host IP.
; deny,permit
host=dynamic

; INVITE
canreinvite=no
; .
insecure=very
;
qualify=yes

; DTMF
dtmfmode=rfc2833

; ( G711)
disallow=all
allow=ulaw
allow=alaw

;
context=office_rules



extension.conf 2nd Asterisk:
;
[office]
exten => _916.,1,Set(CALLERID(all)="Volgograd <34>")
exten => _916.,n,Dial(SIP/${EXTEN:3}@kazan,60,r)
exten => _916.,n,HangUp
..

include => office_rules

;
; 1XX 2XX
[office_rules]
exten => _[12]XX,1,Dial(SIP/${EXTEN},60,tTr)
exten => _[12]XX,n,HangUp()



Ps. I would appreciate tips on extending functionality and security.

upd: In any case, in terms of the security aspect, you need to look at it .

A few comments.
If you have some experience with asterisk, then you should have a question.
How is the context determined for outgoing calls?
Record
context=office_rules

only works on incoming calls. So, in this case, on the receiving side, the asterisk sees that there is a peer in the system, which has the same IP address as the client that makes the call. And it takes its context.

And further. Nobody bothers you to specify several register if you have several providers. The essence of register is to tell you exactly where you are. If you say “you are here” 2 or more times, there will be no problems and moreover, you will be insured against interruptions of one of the providers.

Source: https://habr.com/ru/post/107668/


All Articles