Asterisk install and network quality of service feature. Telasip is the provider.

Asterisk is an Opensource Public Branch eXchange system that does all the things a PBX should do.

When installed with a decent provider and the proper network configuration, it is a reliable and reasonably easy to configure service.

When you are done with the HowTo you should have a 2 extension phone network and a decent call waiting queue.

This document assumes that you are using a fresh standard system install of Debain Etch. It also assumes that this server is an image that is running on a Vmware server. It will most likely work for your flavor of linux.

Asterisk is great, but to make it fantastic you need some other tools.

These tools are metrics that provide you with all kinds of information in real time.

Call Data Recording is handled by Asterisk internally and then stored to a database. There is a module for Asterisk that allows Mysql functionality, but Asterisk comes with an Open DataBase Connectivity module, so thats a no brainier. You will have to configure ODBC and Mysql to work together, of course I will provide those steps.

This HowTo is sparse on theory and takes a route that lets you have a working install the first time.

Section 1. Installation

Let’s install the backend we are going to need to see all that calling data.

Ssh into the box:

debian:~# apt-get install apache2 mysql-server php5-mysql
debian:~# apt-get install libapache2-mod-php5 phpmyadmin
debian:~# apt-get install asterisk asterisk-sounds madplayer

It’s a good idea to add an admin to mysql at this stage, then we can configure the asterisk dataset.


Root is given access to Mysql sans password, so connect to :


Login as root, no password.

Probably a good idea to change your root password here.

Great, we can now port over the dataset.

First create the user asterisk and select create database with the same name.

Edit a file: /etc/odbc.ini

Description = MySQL test database
Trace= On
TraceFile = /var/log/mysqlodbc
Driver= mysql
SERVER= localhost
USER = asterisk
PASSWORD = xxyy123
DATABASE= asterisk

and we also need to edit odbcinst.ini

debian:~#vi /etc/odbcinst.ini


Description             = MySQL test database

Trace = On

TraceFile = /var/log/mysqlodbc

Driver = mysql

SERVER= localhost

USER = asterisk

PASSWORD= xyourpasswordforasterisk

DATABASE= asterisk

Test the odbc install with this line:

debian:/etc# isql -v mysql
| Connected!
| sql-statement
| help [tablename]
| quit

ok all done. Let’s add the database structure to the Mysql database.

First here is the database structure.


Database asterisk

Table structure for table cdr

Field Type Null Default
calldate datetime Yes 0000-00-00 00:00:00
clid varchar(80) Yes
src varchar(80) Yes
dst varchar(80) Yes
dcontext varchar(80) Yes
channel varchar(80) Yes
dstchannel varchar(80) Yes
lastapp varchar(80) Yes
lastdata varchar(80) Yes
duration int(11) Yes 0
billsec int(11) Yes 0
disposition varchar(45) Yes
amaflags int(11) Yes 0
accountcode varchar(20) Yes
uniqueid varchar(32) Yes
userfield varchar(255) Yes

And here is the command to build it.

Copy and paste below to the sql command window in phpmyadmin


`calldate` datetime NOT NULL default '0000-00-00 00:00:00',

`clid` varchar(80) NOT NULL default '',

`src` varchar(80) NOT NULL default '',

`dst` varchar(80) NOT NULL default '',

`dcontext` varchar(80) NOT NULL default '',

`channel` varchar(80) NOT NULL default '',

`dstchannel` varchar(80) NOT NULL default '',

`lastapp` varchar(80) NOT NULL default '',

`lastdata` varchar(80) NOT NULL default '',

`duration` int(11) NOT NULL default '0',

`billsec` int(11) NOT NULL default '0',

`disposition` varchar(45) NOT NULL default '',

`amaflags` int(11) NOT NULL default '0',

`accountcode` varchar(20) NOT NULL default '',

`uniqueid` varchar(32) NOT NULL default '',

`userfield` varchar(255) NOT NULL default '',

KEY `calldate` (`calldate`),

KEY `dst` (`dst`),

KEY `accountcode` (`accountcode`)


Now we should have a database structure, you can review it in phpmyadmin to double check.

Back up your existing asterisk configuration at this point.

debian:/etc# cp -a asterisk asterisk.back

On to the configuration.

  1. Asterisk Configuration

sip.conf- this file controls your peer access and settings to your service provider. You will need to register with your provider and set up passwords for your connecting phones in this file.

register=username:password@gw4.telasip.com [review the domain, it may be different]
host=gw4.telasip.com [review this, it might be different]


To set up an extension that is a sip phone, like our Grandstream Gxp-2000:



username=user name phone
secret=password phone

Edit a file: /etc/asterisk/extensions.conf

Change the value TRUNK:


[from-trunk] exten=>_2403961450,1,Dial(SIP/201,30,r)

and add the dial plan.

You can delete from the context [demo] and after, everything.

Then add this dialplan



exten => s,1,Ringing

exten => s,2,Set(CALLERID(number)=${CALLERIDNUM})

