Personal VOIP/PBX using Asterisk, part 2

This is part two of my series on how to set up an asterisk server for home use on a Linode VPS — but is applicable to any host that doesn’t have additional hardware telephony devices installed in the server. Please refer to Part 1 for how to set up the dummy timing module.

Also, before continuing, please read my little sidebar post about IP telephony codecs. Most specifically the part on adding iLBC codec to the asterisk config. Then “read more” below for the rest of this post.

First step, obtain the asterisk sources and unpack on the server.  I ran the following as a normal user account:

make menuselect

A menu of options will come up. Be sure to set iLBC as a codec in that section. 

Run the following as root

make install
make samples
make config 

Don’t Run as Root

Amazingly, default install for asterisk is to run as root. If asterisk is compromised remotely or even compromised locally by a logged in user, it may be possible to compromise the entire system. If it will run as a normal user, why not  do that?

Just in case the above post is missing, below are the commands I did to set up Asterisk not to run as root. Reminder, this is using a Centos 5 distribution. Also note I didn’t do /dev/zap since I don’t have any hardware on this box. 

/usr/sbin/groupadd asterisk 
/usr/sbin/useradd -d /var/lib/asterisk -g asterisk asterisk 
chown --recursive asterisk:asterisk /var/lib/asterisk
chown --recursive asterisk:asterisk /var/log/asterisk
mkdir /var/run/asterisk
chown --recursive asterisk:asterisk /var/run/asterisk
chown --recursive asterisk:asterisk /var/spool/asterisk
chown --recursive asterisk:asterisk /usr/lib/asterisk
chmod --recursive u=rwX,g=rX,o= /var/lib/asterisk
chmod --recursive u=rwX,g=rX,o= /var/log/asterisk
chmod --recursive u=rwX,g=rX,o= /var/run/asterisk 
chmod --recursive u=rwX,g=rX,o= /var/spool/asterisk 
chmod --recursive u=rwX,g=rX,o= /usr/lib/asterisk 
chown --recursive root:asterisk /etc/asterisk
chmod --recursive u=rwX,g=rX,o= /etc/asterisk
chmod g+w /etc/asterisk/voicemail.conf
chmod g+w,+t /etc/asterisk

 File Edits

  • /etc/asterisk/asterisk.conf: set astrundir to /var/run/asterisk
  • /etc/asterisk/asterisk.conf: Remove ‘(!)’ from first line that says [directories]
  • /etc/asterisk/asterisk.conf: Remove comments from runuser and rungroup so they both specify user asterisk
  • /etc/init.d/asterisk: uncomment AST_USER and AST_GROUP so they both specify asterisk

Start Asterisk

Start asterisk with command “service asterisk start” and verify it is not running as root with “ps -fu asterisk”

First Test, Softphone


Need a softphone to connect. A good open source softphone is X-lite. Download and install it. Another good one is QuteCom. Heck, download and install that too. Can’t hurt!  Of course both run under OS X else I wouldn’t be mentioning it!

In the /etc/asterisk directory, mv sip.conf to sip.conf-sample and recreate a new sip.conf file and add to it the following lines:


    host=dynamic       ; Not needed if you have a static IP
    nat=yes            ; Do not use this line if NOT behind NAT
    canreinvite=no     ; Used when behind a NAT
    secret=notttisone  ; Change this obviously

The secret is the password the softphone will use to connect. The 1001 is the acct name and extension. 

Start up dahdi and asterisk, then connect to asterisk console

service dahdi start
service asterisk start
asterisk -rvvv

Configure the softphone to use acct/username 1001 and the password matching the secret set above and the IP address of your server for domain and proxy. It should register and a status line will update with that in the asterisk console. 

Try placing a call to any number. It should fail with an unavailable message, but that message will be coming from the asterisk server! 🙂

Connecting to Gizmo5


So far this isn’t very useful. What we need is a method to call out. There are a number of VOIP service providers out there that generally provide free calls to other voip services but charge for connections to landline and mobile phones. Gizmo does that as well, but if you create an account with them you’ll get 10 cents of free call-out credit. Enough to test this with (probably about 5 calls). 

There are other SIP providers as well, like VOIPRAIDER, that I haven’t tried out yet.

To configure your asterisk server to dial out to Gizmo, you’ll need your sip number, which probably starts with 1747, as well as your account password.

First step, need to make changes to the existing sip.conf file, being sure to substitute my example 1747 number and PASSWORD (secret) with your own.



Run asterisk -rvvv if not already running and enter the command “sip reload” to reload the sip file. 
Next step is to configure a simple dial plan.  In the same /etc/asterisk directory, rename (mv) extensions.conf to extensions.conf-sample and create a new extensions.conf file and park the following in it.



exten => s,1,Verbose(1|Unrouted call handler) 
exten => s,n,Answer() 
exten => s,n,Wait(1) 
exten => s,n,Playback(tt-weasels) 
exten => s,n,Hangup() 

   exten => _X.,1,NoOp()
   exten => _X.,2,Dial(SIP/${EXTEN:1},20,r)
   exten => _X.,3,Hangup

   include => outgoing_calls 

