O'Reilly logo

Asterisk: The Future of Telephony, 2nd Edition by Leif Madsen, Jared Smith, Jim Van Meggelen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required


This is a book for anyone who is new to Asterisk™.

Asterisk is an open source, converged telephony platform, which is designed primarily to run on Linux. Asterisk combines more than 100 years of telephony knowledge into a robust suite of tightly integrated telecommunications applications. The power of Asterisk lies in its customizable nature, complemented by unmatched standards compliance. No other PBX can be deployed in so many creative ways.

Applications such as voicemail, hosted conferencing, call queuing and agents, music on hold, and call parking are all standard features built right into the software. Moreover, Asterisk can integrate with other business technologies in ways that closed, proprietary PBXes can scarcely dream of.

Asterisk can appear quite daunting and complex to a new user, which is why documentation is so important to its growth. Documentation lowers the barrier to entry and helps people contemplate the possibilities.

Produced with the generous support of O’Reilly Media, Asterisk: The Future of Telephony was inspired by the work started by the Asterisk Documentation Project. We have come a long way, and this book is the realization of a desire to deliver documentation that introduces the most fundamental elements of Asterisk—the things someone new to Asterisk needs to know. It is the first volume in what we are certain will become a huge library of knowledge relating to Asterisk.

This book was written for, and by, the Asterisk community.


This book is for those new to Asterisk, but we assume that you’re familiar with basic Linux administration, networking, and other IT disciplines. If not, we encourage you to explore the vast and wonderful library of books that O’Reilly publishes on these subjects. We also assume you’re fairly new to telecommunications, both traditional switched telephony and the new world of Voice over IP.


The book is organized into these chapters:

Chapter 1, A Telephony Revolution

This is where we chop up the kindling and light the fire. Asterisk is going to change the world of telecom, and this is where we discuss our reasons for that belief.

Chapter 2, Preparing a System for Asterisk

Covers some of the engineering considerations you should have in mind when designing a telecommunications system. Much of this material can be skipped if you want to get right to installing, but these are important concepts to understand, should you ever plan on putting an Asterisk system into production.

Chapter 3, Installing Asterisk

Covers the obtaining, compiling, and installation of Asterisk.

Chapter 4, Initial Configuration of Asterisk

Describes the initial configuration of Asterisk. Here we will cover the important configuration files that must exist to define the channels and features available to your system.

Chapter 5, Dialplan Basics

Introduces the heart of Asterisk, the dialplan.

Chapter 6, More Dialplan Concepts

Goes over some more advanced dialplan concepts.

Chapter 7, Understanding Telephony

Taking a break from Asterisk, this chapter discusses some of the more important technologies in use in the Public Telephone Network.

Chapter 8, Protocols for VoIP

Following the discussion of legacy telephony, this chapter discusses Voice over Internet Protocol.

Chapter 9, The Asterisk Gateway Interface (AGI)

Introduces one of the more amazing components, the Asterisk Gateway Interface. Using Perl, PHP, and Python, we demonstrate how external programs can be used to add nearly limitless functionality to your PBX.

Chapter 10, Asterisk Manager Interface (AMI) and Adhearsion

Describes how external applications can connect to Asterisk to manipulate or monitor various aspects of the system. Also included in this chapter is a gentle introduction to the Adhearsion framework.

Chapter 11, The Asterisk GUI Framework

The Asterisk GUI Framework, new in Asterisk 1.4, is a framework system that allows web developers to create graphical interfaces with minimal interference to the standard configuration files.

Chapter 12, Relational Database Integration

Walks you through setting up Asterisk to work with ODBC databases.

Chapter 13, Managing Your Asterisk System

Discusses issues regarding how to best manage your Asterisk phone system, including CDR, logs, and prompts.

Chapter 14, Potpourri

Briefly covers what is, in fact, a rich and varied cornucopia of incredible features and functions—all part of the Asterisk phenomenon.

Chapter 15, Asterisk: The Future of Telephony

Predicts a future where open source telephony completely transforms an industry desperately in need of a revolution.

Appendix A, VoIP Channels

Appendix B, Application Reference

Appendix C, AGI Reference

Appendix D, Configuration Files

Appendix E, Asterisk Dialplan Functions

Appendix F, Asterisk Manager Interface Actions

Appendix G, An Example of func_odbc


This book is focused on documenting Asterisk Version 1.4; however, many of the conventions and information in this book are version-agnostic. Linux is the operating system we have run and tested Asterisk on, with a leaning toward Red Hat syntax. We decided that while Red Hat–based distributions may not be the preferred choice of everyone, their layout and utilities are nevertheless familiar to many experienced Linux administrators.

Conventions Used in This Book

The following typographical conventions are used in this book:


