Asterisk & VoIP

I’ve recently moved to a new home; one of the consequences is the shift of utilities such as power, gas, water, and the topic of this post: phone. Being a Linux using geek, I’ve long been aware of Asterisk, but never really looked into it until lately. What I found was fun, useful, and economical.

Asterisk is an open-source communications project, aimed at telephony. It’s not a PBX system, but can be used to create one (among a great many other things). It scales well to more users than I care to think if (given it can be clustered to scale to many thousands of concurrent phone calls). Asterisk is professional-grade stuff.

It’s also fun for hobbyists like me. The initial idea of using Asterisk centered around using it with Google Talk (and Google Voice) to provide free phone service. Beats the heck out of paying the phone company substantially more with far fewer features.

So, what do you need to run Asterisk? A few things:
• A machine running Linux (though xBSD probably works fine too). I chose to use a virtualized machine - first using Xen, then using Linux Containers.
• A way to hook your phone up to your Asterisk system. The cheapest/easiest way to do this is to get an “ATA” box.
• A VoIP provider - this is possible with Google Talk and Google Voice, but there are other options, which I’ll discuss.


The first thing you have to do is have a way to run Asterisk; as I’ve said, I chose to use Linux Containers in the end. I’ll cover the complete setup of the Linux Container in a different article; setting up the containers aren’t overly difficult, but it can get complicated when the necessary step of configuring a firewall is reached. I run Debian, so setting up Asterisk is generally as easy as ‘apt-get install asterisk.’

There are many configuration files for Asterisk; Debian keeps them in /etc/asterisk. There are a few key configuration files to concern yourself with:
/etc/asterisk/sip.conf: This configures all SIP protocol connections - this generally includes any ATA devices or soft phones you intend to use.
/etc/asterisk/iax.conf: This configures IAX2 protocol connections - IAX2 is a telephony protocol that does many of the things SIP does - however, unlike SIP, IAX2 transverses firewalls and NAT quite well. IAX also has a jitter buffer, which can help smooth out any stuttering caused by network congestion.
/etc/asterisk/extensions.conf: This configures what happens when a call is placed or received - it defines how to send out connections when a number is dialed, and what to do when a call is received.
/etc/asterisk/voicemail.conf: For a home user like me, this requires little - I define a mailbox, and an email address where voicemail also gets mailed to. This is pretty neat - while I can get the voicemail from a phone, I’m also able to receive notification that I have voicemail when I’m not at home - and listen to it right then as well.
/etc/asterisk/jabber.conf: Configures connections using the XMPP (originally Jabber) protocol - this is needed if you intend to use Google Talk & Google Voice.
/etc/asterisk/gtalk.conf: This has configuration details specific to Google Talk.
There are many more configuration files than that; but a home user will spend most of their time editing these files.

Connecting the phone to Asterisk:

Next up, you’ll need a way to connect your phone to your Asterisk system. There are a few ways to do this:
• Buy a SIP or IAX phone - the phone connects directly to the Asterisk server using Ethernet & TCP/IP.
• Buy an ATA - an ATA bridges VoIP with an analog phone. They have the required digital-to-analog converters, compression hardware, power, ringtone, dial tone, and other functions needed to connect your old-fashioned analog phone to a VoIP network. ATA’s are also made that let you connect the PSTN (phone company) to your Asterisk system - which is useful if you want to have at least one line that can be relied on if your Internet connection isn’t something you’d trust with your life.
• Buy dedicated server hardware - These are generally PCI (or PCI Express) cards that are installed onto the Asterisk server. These are quite expensive, as they are professional products, designed to connect many incoming and outgoing phone lines. I really wouldn’t suggest option #3 unless there’s a compelling reason to have one; these are carrier-grade pieces of hardware for connecting high-capacity connections to the telephone company. These are for a business that wants to connect directly to the PSTN, instead of connecting to a VoIP provider over the Internet.
Since most people already have an analog phone (and because pure VoIP phones aren’t economical for home users), the best option right now is to get an ATA device. There are several options, and I’ll cover a few that I’ve looked at:
Cisco PAP2T-NA: This costs about $50. This is the device I decided upon in the end. Two separate analog ports, each able to handle two connections (for call waiting). This is nice because it lets me connect one line to my family’s telephone (for day-to-day use), and a second line to a separate phone in my home office, which would include a fax machine if necessary. The PAP2T-NA is “unlocked” which makes it perfect for use with Asterisk. It also supports the G.711, G.723, G.726, and G.729 codecs (though it lacks the horsepower to handle more than one G.729 session). It can also handle fax communications using a G.711 pass-through mode.
Cisco SPA-2102: About $10 more than the PAP2T-NA, has the features of the PAP2T-NA, plus an additional Ethernet interface. It can act as a wired router - which means you can hook it up directly to your DSL or cable modem, and have it act as the firewall/router. A nice feature, but not one I’m interested in…
GrandStream HT-286: Comes in at $25. A basic ATA; it has one analog phone port, supports the same codecs as the Cisco models. In short, it’s very similar to the PAP2T-NA, has half the number of analog ports, and costs half as much. Honestly, I just liked the idea of having two analog ports, which is the only reason I didn’t get this one.

VoIP Providers:

Finally, you’ll need a VoIP provider. Well, at least for the moment. Once installed and running, it’s technically possible to do pure VoIP without needing any service provider. However, there’s a catch: Without a service provider, you cannot connect to the PSTN (ie. a normal phone network). Practically nobody uses a SIP (or IAX) “telephone number” - and it’s impossible for you to call it using a pay phone, for example. For the time being, you more or less have to use a service provider to get anything useful (ie. normal phone calls) from your Asterisk system.

