How To Install Asterisk VOIP PBX on Debian Linux

I don’t have a land line. I don’t see the point. My wife and I both have cell phones and that has served us well for many years. But now that my wife has quit her job to start her own business we’ve started looking into getting phone service in the traditional sense; a land line. But for a myriad of reasons I don’t want to get it through the phone company (I’m a cheap bastard and although the office, aka the spare bedroom, is heavily wired for ethernet, it doesn’t have a working phone line.) We also require heavy call processing. We’ll need multiple lines, ring groups, a robust voice mail system, and the ability to ring a cell phone if the office lines don’t answer. Meeting that requirement means that we also need a PBX, which are spendy little devils. So once again I turn to the open source community to fill a void in a cost effective manner without compromising features or flexibility. Enter Asterisk.
Asterisk is a Linux/Unix based telephony tool kit with all the bells and whistles of even the most robust of PBX’s. From automated attendants to voice over IP, Asterisk has it all.

After a bit of reading this O’Reilly book, I decided to take a stab at building my own Asterisk PBX. I found many tutorials online but most of them involving business VOIP providers and dealing with offices connecting to the PSTN. I wanted an easy way to experiment with Asterisk without connecting to the PSTN or spending a lot of cash on a service that I wasn’t sure I’d even use. I tried using Free World Dialup, a free VOIP gateway, but it is limited to only calling other FWD servers, which wasn’t really enough for me to really test things out. I dug around a bit and found Broadvoice, who offers a “Bring Your Own Device” package that is about six USD a month. Perfect for testing. So to that end, this tutorial on setting up a very basic Asterisk server that is pure VOIP and soft-phones, perfect for experimenting with this awesome application. I’ll be setting this up on a Debian server running the latest version of Sarge with the 2.6 kernel. You could use Asterisk@home, a fullblown Asterisk/Linux distribution that installs CentOS and Asterisk automatically and sports a nice web-based interface. But I really like to know what’s happening under the hood so I’ll be downloading the latest source and compiling it, and not using the .deb packages.

I’m assuming you have a fresh install of Debian Sarge waiting for you to work with. Let’s start off by getting it all ready to compile and run Asterisk. I have an Intel P3 1gig processor, and since we’ll need the kernel source, let’s upgrade our kernel and install the corresponding kernel headers then reboot.

apt-get install kernel-image-2.6.8-2-686 kernel-headers-2.6.8-2-686

Next we’ll install everything we need to compile our source.

apt-get install libncurses5-dev bison libssl-dev libnewt-dev zlib1g-dev procps gcc make binutils doxygen

Now change to our working directory and download and untar our source.

cd /usr/src
for i in *.tar.gz; do tar zxvf $i; done

The order of installation matters here so do as I do and you shouldn’t have any problems. We’ll install libpri first even though we won’t be using any pri lines, but Asterisk wants it so we’ll install it.

cd /usr/src/libpri-1.2.1
make install

Next we’ll compile the zaptel modules even though we won’t be using any zaptel cards. Like libpri, Asterisk needs it to compile, but Asterisk needs some kind of timing device which is usually provided by the zaptel hardware. Since we’re using only VOIP and the 2.6 kernel we can use the ztdummy module for timing. To compile the ztdummy module we have to edit zaptel’s Makefile and uncomment the ztdummy line.

cd /usr/src/zaptel-1.2.1 && vi Makefile

Find this line: MODULES:=zaptel tor2 torisa wcusb wcfxo wctdm wctdm24xxp \
ztdynamic ztd-eth wct1xxp wct4xxp wcte11xp pciradio \
ztd-loc # ztdummy
And change it to: MODULES:=zaptel tor2 torisa wcusb wcfxo wctdm wctdm24xxp \
ztdynamic ztd-eth wct1xxp wct4xxp wcte11xp pciradio \
ztd-loc ztdummy

Now compile and install:

make linux26
make install
modprobe ztdummy

We want to have the ztdummy module load automatically each time we boot so edit the /etc/modules file and include ztdummy. Run update-modules to update the system. Now for the big install. Cd to /usr/src/asterisk-1.2.1. We’ll want to edit the Makefile for Asterisk to add a few optimizations for our architecture. Find and uncomment the following lines for Pentium processors:


Now compile and install in the following order:

make mpg123
make install
make samples
make progdocs
make config (should install the startup script but fails so cp contrib/init.d/rc.debian.asterisk /etc/init.d/asterisk)

Install the asterisk-sounds source which installs things such as the mp3’s that will be played while on hold.

cd /usr/src/asterisk-sounds-1.2.1 && make install

At this point DO NOT START ASTERISK!!! It is not a very good idea to run Asterisk as root so we’ll create a non-privileged user and run under it.

echo “asterisk:x:104:104:Asterisk PBX daemon,,,:/var/lib/asterisk:/bin/false” >> /etc/passwd
echo “asterisk:x:104:” >> /etc/group

Now edit /etc/init.d/asterisk and uncomment:


Since the asterisk user can’t write to /var/run (and we don’t want it to) we’ll create a place for it’s process id file. Edit /etc/asterisk/asterisk.conf and change:

astrundir => /var/run


astrundir => /var/run/asterisk

Create the new directory and change the owner to the asterisk users:

mkdir /var/run/asterisk && chown asterisk:asterisk /var/run/asterisk

We also have to fix the file ownship on the rest of the places the asterisk user needs to write to:

chown -R asterisk:asterisk /var/log/asterisk
chown -R asterisk:asterisk /var/spool/asterisk
chown -R asterisk:asterisk /var/lib/asterisk/
chown -R asterisk:asterisk /dev/zap/pseudo

You’ll also need to add asterisk to the audio group:

adduser asterisk audio

You can now fire it up and see if all is well.

asterisk -U asterisk -G asterisk -cvv

Configure Astersik

Setup an account with Broadvoice and have your account information handy. Make backup copies of the /etc/asterisk/sip.conf and /etc/asterisk/extensions.conf. Change your files to the following, changing the account information to your own.


port = 5060           ; Port to bind to (SIP is 5060)
bindaddr =    ; Address to bind to (all addresses on machine)
disallow=all          ; Dis-allow all codecs

register =>

;Disable canreinvite if you are behind a NAT

; Line one soft-phone

; Line two soft-phone



; Echo test - dial 600
exten => 600,1,Playback(demo-echotest)
exten => 600,2,Echo
exten => 600,3,Playback(demo-echodone)
exten => 600,4,Goto(s,6)

; Dial 2999 for voicemail
exten => 2999,1,Ringing
exten => 2999,2,VoicemailMain,s2000

; Dial out - dial 9 for external line
exten => _9.,1,SetCallerID(5555551212)
exten => _9.,2,Dial(SIP/${EXTEN:1}

; Incoming calls
;exten => 5555551212,1,Dial(SIP/2000,15,tTr)
; Same as above but rings ext 2000 and 2001 at the same time
exten => 5555551212,1,Dial(SIP/2000&SIP/2001&SIP/,15,tTr)
exten => 5555551212,2,Voicemail,u2000
exten => 5555551212,102,Voicemail,b2000
exten => 5555551212,103,Hangup