{"id":441,"date":"2012-08-29T01:00:00","date_gmt":"2012-08-28T23:00:00","guid":{"rendered":"https:\/\/www.fussylogic.co.uk\/blog\/?p=441"},"modified":"2012-09-27T22:18:23","modified_gmt":"2012-09-27T21:18:23","slug":"asterisk-for-a-small-business-i","status":"publish","type":"post","link":"https:\/\/www.fussylogic.co.uk\/blog\/?p=441","title":{"rendered":"Asterisk For a Small Business (I)"},"content":{"rendered":"<p>FussyLogic is a small business. I run it from a home office. Most of my incoming phone calls are to my mobile; but I want to have a landline presence for the business too. It\u00e2\u20ac\u2122s not cost effective to pay for an additional land line from BT just for those rare landline calls. I choose then to have a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Voice_over_Internet_Protocol\">VoIP<\/a> line. I use <a href=\"http:\/\/www.voiptalk.org\/\">voiptalk<\/a>, and buy a non-geo 0845 number from them. For my convenience I also have an VoIP line for for the residential line as well and an 0845 to go with that.<\/p>\n<p>I could just use a dual line VoIP converter, like the Grandstream <a href=\"http:\/\/www.voip-info.org\/wiki\/view\/HT-486\">Handytone 486<\/a> and point the two lines at the two accounts. However, I\u00e2\u20ac\u2122d like to gain some facilities from my use of VoIP not just emulate the analogue telephone system. Here\u00e2\u20ac\u2122s what I want(ed):<\/p>\n<ul>\n<li>Phones not equal to phone lines. I\u00e2\u20ac\u2122d like PBX facilities were I can call one phone from another within the house.<\/li>\n<li>Mobiles-as-extensions. Both I and my wife have Android phones. They\u00e2\u20ac\u2122re powerful enough to act as IP phones in themselves. When I\u00e2\u20ac\u2122m in the house I would like to be able to answer the house phone using my mobile. My mobile is always with me, so why should I have to go running for physical phone?<\/li>\n<li>Independent voicemail for residence and business.<\/li>\n<\/ul>\n<p>The key to getting me these facilities is the Asterisk telephony server software. Asterisk is incredibly powerful but can also be complicated to configure. I\u00e2\u20ac\u2122m going to walk you through my phone system setup, step by step in the hopes that describing a system configuration from scratch will clarify all the dark corners of Asterisk that might be stopping you from using it.<\/p>\n<h2 id=\"nomenclature\">Nomenclature<\/h2>\n<p>One of the most difficult hurdles to get over when starting with IP telephony is knowing what the words mean. I\u00e2\u20ac\u2122ll try not to use any term that I haven\u00e2\u20ac\u2122t defined here.<\/p>\n<dl>\n<dt><a href=\"http:\/\/en.wikipedia.org\/wiki\/Session_Initiation_Protocol\">SIP<\/a><\/dt>\n<dd>\n<p>SIP is the standard telephony protocol for the Internet. It\u00e2\u20ac\u2122s actually a family of protocols, SIP, SDP, and RTP being the main ones. SIP is really just a signalling protocol, it lets one device tell another than it would like to establish a communication channel. In some ways it\u00e2\u20ac\u2122s a little like SMTP is for email, but with SMTP the email is sent in-band. With SIP the actual voice data is sent using RTP.<\/p>\n<\/dd>\n<dt>Trunk<\/dt>\n<dd>\n<p>Think of this as meaning a phone line. Your BT phone socket is your \u00e2\u20ac\u0153trunk\u00e2\u20ac\u009d in the analogue world. In the internet telephony world a trunk is an endpoint that you make calls on \u00e2\u20ac\u201c it\u00e2\u20ac\u2122s the external receiver of the phone number you dial.<\/p>\n<\/dd>\n<dt>Extension<\/dt>\n<dd>\n<p>This is one of your local phones. It\u00e2\u20ac\u2122s the device you dial a number on. In Asterisk parlance this sometimes means the dialstring \u00e2\u20ac\u201c i.e.\u00c2\u00a0what was dialled.<\/p>\n<\/dd>\n<dt><a href=\"http:\/\/en.wikipedia.org\/wiki\/Foreign_exchange_station#Foreign_eXchange_Station\">FXS<\/a><\/dt>\n<dd>\n<p>Foreign eXchange Service. An analogue phone system interface that pretends to be a phone line. Suitable for connecting analogue phones to (i.e.\u00c2\u00a0you plug your phone into it).<\/p>\n<\/dd>\n<dt><a href=\"http:\/\/en.wikipedia.org\/wiki\/Foreign_exchange_office#Foreign_eXchange_Office\">FXO<\/a><\/dt>\n<dd>\n<p>Foreign eXchange Object. An analogue phone system interface that pretends to be a phone. Suitable for connecting to a phone line (i.e.\u00c2\u00a0you connect it to your phone company socket).<\/p>\n<\/dd>\n<dt><a href=\"http:\/\/en.wikipedia.org\/wiki\/Analog_telephone_adapter\">ATA<\/a><\/dt>\n<dd>\n<p>Analogue telephone adaptor. Essentially a device with one or more FXS ports on it. It\u00e2\u20ac\u2122s job is to turn a standard analogue phone into a SIP phone.<\/p>\n<\/dd>\n<\/dl>\n<h2 id=\"server\">Server<\/h2>\n<p>The first step is to install Asterisk. I\u00e2\u20ac\u2122m on Debian and use <code>apt-get<\/code>, but the idea\u00e2\u20ac\u2122s the same whatever you use.<\/p>\n<pre><code>$ apt-get install asterisk asterisk-voicemail<\/code><\/pre>\n<p>We\u00e2\u20ac\u2122ll be editing the configuration files stored in <code>\/etc\/asterisk<\/code>, there are a scary-looking number of them. Don\u00e2\u20ac\u2122t be scared though, the large number is merely a symptom of Asterisk\u00e2\u20ac\u2122s flexibility. We\u00e2\u20ac\u2122re going to be concerned primarily with two of these files:<\/p>\n<ul>\n<li><code>\/etc\/asterisk\/sip.conf<\/code><\/li>\n<li><code>\/etc\/asterisk\/extensions.conf<\/code><\/li>\n<\/ul>\n<p>We\u00e2\u20ac\u2122ll touch a few others briefly, but the majority of your Asterisk configuration is done in these files.<\/p>\n<h2 id=\"trunks\">Trunks<\/h2>\n<p>Let\u00e2\u20ac\u2122s begin by getting ourselves access to our trunk lines. You can sign up with any VoIP SIP provider you like. You will need from them the following pieces of information (at least):<\/p>\n<ul>\n<li>Username\/phonenumber (almost certainly the same). The phone number here is <em>not<\/em> a number on the BT network. For now consider it as a private number within your VoIP provider\u00e2\u20ac\u2122s network.<\/li>\n<li>Secret (password for that number). Obviously you don\u00e2\u20ac\u2122t want anyone who knows your phone number to be able to make calls on your dime, or in fact to receive your incoming calls. The secret is what allows you to prove the number is yours.<\/li>\n<li>SIP contact host, this is the host that your username and password get sent to. Think of this as equivalent to the \u00e2\u20ac\u0153www.facebook.com\u00e2\u20ac\u009d you type in the address bar of your browser.<\/li>\n<li>Outbound proxy. Almost certainly your home network will be behind a firewall (if it\u00e2\u20ac\u2122s not it should be). Firewalls and IP telephony do not go well together. The workaround for these problems is a proxy machine, that acts on your behalf outside of your firewall.<\/li>\n<\/ul>\n<p>Open up <code>sip.conf<\/code>. Comment out everything not in the <code>[general]<\/code> (you will find most of this file commented out anyway, a large part of the asterisk documentation is in the config files themselves; which only adds to the seeming complexity).<\/p>\n<p>I\u00e2\u20ac\u2122ve got two lines from voiptalk, and so I make use of the template facility in Asterisk\u00e2\u20ac\u2122s <code>sip.conf<\/code>. Like this:<\/p>\n<pre><code>; Providers\n[voiptalk](!)\n    ; &#39;peer&#39; because it won&#39;t be authenticating to us\n    type=peer\n    dtmfmode=rfc2833\n    host=voiptalk.org\n    fromdomain=voiptalk.org\n    outboundproxy=nat.voiptalk.org:5065\n    insecure=port,invite\n    canreinvite=no\n    ; voiptalk codecs\n    disallow=all\n    allow=g729\n    allow=ulaw\n    allow=gsm\n    allow=g723\n    allow=ilbc<\/code><\/pre>\n<p>The \u00e2\u20ac\u0153!\u00e2\u20ac\u009d indicates to Asterisk that this is a template not an actual SIP endpoint \u00e2\u20ac\u201c I\u00e2\u20ac\u2122m using it to describe things that are common to <em>all<\/em> voiptalk accounts. The allowed codecs are something you have to look up from your provider, they\u00e2\u20ac\u2122ll support what they support, just list them as I have done here and then forget about them; similarly the DTMF mode and outbound proxy. The most important item from Asterisk\u00e2\u20ac\u2122s perspective is the \u00e2\u20ac\u0153<code>type=peer<\/code>\u00e2\u20ac\u009d line. Finding out what the different <code>type<\/code>s mean from Asterisk docs is very difficult. In essence, think of it like this: we do not expect a peer to try to register with us using a username and password. Incoming calls from this peer will be identified by matching their source IP address (and the \u00e2\u20ac\u0153<code>host=<\/code>\u00e2\u20ac\u009d parameter specifies that address).<\/p>\n<p>Now we have specified the common settings for this provider, we\u00e2\u20ac\u2122ll make two SIP endpoints using it. Firstly I should point out that the documentation in <code>sip.conf<\/code> is incredibly confusing. You should ignore the entire section about <code>register=&gt;<\/code> as that is not the appropriate way of registering for our sort of setup. Instead, add a section for each of your trunk lines as follows:<\/p>\n<pre><code>[voiptalkRESIDENTIAL](voiptalk)\n    defaultuser=111111111\n    secret=your_111111111_secret_goes_here\n    fromuser=111111111\n    ; context that handles calls from this device\n    context=external\n    ; Adding this option triggers registration so &#39;register=&gt;&#39; is not needed\n    ; all incoming calls from this remote are treated as if it dialled this\n    ; extension\n    callbackextension=trunkRESIDENTIAL<\/code><\/pre>\n<p>That\u00e2\u20ac\u2122s my residential line. Note the top line<\/p>\n<pre><code>[voiptalkRESIDENTIAL](voiptalk)<\/code><\/pre>\n<p>The \u00e2\u20ac\u0153<code>[name]<\/code>\u00e2\u20ac\u009d is just a name, and isn\u00e2\u20ac\u2122t used by Asterisk (but make sure you do not use fully qualified domain name as the endpoint) other than for identifying this endpoint to you, the human. The \u00e2\u20ac\u0153<code>(voiptalk)<\/code>\u00e2\u20ac\u009d following it tells Asterisk to import the earlier \u00e2\u20ac\u0153<code>[voiptalk]<\/code>\u00e2\u20ac\u009d section in this definition. This is what saves us repeating settings for one provider. Particularly important is the \u00e2\u20ac\u0153<code>callbackextension<\/code>\u00e2\u20ac\u009d. When Asterisk finds this option present, it tries to register using the given username and secret with the <code>host=<\/code> machine.<\/p>\n<p>Add another similar section for your business line.<\/p>\n<pre><code>[voiptalkOFFICE](voiptalk)\n    defaultuser=222222222\n    secret=your_222222222_secret_goes_here\n    fromuser=222222222\n    context=external\n    callbackextension=trunkOFFICE<\/code><\/pre>\n<p>Note again the use of the template so we only need to specify information specific to this endpoint.<\/p>\n<p>Save these changes and open up Asterisk\u00e2\u20ac\u2122s command line interface.<\/p>\n<pre><code>$ asterisk -r\nAsterisk 1.8.13.0~dfsg-1+b1, Copyright (C) 1999 - 2012 Digium, Inc. and others.\nCreated by Mark Spencer &lt;markster@digium.com&gt;\nAsterisk comes with ABSOLUTELY NO WARRANTY; type &#39;core show warranty&#39; for details.\nThis is free software, with components licensed under the GNU General Public\nLicense version 2 and other licenses; you are welcome to redistribute it under\ncertain conditions. Type &#39;core show license&#39; for details.\n=========================================================================\nConnected to Asterisk 1.8.13.0~dfsg-1+b1 currently running on hostname (pid = 27724)\nhostname*CLI&gt;<\/code><\/pre>\n<p>The <code>help<\/code> command will show you all the asterisk commands, but we\u00e2\u20ac\u2122re only interested at present in reading our new configuration and checking it\u00e2\u20ac\u2122s working.<\/p>\n<pre><code>hostname*CLI&gt; reload\nhostname*CLI&gt; sip show registry\nHost                dnsmgr Username  Refresh State       Reg.Time                 \nvoiptalk.org:5060   N      111111111     105 Registered  Wed, 29 Aug 2012 20:33:21\nvoiptalk.org:5060   N      222222222     105 Registered  Wed, 29 Aug 2012 20:33:21\n2 SIP registrations.<\/code><\/pre>\n<p>We\u00e2\u20ac\u2122ve successfully registered with our SIP provider for two trunk lines. These registrations are what makes the remote allow outbound calls from us, and direct incoming calls for those usernames to us. If someone were now to SIP dial <code>111111111@voiptalk.org<\/code> our Asterisk server would receive that call. We haven\u00e2\u20ac\u2122t, as yet, got enough configuration for anything to happen to that call. Presence in the above list is (unintuitively) triggered by the <code>callbackextension<\/code> option in the endpoint defintion.<\/p>\n<p>Presence in the following list is triggered by being an endpoint set as a peer:<\/p>\n<pre><code>hostname*CLI&gt; sip show peers\nName\/username              Host         Dyn Forcerport ACL Port  Status\nvoiptalkOFFICE\/222222222   77.240.48.94      N             5060  Unmonitored\nvoiptalkRESIDENTIAL\/11111  77.240.48.94      N             5060  Unmonitored\n2 sip peers [Monitored: 0 online, 0 offline Unmonitored: 2 online, 0 offline]<\/code><\/pre>\n<p>This tells Asterisk that calls from 77.240.48.94 to the 222222222 username will be handled using the <code>voiptalkOFFICE<\/code> endpoint declaration. Let\u00e2\u20ac\u2122s look again at that declaration.<\/p>\n<pre><code>[voiptalkOFFICE](voiptalk)\n    defaultuser=222222222\n    secret=your_222222222_secret_goes_here\n    fromuser=222222222\n    context=external\n    callbackextension=trunkOFFICE<\/code><\/pre>\n<p><code>context<\/code> and <code>callbackextension<\/code> tell asterisk what to do with incoming calls from this endpoint. Outbound calls are routed to this endpoint using the \u00e2\u20ac\u0153<code>SIP\/voiptalkOFFICE<\/code>\u00e2\u20ac\u009d syntax in the dial plan.<\/p>\n<p>We\u00e2\u20ac\u2122ll return to this in more detail after we\u00e2\u20ac\u2122ve covered setting up our local phones in the next article.<\/p>\n<p><a href=\"?p=441\">asterisk1<\/a> <a href=\"?p=443\">asterisk2<\/a> <a href=\"?p=445\">asterisk3<\/a> <a href=\"?p=447\">asterisk4<\/a> <a href=\"?p=449\">asterisk5<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>FussyLogic is a small business. I run it from a home office. Most of my incoming phone calls are to my mobile; but I want to have a landline presence for the business too. It\u00e2\u20ac\u2122s not cost effective to pay for an additional land line from BT just for those rare landline calls. I choose\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.fussylogic.co.uk\/blog\/?p=441\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[31,6],"_links":{"self":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/441"}],"collection":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=441"}],"version-history":[{"count":6,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/441\/revisions"}],"predecessor-version":[{"id":767,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/441\/revisions\/767"}],"wp:attachment":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}