beardy's blog

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

Asterisk: The Definitive Guide: Open Source Telephony for the Enterprise 5th Edition
Asterisk: The Definitive Guide: Open Source Telephony for the Enterprise 5th Edition

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 (
  * 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 (
  * 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 (
  * QuickNet Internet PhoneJack and LineJack (
 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.

Configuring Asterisk

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:



callerid="First Phone" <1000>
host=dynamic        ; The device must always register
; Deny registration from anywhere first
; 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.

callerid="Second Phone" <1001>
host=dynamic        ; The device must always register
; Deny registration from anywhere first
; 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.

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:


; Global variables goes here

; Nothing should land here yet, but every context should end in
; a Hangup(), so we do that.
exten => s,1,Hangup()

; 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

Test it

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:

asterisk -vcr

And run:

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

Related articles

I hope this has been informative, and I would like to thank You for reading. Feel free to comment.

Hi, I’m beardy


  1. good, i did the with the example but the voice is cracking when the message is getting playback.

    i will be thankful if u can help me to configure trunk and how to dial using that trunk. —good article Njoyed 🙂

  2. Thanks for your comment santosh, I’m glad you enjoyed it.
    The reason for your sound crackling might be related to jitter (variances in delay on your network), bandwidth, or the codec you use. Make sure your phone is configured to use the codec you specify for it in sip.conf, some phones have to have their codec, or codecs, configured manually, in their own configuration.
    How to set up a trunk and how to dial with it will be the next article in this series.
    How to set up a SIP trunk in the Asterisk PBX

  3. A very nice article … i was really looking forward for this type which could start from scratch … im working in VoIP provider and your articles are really cool keep posting 🙂

  4. Hi,
    Thank you very much for this information. It opened up a whole freeway of ideas for me and my business. Could you tell me, now that the outgoing provider you gave us is out of business, who do you now recommend for this service?

  5. Very helpful, but I still have few questions in mind. I’m using IMSDroid on two android phones. It requires the following fields to be configured :
    Public identity
    Private identity

    What values should I set for each field? I’ve asterisk running on a local machine.
    What I’ve in mind :
    Public identity : ?? ( How do I configure it in such a way so that I get a url like this,

    Private identity : 1000 , in the case of this example

    Realm : ?? (What should I set as realm)

    I’m new to asterisk and SIP. Your help would be appreciated.

  6. i have two sip servers with ip and both have their dialplan and extensions. has an extension 201 and has an extension 504. now want i want to call from 201 to 504 and vice versa. for that i have to make trunks between these two sip servers.

    but i dont know how to set up this.please help me out to work this system.
    revert asap

  7. M J, thank you for pointing that out, I must have inserted a tag in the wrong place when updating the article. extensions.conf is there again. Sorry for the inconvenience.

  8. What’s up, I wish for to subscribe for this weblog to get latest updates, therefore where can i do it please assist.

  9. Bravo!!!!thx a lot 4 this post, i needed to start Asterisk 1.8 auaolatictmly on my Ubuntu Server and had no idea as how to do it. Your post did the Trick!!!(i still don’t understand starting scripts on linux though, but that’s another issue).Gracias mil.

  10. Remarkable! Its in fact amazing paragraph, I have got much clear idea about from this

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.