Debian Lenny Asterisk Howto

Sep 8th, 2009

These instructions show you how to compile and install Asterisk as a non-root user, this is the safest way to run Asterisk! The instructions also include building Dahdi kernel modules and tools, these provide drivers for external hardware if required, and will allow Asterisk to compile with conference call functionality! Change ‘X’ to suitable version.

Install and Configure Asterisk

# aptitude install build-essential subversion libncurses5-dev
# aptitude install linux-headers-`uname -r`
# adduser asterisk
# su asterisk
# cd /home/asterisk

Download the Asterisk source code from svn ‘branches’ and Dahdi source code from svn ‘trunk’. You can update the source code anytime within the source directories using: svn update. For Asterisk, this will download the latest patches and security updates for that particular version. For Dahdi, this will update the latest source code. Change ‘X’ to suitable version.

$ svn co http://svn.digium.com/svn/asterisk/branches/1.6.X asterisk-source
$ svn co http://svn.digium.com/svn/dahdi/linux/trunk dahdi-kernel
$ svn co http://svn.digium.com/svn/dahdi/tools/trunk dahdi-tools


Compile Dahdi kernel modules and tools, make sure you do this as root user.

$ su
# cd /home/asterisk/dahdi-kernel
# make
# make install
# cd /home/asterisk/dahdi-tools
# ./configure
# make
# make install
# make config


Compile Asterisk, most of this should be done as ‘asterisk’ user, linking the configuration directory and make config must be done as root user.

# su asterisk
$ cd /home/asterisk/asterisk-source
$ ./configure --prefix=$HOME/asterisk/bin --localstatedir=$HOME/asterisk/bin --sysconfdir=$HOME/asterisk/bin
$ make
$ make install
$ make samples
$ su
# ln -s /home/asterisk/asterisk/bin/asterisk /etc/asterisk
# make config


Edit Asterisk Configuration
We need to edit the init.d script so it launches Asterisk using the ‘asterisk’ user, only edit whats shown, leave everything else alone.

# vim /etc/init.d/asterisk
DAEMON=/home/asterisk/asterisk/bin/sbin/asterisk
AST_USER="asterisk"
AST_GROUP="asterisk"


Add the binary path to the shell, this will allow us to launch Asterisk without using the full path.

# su asterisk
$ vim /home/asterisk/.bashrc
PATH=/home/asterisk/asterisk/bin/sbin:$PATH
export PATH


Start Asterisk
Now for the exciting part, lets start Asterisk and log into its CLI!

# su
# /etc/init.d/asterisk start
# su asterisk
$ asterisk -rvvv


Asterisk Configuration
After you have installed Asterisk you will need to configure it to work with a VOIP provider for outgoing / incoming calls and interface it with hardware/software phone(s). You might want to provide functionality like voicemail, conference, music on hold, etc. The following instructions will show you how to get a basic configuration working with minimum of fuss.

Sign up with a IAX VOIP provider
You will first need to sign up with a IAX VOIP provider what is ideally based in your country, I am based in United Kingdom and use VOIPtalk. Make sure you edit the control panel and create a IAX route what points at your Asterisk box, also make a note of the ID and password they provide you with. A lot of VOIP providers will offer SIP services, try and avoid SIP as IAX is a far superior protocol what intergrates with Asterisk perfectly. Click here for explanation.

Asterisk iax.conf
This is where we configure all the IAX settings. Incoming and outgoing calls will use IAX, and our software phone will also use the IAX protocol. IAX uses one port for communication, 4569. You will need to make sure you forward this port on your firewall so the VOIP provider can send incoming calls. We will first insert the [general] settings. jitterbuffer will stop jitter, ulaw and alaw are the best sounding codecs. context=deadend is required so unauthorized calls don’t get unrestricted access to call out. Change ‘X’ to the IP address Asterisk listens on.

# su asterisk
$ mv /etc/asterisk/iax.conf /etc/asterisk/iax.conf.sample
$ vim /etc/asterisk/iax.conf
[general]
bindport=4569
bindaddr=X.X.X.X
jitterbuffer=yes
disallow=all
allow=ulaw
allow=alaw
context=deadend


We need to setup a route for outgoing calls using the IAX VOIP provider. Add this after the above [general] section. username, secret (password), and host will all be provided by your VOIP provider. Make sure your VOIP provider gives you a IAX host, NOT A SIP HOST!! context = default means it will match [default] in the dial plan what we will setup later.

