Connecting Two Asterisk Boxes Together via SIP
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.
Figure 4.5. SIP trunking topology
Configuring Our Asterisk Boxes
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=ulawAnd 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=ulawMany 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 showregistry 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.SIP Phone Configuration
Toronto sip.conf:
[1000] type=friend host=dynamic context=phonesOsaka sip.conf:
[1001] type=friend host=dynamic context=phonesYou 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.Configuring the Dialplan
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 => internalOsaka
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 => internalOnce 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.
 
