<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Connecting Two Asterisk Boxes Together via SIP</title><link rel="stylesheet" href="styles.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.69.1" /><link rel="start" href="index.html" title="Asterisk™: The Future of Telephony" /><link rel="up" href="asterisk-CHP-4.html" title="Chapter 4. Initial Configuration of Asterisk" /><link rel="prev" href="I_sect14_tt599.html" title="Connecting to a SIP Service Provider" /><link rel="next" href="I_sect14_tt645.html" title="Configuring an IAX Softphone" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Connecting Two Asterisk Boxes Together via SIP</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="I_sect14_tt599.html">Prev</a> </td><th width="60%" align="center">Chapter 4. Initial Configuration of Asterisk</th><td width="20%" align="right"> <a accesskey="n" href="I_sect14_tt645.html">Next</a></td></tr></table><hr /></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="connecting_two_asterisk"></a>Connecting Two Asterisk Boxes Together via SIP</h2></div></div></div><p>There may come a time<a id="ch04_siptwo" class="indexterm"></a> 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.</p><div class="sidebar"><a id="I_sidebar4_tt624"></a><p class="title"><b>Configuring a Local Firewall</b></p><p>If you’re running <a id="I_indexterm4_tt625" class="indexterm"></a>iptables on the same machine as the Asterisk box, then you can run the following commands to open port 5060 for SIP signaling, and ports 10,000 through 20,000 for the RTP traffic. You can also narrow the range <a id="I_indexterm4_tt626" class="indexterm"></a>of RTP ports in the <span class="emphasis"><em>rtp.conf</em></span> file located in <span class="emphasis"><em>/etc/asterisk</em></span>. An excellent book on iptables firewalls <a id="I_indexterm4_tt627" class="indexterm"></a><a id="I_indexterm4_tt628" class="indexterm"></a><a id="I_indexterm4_tt629" class="indexterm"></a>is <span class="emphasis"><em>Linux Firewalls</em></span> by Steve Suehring and Robert Ziegler (Novell Press):</p><p><a id="I_programlisting4_tt630"></a></p><pre class="programlisting"># <strong class="userinput"><code>iptables -I RH-Firewall-1-INPUT -p udp --dport 5060 -j ACCEPT</code></strong> # <strong class="userinput"><code>iptables -I RH-Firewall-1-INPUT -p udp --dport 10000:20000 -j ACCEPT</code></strong> # <strong class="userinput"><code>service iptables save</code></strong></pre><p>Be aware that this will allow all UDP traffic from any source access to ports 5060 and 10,000 through 20,000.</p></div><p>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 <a href="connecting_two_asterisk.html#figure_4_5" title="Figure 4.5. SIP trunking topology">Figure 4.5, “SIP trunking topology”</a>). 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.</p><div class="figure"><a id="figure_4_5"></a><p class="title"><b>Figure 4.5. SIP trunking topology</b></p><div class="mediaobject"><a id="I_mediaobject4_tt631"></a><img src="figs/web/ast2_0405.png" alt="SIP trunking topology" /></div></div><p>First, let’s configure our Asterisk boxes.</p><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="id4121686"></a>Configuring Our Asterisk Boxes</h3></div></div></div><p>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 <span class="emphasis"><em>sip.conf</em></span> file <a id="I_indexterm4_tt632" class="indexterm"></a>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.</p><p>Here is the configuration for the Toronto box:</p><p><a id="I_programlisting4_tt633"></a></p><pre class="programlisting">[general] register => toronto:welcome@192.168.1.101/osaka [osaka] type=friend secret=welcome context=osaka_incoming host=dynamic disallow=all allow=ulaw </pre><p>And the configuration for the Osaka box:</p><p><a id="I_programlisting4_tt634"></a></p><pre class="programlisting">[general] register => osaka:welcome@192.168.2.202/toronto [toronto] type=friend secret=welcome context=toronto_incoming host=dynamic disallow=all allow=ulaw </pre><p>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.</p><p>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:</p><p><a id="I_programlisting4_tt635"></a></p><pre class="programlisting">[Apr 22 18:52:32] WARNING[23631]: chan_sip.c:8117 check_auth: username mismatch, have <toronto>, digest has <s></pre><p>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.</p><p>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 <code class="literal">[osaka]</code> authorization block, and on the Osaka box, we have the <code class="literal">[toronto]</code> block. We define the type as a <code class="literal">friend</code>, which allows us to both receive and place calls from the other Asterisk box. The <code class="literal">secret</code> is the password the other system should use when authenticating. The <code class="literal">context</code> is where incoming calls are processed in the dialplan (<span class="emphasis"><em>extensions.conf</em></span>). We set the <code class="literal">host</code> parameter to <code class="literal">dynamic</code>, 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 <code class="literal">disallow</code> and <code class="literal">allow</code> parameters control the codecs we wish to use with the other end.</p><p>If you save the file and reload the SIP channel on both Asterisk boxes (<strong class="userinput"><code>sip reload</code></strong> from the Asterisk console), you should see something like the following, which will tell you the remote box successfully registered:</p><p> <a id="I_programlisting4_tt636"></a></p><pre class="programlisting">*CLI> -- Saved useragent "Asterisk PBX" for peer toronto</pre><p> </p><p>You should see the status of the Host change from (<code class="literal">Unspecified</code>) to the IP address of the remote box when you run <code class="literal">sip show peers</code>:</p><p><a id="I_programlisting4_tt637"></a></p><pre class="programlisting">*CLI> <strong class="userinput"><code>sip show peers</code></strong> Name/username Host Dyn Nat ACL Port Status toronto/osaka 192.168.2.202 D 5060 Unmonitored</pre><p>You can verify that your own registration was successful by running <code class="literal">sip show</code><code class="literal">registry</code> from the Asterisk console:</p><p><a id="I_programlisting4_tt638"></a></p><pre class="programlisting">*CLI> <strong class="userinput"><code>sip show registry</code></strong> Host Username Refresh State Reg.Time 192.168.1.101:5060 osaka 105 Registered Sun, 22 Apr 2007 19:13:20</pre><p>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.</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="id4121946"></a>SIP Phone Configuration</h3></div></div></div><p>See the <a href="asterisk-CHP-4-SECT-6.html" title="Configuring an FXS Channel for an Analog Telephone">the section called “Configuring an FXS Channel for an Analog Telephone”</a>” section of this chapter for more information about configuring SIP phones with Asterisk. Below is the configuration for two SIP phones in the <span class="emphasis"><em>sip.conf</em></span> 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 <span class="emphasis"><em>sip.conf</em></span> file on each respective server.</p><p>Toronto <span class="emphasis"><em>sip.conf</em></span>:</p><p><a id="I_programlisting4_tt639"></a></p><pre class="programlisting">[1000] type=friend host=dynamic context=phones</pre><p>Osaka <span class="emphasis"><em>sip.conf</em></span>:</p><p><a id="I_programlisting4_tt640"></a></p><pre class="programlisting">[1001] type=friend host=dynamic context=phones</pre><p>You should now have extension 1000 registered to Toronto, and extension 1001 registered to Osaka. You can verify this with the <code class="literal">sip show peers</code> command from the Asterisk console. Next, we’re going to configure the dialplan logic that will allow us to call between the extensions.</p></div><div class="sect2" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="id4122019"></a>Configuring the Dialplan</h3></div></div></div><p>Now we can configure a simple dialplan<a id="I_indexterm4_tt641" class="indexterm"></a> for each server allowing us to call between the two phones we have registered: one to Toronto, the other to Osaka. In the <a href="asterisk-CHP-4-SECT-2.html" title="Working with Interface Configuration Files">the section called “Working with Interface Configuration Files”</a>” section of this chapter, we asked you to create a simple <code class="filename">extensions.conf</code> 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.</p><p>Toronto <code class="filename">extensions.conf</code>:</p><a id="I_programlisting4_tt642"></a><pre class="programlisting">[globals] [general] autofallthrough=yes [default] [incoming_calls] [phones] include => internal <span class="emphasis"><em>include => remote </em></span><span class="emphasis"><em>[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</em></span></pre><p>Osaka <code class="filename">extensions.conf</code>:</p><a id="I_programlisting4_tt643"></a><pre class="programlisting">[globals] [general] autofallthrough=yes [default] [incoming_calls] [phones] include => internal <span class="emphasis"><em>include => remote</em></span> [internal] <span class="emphasis"><em>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</em></span></pre><p>Once you’ve configured your <code class="filename">extensions.conf</code> file, you can reload it from the Asterisk console with the <code class="literal">dialplan reload</code> command. Verify your dialplan loaded with the <code class="literal">dialplan show</code> command.</p><p>And that’s it! You should be able to place calls between your two Asterisk servers now.<a id="I_indexterm4_tt644" class="indexterm"></a></p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="I_sect14_tt599.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="asterisk-CHP-4.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="I_sect14_tt645.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Connecting to a SIP Service Provider </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Configuring an IAX Softphone</td></tr></table></div><div xmlns="" id="svn-footer"><hr /><p>You are reading <em>Asterisk: The Future of Telephony</em> (2nd Edition for Asterisk 1.4), by Jim van Meggelen, Jared Smith, and Leif Madsen.<br /> This work is licensed under the <a href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative Commons Attribution-Noncommercial-No Derivative Works License v3.0</a>.<br /> To submit comments, corrections, or other contributions to the text, please visit <a href="http://oreilly.com/catalog/9780596510480/">http://www.oreilly.com/</a>.</p></div></body></html>