Indicates new terms, URLs, email addresses, filenames, file extensions, pathnames, directories, and Unix utilities.

Constant width

Indicates commands, options, parameters, and arguments that must be substituted into commands.

Constant width bold

Shows commands or other text that should be typed literally by the user. Also used for emphasis in code.

Constant width italic

Shows text that should be replaced with user-supplied values.

[ Keywords and other stuff ]

Indicates optional keywords and arguments.

{ choice-1 | choice-2 }

Signifies either choice-1 or choice-2.


This icon signifies a tip, suggestion, or general note.


This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Asterisk: The Future of Telephony, Second Edition, by Jim Van Meggelen, Leif Madsen, and Jared Smith. Copyright 2007 O’Reilly Media, Inc., 978-0-596-51048-0.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Books Online


When you see a Safari® Books Online icon on the cover of your favorite technology book, that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international or local)
(707) 829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:


To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our web site at:



Firstly, we have to thank our fantastic editor Michael Loukides, who offered invaluable feedback and found incredibly tactful ways to tell us to rewrite a section (or chapter) when it was needed, and have us think it was our idea. Mike built us up when we were down, and brought us back to earth when we got uppity. You are a master, Mike, and seeing how many books have received your editorial oversight contributes to an understanding of why O’Reilly Media is the success that it is.

Thanks also to Sanders Kleinfeld, our copy editor, Laurel Ruma, our production editor, and the rest of the unsung heroes in O’Reilly’s production department. These are the folks that take our book and make it an O’Reilly book.

Everyone in the Asterisk community needs to thank Jim Dixon for creating the first open source telephony hardware interfaces, starting the revolution, and giving his creations to the community at large.

Thanks to Tim O’Reilly, for giving us a chance to write this book.

To our most generous and merciless review team:

  • Rich Adamson, President of Network Partners Inc., for your encyclopedic knowledge of the PSTN, and your tireless willingness to share your experience. Your generosity, even in the face of daunting challenge, is inspiring to us all.[1]

  • Tilghman Lesher, for an incredibly thorough review of our book, contributing some much needed time toward Appendixes B and F, in addition to some amazing new Asterisk applications and functions.

  • Andrew Kohlsmith, for helping to write the IMAP voicemail storage section in Chapter 14.

  • David Troy, for providing a technical review, for AstManProxy, and for porting Asterisk to the Roomba (first PBX to run on a vacuum cleaner!).

  • Matthew Gast, fellow O’Reilly author, for reading our book from cover to cover, and then giving us a comprehensive review, and also for T1, The Definitive Guide.

  • Dr. Edward Guy III, for your comprehensive and razor-sharp evaluation of each and every chapter of the first edition, and for your championing of Asterisk.

  • Kristian Kielhofner, President, KrisCompanies, and creator of AstLinux, for the most excellent AstLinux distribution.

  • Russell Bryant, for your rapid and helpful responses to our questions.

  • Joshua Colp, for helping us with performance tweaking, and still more questions.

  • Kevin Fleming, for raising the bar, and for being a class act, respected (dare we say loved) by all.

  • Brian Capouch, for talking about what is possible, and then going out there and doing it.

  • Stephen Uhler, for championing the port of Zaptel to Solaris, and for giving us some golden examples.

  • Jason Parker, for not being a newb.

  • Ekke Loo, for beating up the database chapter.

  • Ian Darwin, for tweaking some of the verbiage for us, and for the cherry-red rotary dial phone (that works with Asterisk!).

  • Joel Sisko, CEO, iConverged, for your comprehensive telecom and wiring knowledge.

Finally, and most importantly, thanks go to Mark Spencer for Gaim (recently renamed Pidgin, www.pidgin.im), Asterisk, and DUNDi, and for contributing his creations to the open source community.

Jim Van Meggelen

For me, it all started in the spring of 2004, sitting at my desk in the technical support department of the telecom company I’d worked at for nearly 15 years. With no challenges to properly exercise the skills I had developed, I spent my time trying to figure out what the rest of my career was going to look like. The telecommunications industry had fallen from the pedestal of being a darling of investors to being a joke known to even the most uninformed. I was supposed to feel fortunate to be one of the few who still had work, but what thankless, purposeless work it was. We knew why our industry had collapsed: the products we sold could not hope to deliver the solutions our customers required—even though the industry promised that they could. They lacked flexibility, and were priced totally out of step with the functionality they were delivering (or, more to the point, were failing to deliver). Nowhere in the industry were there any signs this was going to change any time soon.

I had been dreaming of an open source PBX for many long years, but I really didn’t know how such a thing could ever come to be—I’d given up on the idea several years before. I knew that to be successful, an open source PBX would need to effectively bridge the worlds of legacy and network-based telecom. I always failed to find anything that seemed ready.