[voip_provider]
type=friend
username=USERID
secret=PASSWORD
host=XXXXXXXXX
context=outgoing


This will setup a route for our incoming number, change VOIPNUMBER to the phone number the VOIP provider gave you without any spaces.

[VOIPNUMBER]
type=friend
username=VOIPNUMBER
context=incoming
requirecalltoken=auto


The IAX software phone will use extension 1000, provide it with a password for security.

[1000]
type=friend
host=dynamic
mailbox=1000
secret=PASSWORD
context=phones
requirecalltoken=auto


Asterisk voicemail.conf
This will setup a voicemail box for extension 1000, mailbox = 1000, as show above, will match the voicemail created in this configuration. Replace X with a digit only password, also replace name and email address. When somebody leaves a message a wav audio file will be sent to the email address!

$ mv /etc/asterisk/voicemail.conf /etc/asterisk/voicemail.conf.sample
$ vim /etc/asterisk/voicemail.conf
[internal]
1000 => XXXXXX,Linus Torvalds,mail@example.com
format=wav49
maxsilence=0


Asterisk meetme.conf
This will setup a conference room called ’1234′.

$ mv /etc/asterisk/meetme.conf /etc/asterisk/meetme.conf.sample
$ vim /etc/asterisk/meetme.conf
conf => 1234


Asterisk musiconhold.conf
This will play random files from the default music on hold directory.

$ mv /etc/asterisk/musiconhold.conf /etc/asterisk/musiconhold.conf.sample
$ vim /etc/asterisk/musiconhold.conf
[default]
mode=files
directory=/home/asterisk/asterisk/bin/lib/asterisk/moh
random=yes


Asterisk Menu Sound
I have created a short simple audio file what can be used for the menu in the dial plan. If you want to create your own audio file, read here.

$ wget http://www.wizbox.org/menu.wav
$ mv menu.wav /home/asterisk/asterisk/bin/lib/asterisk/sounds/en


Asterisk extensions.conf
First we need to setup the [general] part of the configuration. autofallthrough will make Asterisk follow the dial plan through without waiting for input.

$ mv /etc/asterisk/extensions.conf /etc/asterisk/extensions.conf.sample
$ vim /etc/asterisk/extensions.conf
[general]
autofallthrough=yes


This is where we will create the basic dial plan. When somebody calls, the phone will ring for 30 seconds, if nobody answers the caller will drop into a menu where they can access voicemail or conference. Make sure you change USERID to what was provided by your VOIP provider!

[outgoing]
exten => _0[1-9].,1,Dial(IAX2/USERID@voip_provider/44${EXTEN:1})
exten => _00.,1,Dial(IAX2/USERID@voip_provider/${EXTEN:2})
exten => _09XX,1,Dial(IAX2/USERID@voip_provider/${EXTEN})
 
[internal]
exten => 901,1,VoiceMailMain()
exten => 901,2,Hangup()
exten => 902,1,MeetMe(1234,cdM)
exten => 902,2,Hangup()
 
[incoming]
exten => VOIPNUMBER,1,Dial(IAX2/1000,30)
exten => VOIPNUMBER,2,Answer
exten => VOIPNUMBER,3,Wait(2)
exten => VOIPNUMBER,4,Set(TIMEOUT(digit)=3)
exten => VOIPNUMBER,5,Set(TIMEOUT(response)=10)
exten => VOIPNUMBER,6,Background(menu)
exten => 1,1,VoiceMail(1000@internal)
exten => 2,2,MeetMe(1234,cdM)
 
[phones]
include => internal
include => outgoing


IAX Software Phone
Make sure Asterisk is running and log into its CLI and reload all of the configuration files.

$ asterisk -rvvv
*CLI> reload

Download free version of Zoiper IAX software phone from here. Go to preferences and create a new IAX account, replace X with the settings created in iax.conf. 1000 = extension created in iax.conf.

Server Hostname/IP: X.X.X.X
Username: 1000
Password: PASSWORD
Caller ID Name: 1000

And now for the exciting bit, click register what is located on the bottom of the main panel. If everything has gone to plan, the Asterisk CLI should now show this:

-- Registered IAX2 '1000' (AUTHENTICATED) at X.X.X.X:4569

You should now be able to make outgoing and receive incoming calls! You can access voicemail 901, conference 902. Happy Asterisk’n!

Useful Information
http://www.voip-info.org/
http://www.digium.com/


Many thanks to the folk in freenode #asterisk, especially [TK]D-Fender for making this article possible!

Tags: