Often it is desirable to connect two physical Asterisk boxes together via IAX in order to send calls between two physical locations (the distance between these locations may be centimeters or kilometers). One of the advantages to using the IAX protocol to do this is a feature called trunking, which utilizes a method of sending the voice data for multiple calls at once with a single header. This has little effect on only one or two simultaneous calls, but if you are sending tens or hundreds of calls between two locations, the bandwidth savings by utilizing trunking can be tremendous.
You will need a timing interface installed on your system, whether it be hardware from Digium or via the kernel by using the ztdummy driver. This will require you to have Zaptel installed on your system and running. See Chapter 3, Installing Asterisk for more information about installing Zaptel.
We’ll be utilizing a simple topology where we have two Asterisk boxes registered to each other directly, and separate phones registered to each Asterisk box. We’ll call the two Asterisk boxes Toronto and Osakafi (see the section called “Connecting Two Asterisk Boxes Together via SIP””). Bob’s phone will be registered and connected to Toronto, while Alice’s phone will be registered and connected to Osaka.
[PROD: I've commented out figure 4_8 as there's no image file for it...—DCPS]
[PROD: fileref for figure 4_8 was out of sequence (pointing to ast2_0407.pdf|png); I changed it to ast2_0408.pdf|png—DCPS]
The first thing we want to do is create a new channel file (iax.conf) by renaming the current sample file to iax.conf.sample and creating a new blank iax.conf:
#cd /etc/asterisk
#mv iax.conf iax.conf.sample
#touch iax.conf
Next, open up the iax.conf file and enter the following configuration on the Toronto Asterisk box:
[general] autokill=yes register => toronto:welcome@192.168.1.107 [osaka] type=friend host=dynamic trunk=yes secret=welcome context=incoming_osaka deny=0.0.0.0/0.0.0.0 permit=192.168.1.107/255.255.255.255
autokill=yes
was explained in the previous section, but its purpose is to make sure
new calls being set up to a remote system that are not acknowledged
within a reasonable amount of time (two seconds by default) are torn
down correctly. This saves us from having a lot of hung channels simply
waiting for an acknowledgement that probably isn’t coming.
The register
line is used to tell the remote
Asterisk box where we are so that when the box at 192.168.1.107 is ready
to send us a call, it sends it to our IP address (in this case our IP
address is 192.168.1.104, which you’ll see in the iax.conf
configuration of the Osaka box). We
send the username Toronto
and the password
welcome
to Osaka, which authenticates our
registration, and if accepted, writes the location of our Asterisk box
into its memory for when it needs to send us a call.
The [Osaka]
definition
is used to control the authentication of the remote box
and delivery into our dialplan. Osaka is the
username used in the incoming authentication. We set the
type
to friend
because we want to
have both the ability to send calls to Osaka and to receive calls from
Osaka. The host
option is set to
dynamic
which tells Asterisk to send calls to the IP
address obtained when the opposite endpoint registers with us.
In the introduction to this section, we mentioned the possible
bandwidth savings when utilizing IAX2 trunking. It’s simple to enable
this functionality in Asterisk, as we just need to add trunk=yes
to our friend definition. As long as
a timing interface is installed and running (i.e.,
dummy), then we can take advantage of IAX2
trunking.
The secret
is straightforward: it’s our
authentication password. We’re defining the [incoming_osaka]
context as the place we will process incoming calls for this
friend
in the extensions.conf
file. Finally, we block all
IP addresses with the deny
option from being allowed
to authenticate, and explicitly permit 192.168.1.107.
The iax.conf
configuration
for Osaka is nearly identical, except for the changes in IP address and
names:
[general] autokill=yes register => osaka:welcome@192.168.1.104 [toronto] type=friend host=dynamic trunk=yes secret=welcome context=incoming_toronto deny=0.0.0.0/0.0.0.0 permit=192.168.1.104/255.255.255.255
In the the section called “Configure the Softphone”” section, we configured our first IAX2 softphone using idefisk. The configuration we’ll be using here is nearly identical except for minor changes in order to cause the peers to be unique. If you’ve already configured a SIP softphone, then you can also utilize that on one (or both) of the peers. Remember that Asterisk is a multiprotocol application, and you can send a call from a SIP phone to Asterisk, across an IAX2 trunk, and then down to another SIP phone (or H.323, MGCP, etc.).
On Osaka:
[1001] type=friend host=dynamic context=phones
On Toronto:
[2001] type=friend host=dynamic context=phones
Next, configure your IAX2 softphone to register to Asterisk. If the phone successfully registers, you’ll see something like:
*CLI> -- Registered IAX2 '1001' (UNAUTHENTICATED) at 192.168.1.104:4569
In order to allow calling between our two Asterisk boxes over the IAX2 trunk, we need to configure a simple
dialplan. The following dialplan will send all extensions in the 1000
range (1000–1999) to Osaka, and all extensions in the 2000 range
(2000–2999) to Toronto. Our example is going to assume that you have
configured a pair of IAX2 softphones, but feel free to utilize a SIP
phone if you’ve already configured one (or two). Just be aware that
you’ll need to change the Dial()
application to send
the call to the SIP phone via the SIP protocol instead of IAX2 (i.e.
Dial(SIP/${EXTEN},30)
instead of
Dial(IAX2/${EXTEN},30)
).
The extensions.conf
file on
Toronto:
[globals] [general] autofallthrough=yes [default] [incoming_calls] [phones] include => internal include => remote [internal] exten => _1XXX,1,NoOp() exten => _1XXX,n,Dial(IAX2/${EXTEN},30) exten => _1XXX,n,Playback(the-party-you-are-calling&is-curntly-unavail) exten => _1XXX,n,Hangup() [remote] exten => _2XXX,1,NoOp() exten => _2XXX,n,Dial(IAX2/toronto/${EXTEN}) exten => _2XXX,n,Hangup() [toronto_incoming] include => internal
The extensions.conf file on Osaka:
[globals] [general] autofallthrough=yes [default] [incoming_calls] [phones] include => internal include => remote [internal] exten => _2XXX,1,NoOp() exten => _2XXX,n,Dial(IAX2/${EXTEN},30) exten => _2XXX,n,Playback(the-party-you-are-calling&is-curntly-unavail) exten => _2XXX,n,Hangup() [remote] exten => _1XXX,1,NoOp() exten => _1XXX,n,Dial(IAX2/osaka/${EXTEN}) exten => _1XXX,n,Hangup() [osaka_incoming] include => internal