Then, one fine day in spring, I half-heartedly seeded a Google search with the phrase “open source telephony,” and discovered a bright new future for telecom: Asterisk, the open source Linux PBX.[2]

There it was: the very thing I’d been dreaming of for so many years. I had no idea how I was going to contribute, but I knew this: open source telephony was going to cause a necessary and beneficial revolution in the telecom industry, and one way or another, I was going to be a part of it.

For me, more of a systems integrator than developer, I needed a way to contribute to the community. There didn’t seem to be a shortage of developers, but there sure was a shortage of documentation. This sounded like something I could do. I knew how to write, I knew PBXes, and I desperately needed to talk about this phenomenon that suddenly made telecom fun again.

If I contribute only one thing to this book, I hope you will catch some of my enthusiasm for the subject of open source telephony. This is an incredible gift we have been given, but also an incredible responsibility. What a wonderful challenge. What a cosmic opportunity. What delicious fun!

First of all, I need to thank Leif and Jared for inviting me to join the Asterisk Documentation Project. I have immensely enjoyed working with both of you, and I am constantly amazed at how well our personalities and skills complement each other. A truly balanced team, are we. Also, thanks goes to Figment for all the typing.

To my wife Killi, and my children Kaara, Joonas, and Joosep (who always remember to visit me when I disappear into my underground lair for too long): you are a source of inspiration to me. Your love is the fuel that feeds my fire, and I thank you.

Obviously, I need to thank my parents, Jack and Martiny, for always believing in me, no matter how many rules I broke. In a few years, I’ll have my own teenagers, and it’ll be your turn to laugh!