Dial plans are scary things, mainly because misconfiguring it could give an outside user ability to dial numbers remotely and get them charged to you.  They will be covered in a future blog post.

Within the asterisk console (which you get when running asterisk -rvvv) type in the comment “dialplan reload” to read in the changes to extensions.conf just made. 

Now it’s time to test! Dial your own cell or home number from the soft phone that is logged into your asterisk server. Dial 9 to get out. So, for example, 913025551212. The phone should ring. Congrats, the first asterisk call. (If you want to save your callout credit, don’t pick up the phone you are calling!)

Below is an example of what the log lines that should show up in your console when making the call.  

  == Using SIP RTP CoS mark 5
    -- Executing [91302738xxxx@phones:1] NoOp("SIP/1000-b7e31048", "") in new stack
    -- Executing [91302738xxxx@phones:2] Dial("SIP/1000-b7e31048", "SIP/,20,r") in new stack
  == Using SIP RTP CoS mark 5
    -- Called
    -- SIP/ answered SIP/1000-b7e31048
    -- Packet2Packet bridging SIP/1000-b7e31048 and SIP/
  == Spawn extension (phones, 91302738xxxx, 2) exited non-zero on 'SIP/1000-b7e31048'

This config will also allow call-in, if you have a call-in number. It won’t do much except play a recording that weasels have taken over your PBX, because that’s all the dialplan above tells it to do. 

The good news is, currently gizmo allows you to get a free call-in number (that is somewhat limited) in area code 775 — which is in Nevada. The limitation of this number is that it makes the user calling record their name and requires the person being called to punch in a number to connect the call, which our asterisk config won’t handle right now. But it will ring into asterisk and you’ll see the debug lines show up in the console. 

Another option for dial-in number is, which will give you a free dial-in number and can be configured to call gizmo numbers for free. This, unfortuantely, also has a limitation that the called user has to press a key to pick up the phone, which asterisk using this config won’t do — but again it will place a call into your asterisk server and the debug records will display.

Here’s an example of a received call:

  == Using SIP RTP CoS mark 5
    -- Executing [s@default:1] Verbose("SIP/1747xxxxxxx-b7e33c38", "1|Unrouted call handler") in new stack
1|Unrouted call handler
    -- Executing [s@default:2] Answer("SIP/1747xxxxxxx-b7e33c38", "") in new stack
    -- Executing [s@default:3] Wait("SIP/1747xxxxxxx-b7e33c38", "1") in new stack
    -- Executing [s@default:4] Playback("SIP/1747xxxxxxx-b7e33c38", "tt-weasels") in new stack
    -- <SIP/17471348546-b7e33c38> Playing 'tt-weasels.ulaw' (language 'en')
    -- Executing [s@default:5] Hangup("SIP/1747xxxxxxx-b7e33c38", "") in new stack
  == Spawn extension (default, s, 5) exited non-zero on 'SIP/17471348546-b7e33c38'

So now we can place outgoing calls through Gizmo5 using asterisk — which technically is no big deal since one could do that a lot easier just using the gizmo5 softphone.  But it’s a start!

Next blog post will be about dialplans and customizing all of this so it’s a bit more useful, and then configuring and using the Cisco SPA3012 ATA (analog telephone adapter) to get the house phones in on the fun!

A Word about Gizmo5


Gizmo5, formerly known as Gizmoproject and sipphone, doesn’t have the best reputation for customer service. I’m using them as an example because it’s the service I am comfortable with, but any other SIP provider should work the same way. So don’t consider this an endorsement.

I haven’t had any bad luck with them, beyond them being a real pain regarding payment methods. Their anti-fraud steps are a bit, in my opinion, over the top. For example, they’ll only except payments from Paypal if it’s a verified account, meaning tied to your bank or you own a Paypal credit card. For credit card payments, I had to fax them a copy of my last bill (which I blacked out all personal info from).  

Also, if you don’t make some sort of payment on your account at least once per year, you can lose all of your dialout credit. So far this hasn’t been a problem for me since I buy two dialin numbers from them — a number in Delaware and a number in UK. (Dial-in numbers cost about $4/month).

One neat thing about Gizmo5 and call-in numbers is, they set your Caller ID to the last dial-in number you purchased. Since that one is my UK number, whenever I call someone in the U.S. using Gizmo, it shows up on their caller ID as a UK number!

4 thoughts on “Personal VOIP/PBX using Asterisk, part 2”

  1. Thanks for this – I was having some trouble figuring out how to get SIP extensions to call via Gizmo5 and your guide made it all perfectly clear. 🙂

  2. Mister Weaverling,

    Thanks for your great artical about Asterisk. I am a beginner in de Linux world. I have a question for you, why you need a linode in Asterisk and what are the benefit to use this ?

    Jac from Holland

  3. No real advantage except not having to worry much about it being down or the network line being down. You could run one of these in your bedroom on a decent broadband line just fine. Only challenge would be if it had a dynamic IP address and you want to connect to it from outside, but that’s not that big of a deal to solve.

Leave a Reply to The_Assimilator Cancel reply

Your email address will not be published. Required fields are marked *