Asterisk is software that turns an ordinary computer into a voice communications server. Asterisk is the world’s most powerful and popular telephony development tool-kit. It is used by small businesses, large businesses, call centers, carriers and governments worldwide. Asterisk is open source and is available free to all under the terms of the GPL.
That is what the Asterisk website describes Asterisk as. I thought I should write a little about it, since it is quite a high first step, to start using and experimenting with it the first time, atleast I found it so, when I first did. Like with many things, there are good, and bad, documentation, and sources thereof. Sometimes both kinds are found in the same place, and it is up to you to judge on the quality. This is quite frustrating when you are looking for answers and don’t already know, or are able to judge, which is correct, and which is not.
Get the book
Let’s get started
I will now describe, in a how-to manner, to get you started, how to install Asterisk in Debian GNU/Linux, connect two SIP devices (telephones), and create a minimal dialplan so that they can call each other. I do not use any web-frontend or GUI, just the configuration files. You will find that it gives the best control and understanding of how things work, if you just take it one step at a time, and learn what you are doing.
What we need is:
- A machine running Debian GNU/Linux
- Asterisk itself (Asterisk is packaged in Debian.)
- Two SIP telephones, “softphones”, or “hardware” telephones using SIP
I presume that you have basic knowledge of package installation and standard Unix tools, and know how to use a text editor of your choice. Allright, let’s begin.
The package we need to install is asterisk. Its package description in Debian is:
Description: Open Source Private Branch Exchange (PBX) Asterisk is an Open Source PBX and telephony toolkit. It is, in a sense, middleware between Internet and telephony channels on the bottom, and Internet and telephony applications at the top. . Asterisk can be used with Voice over IP (SIP, H.323, IAX and more) standards, or the Public Switched Telephone Network (PSTN) through supported hardware. . Supported hardware: . * All Wildcard (tm) ISDN PRI cards from Digium (http://www.digium.com) * HFC-S/HFC-4S-based ISDN BRI cards (Junghanns.NET, beroNet, Digium etc.) * All TDM (FXO/FXS) cards from Digium * Various clones of Digium cards such as those by OpenVox * Xorcom Astribank USB telephony adapter (http://www.xorcom.com) * Voicetronix OpenPCI, OpenLine and OpenSwitch cards * CAPI-compatible ISDN cards (using the add-on package chan-capi) * Full Duplex Sound Card (ALSA or OSS) supported by Linux * Tormenta T1/E1 card (http://www.zapatatelephony.org) * QuickNet Internet PhoneJack and LineJack (http://www.quicknet.net) . This is the main package that includes the Asterisk daemon and most channel drivers and applications.
Install asterisk using aptitude, either in it’s interactive interface or with:
aptitude install asterisk
The asterisk package depends on, among other packages, asterisk-config and asterisk-sounds-main, and for now this is all we need. You might want to install the package asterisk-sounds-extra aswell though.
By default, Asterisk in Debian comes with a lot of sample configuration files, it looks overwhelming the first time one sees them all. However, for a simple first setup like this, only two files are really needed, sip.conf and extensions.conf. The configuration files are kept in /etc/asterisk/, the first thing we do is make a backup/reference copy of the whole directory containing the configuration files:
cp -r /etc/asterisk/ ~/asterisk_backup
The next thing we do is start out from scratch, to avoid the cluttering and confusion from the sample configurations. (Do look at them of course, but don’t use them, as in the case of the ones we will use here, sip.conf and extensions.conf, will only make it hard to read them, with many pages of comments, then one little enabled option here and there.) So, what we do is move sip.conf and extensions.conf out of the way, and create new ones, then giving them the same permissions and ownerships, as the sample files:
cd /etc/asterisk mv sip.conf sip.conf.sample touch sip.conf chmod --reference=sip.conf.sample sip.conf chown --reference=sip.conf.sample sip.conf mv extensions.conf extensions.conf.sample touch extensions.conf chmod --reference=extensions.conf.sample extensions.conf chown --reference=extensions.conf.sample extensions.conf
We are now ready to begin adding entries for our phones. (Please note that this can be done in many ways, this is one. I will possibly write more about this later, i.e describing the use of templates, we keep it simple for now.) Open the empty sip.conf in your favourite text editor and add:
[general] context=incoming allow=ulaw allow=alaw allow=gsm  type=friend secret=replacethis123 dtmfmode=rfc2833 callerid="First Phone" <1000> host=dynamic ; The device must always register canreinvite=no ; Deny registration from anywhere first deny=0.0.0.0/0.0.0.0 ; Replace the IP address and mask below with the actual IP address and mask ; of the computer running the softphone, or the address of the hardware phone, ; either a host address and full mask, or a network address and correct mask, ; registering will be allowed from that host/network. permit=192.168.1.0/255.255.255.0 context=myphones  type=friend secret=replacethis321 dtmfmode=rfc2833 callerid="Second Phone" <1001> host=dynamic ; The device must always register canreinvite=no ; Deny registration from anywhere first deny=0.0.0.0/0.0.0.0 ; Replace the IP address and mask below with the actual IP address and mask ; of the computer running the softphone, or the address of the hardware phone, ; either a host address and full mask, or a network address and correct mask, ; registering will be allowed from that host/network. permit=192.168.1.0/255.255.255.0 context=myphones
Edit the “secret” option, the password, to something more secure, and change the “permit” option to suit your network. The semicolon, “;”, is the comment-character in Asterisk’s configuration files.
Now let me explain a couple of things about the above configuration. The configuration is built up by sections. Sections are named and separated with a name, or tag, enclosed within square brackets [likethis]. The [general] section must be present, in the [general] section all default options are set, that should be used for all devices if they do not have their own value set for the option, to override the default. The “context=incoming” option is very important, it makes the default context be specified, all calls, from peers, or phones, that has not been placed in any other context, will end up there. This “context”, is a context in the dialplan, that we will soon come to. Notice that our two phones override the context option, and are placed in another one, called “myphones”. This will soon become clearer, as we move on with writing our dialplan, in extensions.conf.
The file extensions.conf is where the dialplan is configured. Actually it is one, of several possible places to create a dialplan, but it is the simplest, and the one you will see most referenced, it uses a simple syntax with basic logic. Later on you might want to use the Asterisk Extension Language (in extensions.ael) instead.
Open extensions.conf in your editor and add:
[general] static=yes writeprotect=no clearglobalvars=no [globals] ; Global variables goes here [incoming] ; Nothing should land here yet, but every context should end in ; a Hangup(), so we do that. exten => s,1,Hangup() [myphones] ; When we dial something from the phones we just added in ; sip.conf, Asterisk will look for a matching extension here, ; in this context. ; First Phone, extension 1000. If 1000 is called, here is ; where we land, and the device registered with the ; name 1000, is dialed, after that Asterisk hangs up. exten => 1000,1,Dial(SIP/1000) exten => 1000,n,Hangup() ; The same goes for Second Phone, extension 1001 exten => 1001,1,Dial(SIP/1001) exten => 1001,n,Hangup() ; Testing extension, prepare to be insulted like a ; Monthy Python knight exten => 201,1,Answer() exten => 201,n,Playback(tt-monty-knights) exten => 201,n,Hangup() ; Echo-test, it is good to test if we have sound in both directions. ; The call is answered exten => 202,1,Answer() ; Welcome message is played exten => 202,n,Playback(welcome) ; Play information about the echo test exten => 202,n,Playback(demo-echotest) ; Do the echo test, end with the # key exten => 202,n,Echo() ; Plays information that the echo test is done exten => 202,n,Playback(demo-echodone) ; Goodbye message is played exten => 202,n,Playback(vm-goodbye) ; Hangup() ends the call, hangs up the line exten => 202,n,Hangup()
The dialplan that we have created can be summarized as follows:
- 1000 – First Phone
- 1001 – Second Phone
- 201 – Test message
- 202 – Echo test application
For our configuration to take effect we either have to reload it from Asterisk’s command-line interface, or restart Asterisk. To reload the SIP configuration and the dialplan, connect to the running Asterisk’s command-line:
sip reload dialplan reload
Now configure your telephones to register with your configured Asterisk server, and make your first test calls!
To verify, or troubleshoot the registration, use the following Asterisk CLI commands:
sip show peers sip set debug on
- An introduction to Asterisk, The Open Source Telephony Project
- How to set up a SIP trunk in the Asterisk PBX
I hope this has been informative, and I would like to thank You for reading. Feel free to comment.