To Mark Spencer: thanks for all of the things that everybody else thanks you for, but also, personally, thanks for giving generously of your time to the Asterisk community. The Toronto Asterisk Users’ Group (http://www.taug.ca) made a quantum leap forward as a result of your taking the time to speak to us, and that event will forever form a part of our history. Oh yeah, and thanks for the beers, too. :-)

Finally, thanks to the Asterisk Community. This book is our gift to you. We hope you enjoy reading it as much as we’ve enjoyed writing it.

Leif Madsen

The road to this book is a long one—nearly three years in the making. Back when I started using Asterisk, possibly much like you, I didn’t know anything about Asterisk, very little about traditional telephony, and even less about Voice over IP. I delved right into this new and very exciting world and took in all I could. For two months during a co-op term, for which I couldn’t immediately find work, I absorbed as much as I could, asking questions, trying things and seeing what the system could do. Unfortunately very little to no documentation existed for Asterisk, aside from some dialplan examples I was able to find by John Todd, and having questions answered by Brian K. West on IRC. Of course, this method wasn’t going to scale.

Not being much of a coder, I wanted to contribute something back to the community, and what do coders hate doing more than anything? Documentation! So I started The Asterisk Documentation Assignment (TADA), a basic outline with some information for the beginnings of a book.

Shortly after releasing it on my web site, an intelligent fellow by the name of Jared Smith introduced himself. He had similar aspirations for creating a “dead-tree” format book for the community, and we humbly started the Asterisk Documentation Project. Jared set up a simple web site at http://www.asteriskdocs.org, a CVS server, and the very first DocBook-formatted version of a book for Asterisk. From there we started filling in information, and soon had information submitted by a number of members of the community.

In June of 2004, an animated chap by the name of Jim Van Meggelen started showing up on the mailing lists, and contributing lots of information and documentation—this was definitely a guy we wanted on our team! Jim had the vision and the drive to really get Jared’s and my butts in gear and to work on something grander. Jim brought us years of experience and a writing flair that we could have hardly imagined.

With the core documentation team established, we embarked on a plan for the creation of volumes of Asterisk knowledge, eventually to lead to a complete library and a wealth of information. This book is essentially the beginning of that dream.

Firstly and mostly, I have to thank my parents, Rick and Carol, for always supporting my efforts, allowing me to realize my dreams, and always putting my needs ahead of theirs. Without their vision, understanding, and insight into the future, it would have been impossible to have accomplished what I have. I love you both very much!

I’d like to thank Felix Carapaica and Bill Farkas of the Sheridan Institute of Technology for their dedication to the advancement of knowledge. Their teaching has complemented my prior learning, and has allowed me to expand my understanding of routing and telecommunications exponentially.

There are far too many people to thank individually, but of particular importance, the following people were, and are, the most influential to my understanding of Asterisk: Joshua Colp, Tilghman Lesher, Russell Bryant, Steve Murphy, Olle Johansson, Steven Sokol, Brian K. West, John Todd, and William Suffill, for my very first VoIP phone (which I use to this day!). And for those who I said I’d mention in the book…thanks!

And of course, I must thank Jared Smith and Jim Van Meggelen for having the vision and understanding of how important documentation really is—all of this would have been impossible without you.

Jared Smith

I first started working with Asterisk in the spring of 2002. I had recently started a new job with a market research company, and ended up taking a long road trip to a remote call center with the CIO. On the long drive home we talked about innovation in telephony, and he mentioned a little open source telephony project he had heard of called Asterisk. Over the next few months, I was able to talk the company into buying a developer’s kit from Digium and started playing with Asterisk on company time.

During the next few months, I became more and more involved with the Asterisk community. I read the mailing lists. I scoured the archives. I hung out in the IRC channel, just hoping to find nuggets of Asterisk knowledge. As time went on, I was finally able to figure out enough to get Asterisk up and running.

That’s when the real fun began.

With the help of the CIO and the approval of the CEO, we moved forward with plans to move our entire telecom infrastructure to Asterisk, including our corporate office and all of our remote call centers. Along the way, we ran into a lot of uncharted territory, and I began thinking about creating a good repository of Asterisk knowledge. Over the course of the project, we were able to do some really innovative things, such as invent IAX trunking!

When all was said and done, we ended up with around forty Asterisk servers spread across many different geographical locations, all communicating with each other to provide a cohesive enterprise-class VoIP phone system. This system currently handles approximately 1 million minutes of calls per month, serves several hundred employees, connects to 27 voice T1s, and saves the company around $20,000 (USD) per month on their telecom costs. In short, our Asterisk project was a resounding success!

While in the middle of implementing this project, I met Leif in one of the Asterisk IRC channels. We talked about ways we could help out new Asterisk users and lower the barrier to entry, and we decided to push ahead with plans to more fully document Asterisk. I really wanted some good documentation in “dead-tree” format —basically a book that a new user could pick up and learn the basics of Asterisk. About that same time, the number of new users on the Asterisk mailing lists and in the IRC channels grew tremendously, and we felt that writing an Asterisk book would greatly improve the signal-to-noise ratio. The Asterisk Documentation Project was born! The rest, they say, is history.

Since then, we’ve been writing Asterisk documentation. I never thought it would be this arduous, yet rewarding. (I joked with Leif and Jim that it might be easier and less controversial to write an in-depth tome called Religion, Gun Control, and Sushi than cover everything that Asterisk has to offer in sufficient detail!) What you see here is a direct result of a lot of late nights and long weekends spent helping the Asterisk community—after all, it’s the least we could do, considering what Asterisk has given to us. We hope it will inspire other members of the Asterisk community to help document changes and new features for the benefit of all involved.

Now to thank some people:

First of all, I’d like to thank my beautiful wife. She’s put up with a lot of lonely nights while I’ve been slaving away at the keyboard, and I’d like her to know how much I appreciate her and her endless support. I’d also like to thank my kids for doing their best to remind me of the important things in life. I love you!

To my parents: thanks for everything you’ve done to help me stretch and grow and learn over the years. You’re the best parents a person could ask for.

To Dave Carr and Michael Lundberg: thanks for letting me learn Asterisk on company time. Working with both of you was truly a pleasure. May God smile upon you and grant you success and joy in all you do.

To Leif and Jim: thanks for putting up with my stupid jokes, my insistence that we do things “the right way,” and my crazy schedule. Thanks for pushing me along, and making me a better writer. I’ve really enjoyed working with you two, and hope to collaborate with you on future projects!

To Mark Spencer: thank you for your continued support and dedication and friendship. You’ve been an invaluable resource to our effort, and I truly believe that you’ve started a revolution in the world of telephony. You’re always welcome in my home and at my dinner table!

To the other great people at Digium: thank you for your help and support. We’re especially thankful for your willingness to give us more insight into the Asterisk code, and for donating hardware so that we can better document the Asterisk Developer’s Kit.

To Steven Sokol, Steven Critchfield, Olle E. Johansson, and all the others who have contributed to the Asterisk Documentation Project and to this book: thank you! We couldn’t have done it without your help and suggestions.

[1] In December of 2006, Rich passed away, as his two-year battle with cancer came to an unfortunate end. Rich was posting on the Asterisk Users mailing list as late as November of that year. He was giving to the community right up until the end, which is why we dedicated this book to him.

[2] To get a sense of how big the Asterisk phenomenon is, type “PBX” into Google. As you look at the results, bear in mind that the traditional PBX industry represents billions of dollars. The big players are companies such as Avaya, Nortel, Siemens, Mitel, Cisco, NEC, and many, many more. It is somewhat telling that they don’t seem to be concerned about how they rank in a Google search. As a cultural barometer, we’re pretty sure this matters.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required