Asterisk For a Small Business (I)

By | 2012-08-29

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’s not cost effective to pay for an additional land line from BT just for those rare landline calls. I choose then to have a VoIP line. I use voiptalk, 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.

I could just use a dual line VoIP converter, like the Grandstream Handytone 486 and point the two lines at the two accounts. However, I’d like to gain some facilities from my use of VoIP not just emulate the analogue telephone system. Here’s what I want(ed):

  • Phones not equal to phone lines. I’d like PBX facilities were I can call one phone from another within the house.
  • Mobiles-as-extensions. Both I and my wife have Android phones. They’re powerful enough to act as IP phones in themselves. When I’m 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?
  • Independent voicemail for residence and business.

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’m 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.


One of the most difficult hurdles to get over when starting with IP telephony is knowing what the words mean. I’ll try not to use any term that I haven’t defined here.


SIP is the standard telephony protocol for the Internet. It’s 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’s 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.


Think of this as meaning a phone line. Your BT phone socket is your “trunk” in the analogue world. In the internet telephony world a trunk is an endpoint that you make calls on – it’s the external receiver of the phone number you dial.


This is one of your local phones. It’s the device you dial a number on. In Asterisk parlance this sometimes means the dialstring – i.e. what was dialled.


Foreign eXchange Service. An analogue phone system interface that pretends to be a phone line. Suitable for connecting analogue phones to (i.e. you plug your phone into it).


Foreign eXchange Object. An analogue phone system interface that pretends to be a phone. Suitable for connecting to a phone line (i.e. you connect it to your phone company socket).


Analogue telephone adaptor. Essentially a device with one or more FXS ports on it. It’s job is to turn a standard analogue phone into a SIP phone.


The first step is to install Asterisk. I’m on Debian and use apt-get, but the idea’s the same whatever you use.

$ apt-get install asterisk asterisk-voicemail

We’ll be editing the configuration files stored in /etc/asterisk, there are a scary-looking number of them. Don’t be scared though, the large number is merely a symptom of Asterisk’s flexibility. We’re going to be concerned primarily with two of these files:

  • /etc/asterisk/sip.conf
  • /etc/asterisk/extensions.conf

We’ll touch a few others briefly, but the majority of your Asterisk configuration is done in these files.


Let’s 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):

  • Username/phonenumber (almost certainly the same). The phone number here is not a number on the BT network. For now consider it as a private number within your VoIP provider’s network.
  • Secret (password for that number). Obviously you don’t 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.
  • SIP contact host, this is the host that your username and password get sent to. Think of this as equivalent to the “” you type in the address bar of your browser.
  • Outbound proxy. Almost certainly your home network will be behind a firewall (if it’s 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.

Open up sip.conf. Comment out everything not in the [general] (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).

I’ve got two lines from voiptalk, and so I make use of the template facility in Asterisk’s sip.conf. Like this:

; Providers
    ; 'peer' because it won't be authenticating to us
    ; voiptalk codecs

The “!” indicates to Asterisk that this is a template not an actual SIP endpoint – I’m using it to describe things that are common to all voiptalk accounts. The allowed codecs are something you have to look up from your provider, they’ll 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’s perspective is the “type=peer” line. Finding out what the different types 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 “host=” parameter specifies that address).

Now we have specified the common settings for this provider, we’ll make two SIP endpoints using it. Firstly I should point out that the documentation in sip.conf is incredibly confusing. You should ignore the entire section about register=> 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:

    ; context that handles calls from this device
    ; Adding this option triggers registration so 'register=>' is not needed
    ; all incoming calls from this remote are treated as if it dialled this
    ; extension

That’s my residential line. Note the top line


The “[name]” is just a name, and isn’t 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 “(voiptalk)” following it tells Asterisk to import the earlier “[voiptalk]” section in this definition. This is what saves us repeating settings for one provider. Particularly important is the “callbackextension”. When Asterisk finds this option present, it tries to register using the given username and secret with the host= machine.

Add another similar section for your business line.


Note again the use of the template so we only need to specify information specific to this endpoint.

Save these changes and open up Asterisk’s command line interface.

$ asterisk -r
Asterisk, Copyright (C) 1999 - 2012 Digium, Inc. and others.
Created by Mark Spencer <>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
Connected to Asterisk currently running on hostname (pid = 27724)

The help command will show you all the asterisk commands, but we’re only interested at present in reading our new configuration and checking it’s working.

hostname*CLI> reload
hostname*CLI> sip show registry
Host                dnsmgr Username  Refresh State       Reg.Time           N      111111111     105 Registered  Wed, 29 Aug 2012 20:33:21   N      222222222     105 Registered  Wed, 29 Aug 2012 20:33:21
2 SIP registrations.

We’ve 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 our Asterisk server would receive that call. We haven’t, as yet, got enough configuration for anything to happen to that call. Presence in the above list is (unintuitively) triggered by the callbackextension option in the endpoint defintion.

Presence in the following list is triggered by being an endpoint set as a peer:

hostname*CLI> sip show peers
Name/username              Host         Dyn Forcerport ACL Port  Status
voiptalkOFFICE/222222222      N             5060  Unmonitored
voiptalkRESIDENTIAL/11111      N             5060  Unmonitored
2 sip peers [Monitored: 0 online, 0 offline Unmonitored: 2 online, 0 offline]

This tells Asterisk that calls from to the 222222222 username will be handled using the voiptalkOFFICE endpoint declaration. Let’s look again at that declaration.


context and callbackextension tell asterisk what to do with incoming calls from this endpoint. Outbound calls are routed to this endpoint using the “SIP/voiptalkOFFICE” syntax in the dial plan.

We’ll return to this in more detail after we’ve covered setting up our local phones in the next article.

asterisk1 asterisk2 asterisk3 asterisk4 asterisk5

Leave a Reply