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:
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 â€œwww.facebook.comâ€ 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.
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:
; '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
Thatâ€™s my residential line. Note the top line
[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
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 18.104.22.168~dfsg-1+b1, Copyright (C) 1999 - 2012 Digium, Inc. and others.
Created by Mark Spencer <firstname.lastname@example.org>
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 22.214.171.124~dfsg-1+b1 currently running on hostname (pid = 27724)
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> sip show registry
Host dnsmgr Username Refresh State Reg.Time
voiptalk.org:5060 N 111111111 105 Registered Wed, 29 Aug 2012 20:33:21
voiptalk.org:5060 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
email@example.com 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 126.96.36.199 N 5060 Unmonitored
voiptalkRESIDENTIAL/11111 188.8.131.52 N 5060 Unmonitored
2 sip peers [Monitored: 0 online, 0 offline Unmonitored: 2 online, 0 offline]
This tells Asterisk that calls from 184.108.40.206 to the 222222222 username will be handled using the
voiptalkOFFICE endpoint declaration. Letâ€™s look again at that declaration.
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.