When looking for service providers, it’s useful to use Google to search for “Asterisk” or “hobbyist-friendly” VoIP providers. After looking around, I found a few that are the most popular. I’ll cover a few options I’ve explored here. All of them provide CallerID and Voice Mail. The ATA (and/or Asterisk) provides call waiting. Payment for all is by debit - you put money into your account, and you will be able to make calls until the money runs out. This is actually pretty nice - you don’t have to worry about “surprise” phone bills.
Google Talk (and Google Voice): This uses Google as your VoIP provider. A computer user can call your home phone using Google Talk, and if you configure Google Voice, someone dialing your Google Voice number, it works like any other phone connected to Google Voice. Incoming & outgoing calls to the US & Canada are free (for the moment). There is no E911, and always has Google’s annoying “Press 1 to accept this call” prompt.
Flowroute: Flowroute is one of the most popular VoIP providers. Great website, good service. They only accept SIP, and only use G.711 and G.729. A DID (a “normal” phone number) is about $1.39 a month. Calls are about a penny a minute for incoming or outgoing to the US. E911 is an additional $1.39 a month. Flowroute are aware they have many Asterisk hobbyists using their service, so they provide instructions (and configuration examples) for how to configure your Asterisk system to use Flowroute. has a far less “flashy” website than Flowroute (the private portal for customers is much nicer than the public portal). seems to have features Flowroute doesn’t: They accept SIP and IAX, as well as using the G.711, GSM, and G.729 codecs. has a ‘value’ rate of bout 1.1 cents per minute, and a “Premium” tier for about 1.25 cents per minute. DID numbers are about $0.99 per month with E911 costing about $1.50 per month. Just like Flowroute, also knows about their open source users, and also provide instructions for connecting an Asterisk system to their service.
There’s no reason you can’t use multiple providers.

I personally chose to use as my primary VoIP provider, and have Google Talk/Google Voice active and accepting calls (not that I get any, but…). My reasons for choosing VoIP.MS:
• IAX support: For my use case, IAX is the superior VoIP protocol.
• GSM support: GSM is the voice codec used by GSM phones; its patents are now expired, so it’s usable without a license. It also requires a fraction of the bandwidth needed for G.711. (G.729 uses a bit less less bandwidth, but costs $10 per additional line (the ATA provides one). I generally use G.729, but for the rare cases where I have more phone calls than G.729 licenses (ie. two or more), it’s nice to have a codec that will slash my bandwidth usage (and make the experience better for everybody in the process).

It’s also worth noting: With and Flowroute: it’s not even necessary to run an Asterisk server - an ATA can connect directly to their service. Asterisk running in the middle allows for a lot of extra customization - largely unnecessary - but fun.

A note on codecs:

There are a number of codecs used by Asterisk and VoIP:
G.711: This includes “μlaw” - used in North America & Japan, and the “alaw” - used in the rest of the world). G.711 is an 8 kHz, 8-bit PCM codec with a bandwidth of 64 kb/sec.
GSM: The codec used by GSM cellular phones. It is a compressed format, with a bandwidth of about 13 kb/s. The patents on GSM have expired, and it requires relatively little CPU to compress GSM. As a result, GSM is pretty well suited for open source VoIP - it uses a fifth of the bandwidth of G.711, with nearly the same audio quality.
G.723.1: A low bitrate (6.3 or 5.3 kb/s) codec used in H.323 videoconferencing. Its last patent expires in 2014.
G.726: This is the standard codec used on DECT cordless phones; it can use from 16-40 kb/s of bandwidth; 32 kb/s is the de facto standard, and Asterisk only supports the 32 kb/s standard.
G.729: An excellent codec for low bandwidth usage, while providing excellent voice quality. It’s also relatively CPU-intensive compared to other codecs, and is encumbered by patents.
Speex: An Ogg codec that is patent-free and widely used for VoIP applications - Xbox Live used Speex for a number of years, but has recently upgraded to the lower-latency SILK codec. Speex has a very wide range of nitrates - from 2 to 44 kb/s. It isn’t used by any ATA devices I know of, but a few soft phones can use speed.
iLBC: Internet Low Bitrate Codec. It was formerly freeware with a limited commercial license, but has been opened up to a 3-clause BSD license as part of the WebRTC project. It’s not currently available for Asterisk (due to licensing changes - the freeware-licensed code isn’t the same as the BSD code; takes time to port things). iLBC has graceful degradation - so if your network drops a lot of packets, iLBC has a lot less jitter.
Opus: Opus is an in-development codec not available for use with Asterisk yet. It combines the Skype SILK codec with the low-latency Ogg CELT codec. The result: a codec useful for VoIP that has insanely low latency and quality good enough to compete with HE-AAC personal radio (actually, the quality of Opus is better than Ogg Vorbis or normal AAC, making arguably the best sounding codec available). I’ve played around with builds from the current source tree, and Opus sounds amazing - not just for voice, but for music too.

Worth the effort?

So, after going to all this effort to setup and install an Asterisk system - is it worth all the bother? Absolutely.

A normal POTS (Plain Old Telephone Service) line from my telco runs about $20/month. No long distance. No caller id. No voicemail. No call waiting.

Using as my service provider, I get two lines for $2/month. E911 is only needed on one line (if I dial 911 from any phone, it uses the line with E911 active). That means I start at $3.50 per month. Sure, I pay 1.25 cents per minute for every call - but that’s anywhere in the US & Canada. International rates are generally less than a dime per minute. With the number of minutes I use, I spend quite a bit less than what my telco charges. As a bonus, I get long distance, caller ID, voicemail (that also gets mailed to my inbox), and call waiting - free.

So there are all kinds of phone features - many the local telco doesn’t provide, all kinds of geekery possible via Asterisk, and all for a fraction of the cost of my local telco! What’s not to like?