exten => s,3,Wait(2)

exten => s,4,Answer

;exten => s/4074322547,5,SetMusicOnHold(private)

;exten => s/4074322547,6,Macro(stdexten,1234,SIP/grandstream)

;exten => s/4075923644,5,SetMusicOnHold(private)

;exten => s/4075923644,6,Macro(stdexten,1234,SIP/grandstream)

exten => s/8138904500,5,Macro(stdexten,1234,SIP/grandstream)

exten => s,5,Background(greet1)

exten => s,6,WaitExten(10)

exten => s,n,Set(CALLERID(all)=No Selection-<${CALLERID(number)}>)

exten => s,n,Macro(stdexten,1234,SIP/grandstream)

exten => 1,1,Playback(transfer)

exten => 1,n,Ringing

exten => 1,n,Wait(2)

exten => 1,n,NoOp,(${CALLERID(all)})

exten => 1,n,Set(CALLERID(all)=Sales-<${CALLERID(number)}>)

exten => 1,n,Queue(example_queue|tT|||150)

exten => 1,n,Voicemail(1234)

exten => 2,1,Playback(transfer)

exten => 2,n,Ringing

exten => 2,n,Wait(2)

exten => 2,n,Set(CALLERID(name)=TechSupport-)

exten => 2,n,Queue(example_queue|tT|||150)

exten => 2,n,Voicemail(1234)

exten => 3,1,Goto(mainmenu,s,3)

exten => 1234,1,Playback(transfer,skip) ; “Please hold while…”

exten => 1234,n,Set(CALLERID(all)=Direct-<${CALLERID(number)}>)

exten => 1234,n,Macro(stdexten,1234,SIP/grandstream)

;exten => 1234,1,Voicemail(dug)

exten => 1235,1,Playback(transfer,skip)

exten => 1235,n,Macro(stdexten,1235,SIP/grandstream2)

exten => 1235,1,Voicemail(queen)

exten => 1238,1,Playback(transfer,skip)

exten => 1238,n,Macro(stdexten,1235,IAX2/user01)

exten => 8500,1,VoicemailMain

exten => 8500,n,Goto(s,7)

exten => 666,1,Goto(mainmenu,s,1)

exten => i,1,Goto(mainmenu,s,3)

exten => 129,1,Queue(example_queue|tT|||300) ;dont set n option until really needed

exten => 129,2,Playback(some_announce_after_leaving_queue)

exten => 129,3,Voicemail(s1234)

exten => 333,1,SetMusicOnHold(stream)

exten => 333,n,WaitMusicOnHold(600)

exten => 334,1,SetMusicOnHold(private)

exten => 334,n,WaitMusicOnHold(600)

There are a few more options in there, and in later tutorials I will show you how to activate these features.


Let’s add our extensions to the queue.

Edit the file queues.conf:



member => SIP/grandstream

member => SIP/grandstream2


Edit the file cdr_odbc.conf



Install the stats software from


untar in /var/www/stats

Edit a file /var/www/stats/asterisk-stats-v2/lib/defines.php

define (“WEBROOT”, “http://testasterisk/asterisk-stat/”);

define (“FSROOT”, “/var/www/asterisk-stat-v2/”);

define (“LIBDIR”, FSROOT.”lib/”);

define (“HOST”, “localhost”);

define (“PORT”, “3306″);

define (“USER”, “asterisk”);

define (“PASS”, “asteriskdbpassword”);

define (“DBNAME”, “asterisk”);

define (“DB_TYPE”, “mysql”); // mysql or postgres

define (“DB_TABLENAME”, “cdr”);


Install the operator panel from


untar in /var/www/monitor

Edit the file op_servers.cfg


replace your username and password with your username and password for the manager in asterisk.

Edit a file


debian:~#vi /etc/asterisk/manager.conf

It should look like this



enabled = yes

port = 5038

bindaddr =


secret = mysecret



read = system,call,log,verbose,command,agent,user

write = system,call,log,verbose,command,agent,user


Notice the username is in [] and the secret is listed below. These values need to match the onces in your op_servers.cfg

Now launch your op_server.pl and watch the output to see it connect to your asterisk box and the information it provides.



Now we need to start asterisk and record our greeting.


Call your number provided by telasip, it will fall back to the 1234 extension, now record your greeting.


Do this until you are satisfied. Navigate to:

debian:~#cd /var/spool/asterisk/voicemail/default/1234/INBOX

And copy the file you want as a message.


debian:~#cp -a msg000.gsm[Replace with good message] /usr/share/asterisk/sounds/greet1.gsm

debian:~#asterisk -vvvvvvvvvvvvvc

Asterisk Ready.

*CLI> sip show registry

Host Username Refresh State

gw4.sip.telasip.com:5060 username 105 Registered

This command shows you are registered, and now you should be able to take incoming calls.

Comments are welcome. A nice link with pics is on its way!

No Comment.

Add Your Comment