
Article for beginners asteriskovodov.
So, we have two asterisks.
The task is to organize direct dialing through the prefix back and forth on IAX2.
Initial data:
Asterisk 1.4 at both ends
1. samara.asterisk.ru - external DNS name of the first asterisk.
2. kazan.asterisk.ru - external DNS name of the second asterisk. Let him have several providers (for example, kazan2.asterisk.ru, kazan3.asterisk.ru).
Let us turn to the car codes of the regions.
Then dialing from Samara will be 9-16- <number>.
From Kazan 9-63- <number>.
To begin with, I advise you to get acquainted with IAX2
better than SIP for server-2-server interaction.
It does not matter whether asterisks have direct access to the Internet. The main thing is to forward UDP port 4569.
In the
last article I described how to implement SIP communication. Now came the turn of IAX2. Moreover, this protocol was created for this.
')
Another aspect is the use of the correct codec. From personal experience, G729 is best suited. You can find it on the Internet and download it to an asterisk in the CLI interface using the module load codec_g729.so command.
iax.conf of the 1st (Samara) asterisk[general]
disallow=all
allow=g729
allow=gsm
allow=alaw
allow=ulaw
bindaddr=0.0.0.0
calltokenoptional = 0.0.0.0/0.0.0.0
delayreject=yes
jitterbuffer=yes
register => samara:password4samara@kazan.asterisk.ru
register => samara:password4samara@kazan2.asterisk.ru
register => samara:password4samara@kazan3.asterisk.ru
; see tips in www.voip-info.org/wiki/view/Asterisk+config+iax.conf
[guest]
type=user
host=dynamic
; for incoming
[kazan]
type=friend
qualify=yes
auth=md5
trunk=yes
username=kazan
secret=password4kazan
host=dynamic
context=office_rules
extensions.conf of the 1st (Samara) asterisk...
[office]
exten => _916.,1,Set(CALLERID(all)="Samara (num ${CALLERID(num)}) <63>")
exten => _916.,n,NoOp(${CALLERID(all)})
exten => _916.,n,Dial(IAX2/samara:password4samara@kazan/${EXTEN:3},60,tT)
exten => _916.,n,HangUp
...
include => office_rules
[office_rules]
exten => _[12]XX,1,Dial(SIP/${EXTEN},60,tT)
exten => _[12]XX,n,HangUp
iax.conf 2nd (Kazan) asterisk[general]
disallow=all
allow=g729
allow=gsm
allow=alaw
allow=ulaw
bindaddr=0.0.0.0
calltokenoptional = 0.0.0.0/0.0.0.0
delayreject=yes
jitterbuffer=yes
register => kazan:password4kazan@samara.asterisk.ru
; see tips in www.voip-info.org/wiki/view/Asterisk+config+iax.conf
[guest]
type=user
host=dynamic
; for incoming
[samara]
type=friend
qualify=yes
auth=md5
trunk=yes
username=samara
secret=password4samara
host=dynamic
context=office_rules
extensions.conf 2nd (Kazan) asterisk...
[office]
exten => _963.,1,Set(CALLERID(all)="Kazan (num ${CALLERID(num)}) <16>")
exten => _963.,n,NoOp(${CALLERID(all)})
exten => _963.,n,Dial(IAX2/kazan:password4kazan@samara/${EXTEN:3},60,tT)
exten => _963.,n,HangUp
...
include => office_rules
[office_rules]
exten => _[12]XX,1,Dial(SIP/${EXTEN},60,tT)
exten => _[12]XX,n,HangUp
A few comments.
1. It is very important for external subscribers to give the opportunity to call only to internal numbers.
The office context should be described for your office users, in the same place you can describe calls to the city and by intercity.
The office_rules context is used for external subscribers - we only allow there to make calls to internal numbers (3-digit ones that start with 1 or 2).
2. When calling, the following design is used:
Dial(IAX2/login:password@iax-account/...)
The bottom line is that we call with authorization on the server, which was able to register with us for an iax-account account. As in the case of SIP, you can specify several register directives.
3. The example inside the office uses SIP-connected clients.
4. You can view registrations for IAX2 using the iax2 show registry command.
5. For the case if the asterisk is behind NAT. For example, to determine the provider for outgoing traffic, you use separate ah-pi address (for example, 192.168.4.5 - one provider, 192.168.14.5 - another provider), and on the gateway there is a forwarding to the ah-pi address based on the provider.
In this case, in order for the registration to work, you need to add to the peers description on our asterisk:
sourceaddress = 192.168.4.5
sourceaddress = 192.168.14.5
Such a construction on the current version allows to achieve multiple registration of one peer on several providers. Those. roughly speaking, we have the opportunity to say several times that “we have such and such an IP address”.
Example
iax2 show registry:
Host dnsmgr Username Perceived Refresh State
155.15.75.270:4569 N peer1 72.255.69.78:4569 60 Registered
92.14.191.35:4569 N peer1 72.255.69.78:4569 60 Registered