There may come a time when you have a pair of Asterisk boxes, and you’d like to pass calls between them. Luckily this isn’t very difficult, although it does have some oddities that we need to deal with, but from the configuration viewpoint it isn’t really all that difficult.
Our topology will consist of a SIP phone (Alice) registered to Asterisk A (Toronto), and a separate SIP phone (Bob) registered to Asterisk B (Osaka). At the end of this section, you will be able to set up a call from Alice to Bob (and vice versa) through your pair of Asterisk boxes (see Figure 4.5, “SIP trunking topology”). This is a common scenario when you have two physical locations, such as a company with multiple offices that wants a single logical extension topology.
First, let’s configure our Asterisk boxes.
We have a pair of Asterisk boxes that we’re going to call Toronto and Osaka and that we’re going to have register to each other. We’re going to use the most basic sip.conf file that will work in this scenario. Just like the SIP phone configuration earlier in this chapter, it’s not necessarily the best way to do it, but it’ll work.
Here is the configuration for the Toronto box:
[general] register => toronto:welcome@192.168.1.101/osaka [osaka] type=friend secret=welcome context=osaka_incoming host=dynamic disallow=all allow=ulaw
And the configuration for the Osaka box:
[general] register => osaka:welcome@192.168.2.202/toronto [toronto] type=friend secret=welcome context=toronto_incoming host=dynamic disallow=all allow=ulaw
Many of the previous options may be familiar to you by now, but let’s take a look at them further just in case they are not.
The second line of the file tells our Asterisk box to register to the other box, with the purpose of telling the remote Asterisk box where to send calls when it wishes to send a call to our local Asterisk box. Remember how we mentioned a little oddity in the configuration? Notice that at the end of the registration line we tag on a forward slash and the username of the remote Asterisk box? What this does is tell the remote Asterisk box what digest name to use when it wants to set up a call. If you forget to add this, then when the far end tries to send you a call, you’ll see the following at your Asterisk CLI:
[Apr 22 18:52:32] WARNING[23631]: chan_sip.c:8117 check_auth: username mismatch, have <toronto>, digest has <s>
So by adding the forward slash and username, we tell the other end what to place in the Digest username of the Proxy Authorization field in the SIP INVITE message.
The rest of the file is the authorization block we use to control
the incoming and outgoing calls from the other Asterisk box. On the
Toronto box, we have the [osaka]
authorization block,
and on the Osaka box, we have the [toronto]
block. We
define the type as a friend
, which allows us to both
receive and place calls from the other Asterisk box. The
secret
is the password the other system should use
when authenticating. The context
is where incoming
calls are processed in the dialplan
(extensions.conf). We set the
host
parameter to dynamic
, which
tells our Asterisk box that the other endpoint will register to us,
thereby telling us what IP address to set up calls when we want to send
a call to the other end. Finally, the disallow
and
allow
parameters control the codecs we wish to use
with the other end.
If you save the file and reload the SIP channel on both Asterisk
boxes (sip reload
from the
Asterisk console), you should see something like the following, which
will tell you the remote box successfully registered:
*CLI> -- Saved useragent "Asterisk PBX" for peer toronto
You should see the status of the Host change from
(Unspecified
) to the IP address of the remote box
when you run sip show peers
:
*CLI> sip show peers
Name/username Host Dyn Nat ACL Port Status
toronto/osaka 192.168.2.202 D 5060 Unmonitored
You
can verify that your own registration was successful by running
sip show
registry
from the Asterisk
console:
*CLI> sip show registry
Host Username Refresh State Reg.Time
192.168.1.101:5060 osaka 105 Registered Sun, 22 Apr 2007 19:13:20
Now that our Asterisk boxes are happy with each other, let’s configure a couple of SIP phones so we can call between the boxes.
See the the section called “Configuring an FXS Channel for an Analog Telephone”” section of this chapter for more information about configuring SIP phones with Asterisk. Below is the configuration for two SIP phones in the sip.conf file for each server, which we’ll be referencing from the dialplan in the next section, thereby giving us two endpoints to call between. Append this configuration to the end of the sip.conf file on each respective server.
Toronto sip.conf:
[1000] type=friend host=dynamic context=phones
Osaka sip.conf:
[1001] type=friend host=dynamic context=phones
You should now have extension 1000 registered
to Toronto, and extension 1001 registered to Osaka. You can verify this
with the sip show peers
command from the Asterisk
console. Next, we’re going to configure the dialplan logic that will
allow us to call between the extensions.
Now we can configure a simple dialplan for each server allowing us to call between the two
phones we have registered: one to Toronto, the other to Osaka. In the
the section called “Working with Interface Configuration Files”” section of this chapter, we
asked you to create a simple extensions.conf
file. We are going to build
up a dialplan based on this simple configuration. The dialplan for each
server will be very similar to the other one, but for clarity we will
show both. The new lines we’re adding to the file will be
italicized.
Toronto extensions.conf
:
[globals] [general] autofallthrough=yes [default] [incoming_calls] [phones] include => internal include => remote [internal] exten => _2XXX,1,NoOp() exten => _2XXX,n,Dial(SIP/${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(SIP/osaka/${EXTEN}) exten => _1XXX,n,Hangup() [osaka_incoming] include => internal
Osaka extensions.conf
:
[globals] [general] autofallthrough=yes [default] [incoming_calls] [phones] include => internal include => remote [internal] exten => _1XXX,1,NoOp() exten => _1XXX,n,Dial(SIP/${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(SIP/toronto/${EXTEN}) exten => _2XXX,n,Hangup() [toronto_incoming] include => internal
Once you’ve configured your extensions.conf
file, you can reload it from
the Asterisk console with the dialplan reload
command. Verify your dialplan loaded with the dialplan
show
command.
And that’s it! You should be able to place calls between your two Asterisk servers now.