Asterisk - build your own PBX

March 23rd, 2005 by Samuel Tardieu

Several people asked me to describe my home PBX installation, based on the Asterisk Open Source PBX in order to build their own.

Infrastructure

My home network is made of several devices; only those related to VoIP (voice over IP) are represented here:

PBX installation

My home phone line comes from France Telecom, the historical PSTN (Phone Switched Telephony Network) provider in France. When it arrives in France Telecom building (not represented here), my line is splitted in two parts: lower frequencies go to France Telecom equipment for voice processing while higher frequencies are distributed to equipment belonging to Free Telecom, my ADSL provider.

Free Telecom is an innovative player in the ADSL world. They distribute more than IP over ADSL. They have built their own ADSL modem, called the Freebox, which is lended to the clients. The Freebox can not only transport IP over ADSL, it also delivers an independent phone line (which itself uses VoIP internally on the Free Telecom network) as well as television. Not everyone can get television, it depends on the equipment installed by Free Telecom in France Telecom premises and on the line quality. As far as I am concerned, I get around 6Mb/s of download bandwidth and 400kb/s of upload bandwidth.

On the Free Telecom phone line, one can call any French landline number for free with illimited time. Also, the incoming number attributed to you by Free Telecom (you can even choose it) can be called from any France Telecom landline at a local rate, from anywhere in France.

This is all great, but two phone lines (France Telecom and Free Telecom) mean two physical telephones. Two voice mail systems. That’s why I installed Asterisk, a free software PBX system released under the GNU General Public License on one of my computer running the free Debian GNU/Linux operating system.

Hardware

I bought two DIGITX100P cards from DigitNetworks to interface my Asterisk PBX with the physical phone lines. Although the Free Telecom line uses VoIP while in the Free Telecom network, it can only be accessed through a regular phone plug if you use the Freebox. I have seen one report of someone using it directly with a MGCP client with a regular ADSL modem, but in this case you loose the Freebox other benefits such as TV.

Also, I bought two Grandstream Budgetone 100 phones. Those are IP phones; they connect to Asterisk using the SIP protocol. At this time, I only use one of them, I have yet to bring the network into the bedroom to use the other one (although I am not sure this is a good idea to have the network in the bedroom at all).

That’s about everything you need to build your own phone system. If you do not want to buy IP phones, you can either look for FXS interfaces allowing you to use regular phones or use softphones, computer programs that let you phone using a mike and headphones.

Placing an outgoing call

The goal of this system was that anyone could use it while staying at my place. I didn’t want people to do anything special to be able to place a phone call.

If someone dials the phone located on my desk, the phone will transmit the dialed number to Asterisk. Asterisk will first look whether it can reach that phone number using VoIP:

  • if the phone number is registered in the ENUM database, the published route will be used; for example, if someone uses this system with any of my phone numbers, he will automatically gets redirected to my Asterisk PBX without using any phone operator
  • several providers are tried, as some of them offer free call terminations in some countries or for some categories of numbers; for example, if I call a US toll-free number, I get several routes that I can use for free. That means that even from France, I can call US toll-free numbers without paying a dime. Moreover, the callee will not pay anything more than if the call had been placed from within the USA
  • if I really have to, one of my phone lines will be used, depending on their availability and on the number dialed; Free Telecom is often the preferred choice, although at some times in the day it is cheaper to use France Telecom to call French cell phones

The following picture shows (in green) a call placed on the IP phone at my place going out on the France Telecom line.

Outgoing PSTN call

The next one shows a call for which a VoIP route has been located and is being used. The call may reach a real PSTN phone at some other places, or may reach an IP phone if the target user uses VoIP.

Outgoing VoIP call

Incoming calls

Incoming calls can arrive in three different ways: the France Telecom line, the Free Telecom line or using VoIP. My firewall and router box (a lovely Soekris Net4801 disk- and fan-less PC running the free sofware OpenBSD operating system from a compact flash memory card) has been instructed to redirect incoming VoIP packets to my Asterisk PBX. So at the end, incoming calls are handled at the same place and will enter the same processing loop (with different parameters such as an identification of the incoming line).

The Soekris uses OpenBSD packet filter to provide QoS (Quality of Service) over my Internet connection. VoIP packets will get out first as long as there are no more than four simultaneous conversations. After that, the bandwidth will be shared with other applications to prevent a DoS (Denial of Service) attach on my VoIP server.

Depending on the caller ID, different actions may be taken. First of all, if the caller ID is unknown and the call came from the France Telecom line (the only one present in directories), the caller will be presented with a IVR (Interactive Voice Response) system. He will hear some messages asking him to press a certain key on his phone keyboard if he is not a telemarketer. If he confirms, he still needs to type my birth date to get through. Otherwise, Asterisk hangs up. This may sound harsh, but this has not been a problem so far (at least noone told me it was one), and I’ve screened probably many telemarketers phone calls.

Then Asterisk tries to present the call to me. In order to do that, it tries to reach simultaneously:

  • my IP phone at home
  • a VoIP softclient on my laptop, running Lunar Linux
  • any SIP or IAX softphone I could have registered from anywhere

The following pictures illustrates the case where a call comes from the PSTN through the Free Telecom phone line, goes to Asterisk, and goes out using VoIP to a phone registered from a remote location. The red lines show failures to either contact the client or get it to go off-hook.

Incoming PSTN call

Asterisk goodies

Asterisk by being a free software is easily expandable and benefits from a very active developpers community. The software is already excellent but gets better every day.

One feature I use a lot is AGI (Asterisk Gateway Interface), a communication mechanism allowing one to use any programming language to extend Asterisk. A simple textual protocol is used to exchange meaningful information between Asterisk and the module. For example, my whole dial plan logic has been coded using the Python programming language. My DISA (Direct Inwards System Access) is also coded in Python; it allows me to call home, authenticate myself, and do just as if I were there. For example, if I need to call abroad from my cell phone, it is much cheaper for me to call home and redial from there (especially if you consider that I often find free providers for the countries I call much such as the USA).

Asterisk also comes with integrated applications such as a powerful voice mail system (although you can write your own using AGI), DISA, IVR, text-to-speech and so on. Do not hesitate: build your own PBX system; you don’t have to buy any equipment to do that, you can first try to make a full VoIP system using free soft phones. Just do it. But be careful: you may be hooked very fast.

(you can also have a look at this blog entry)

Update: on 2006-05-16, Free Telecom opened their SIP server. It means that it is no longer necessary to use a FXO card with them. Log into your Free ADSL account and configure your SIP account.

54 Responses to “Asterisk - build your own PBX”

  1. Thomas Says:

    My suggestion for the bedroom network would be to have a separate VLAN there on which only the telephone is allowed… No DHCP lease for your laptop while in bed! (although you must be covered by Wifi already anyway…)

  2. Samuel Tardieu Says:

    I can reach three different wide-open WiFi spots from my bedroom (none of them being mine, I have none at this time).

    I could use a VLAN (I have a very cheap 100Mb/s switch which doesn’t understand VLANs, but my phones do). Or even a separate network as my Soekris router still has one free 100Mb/s port.

  3. Matt Riddell Says:

    Keep up the good work - so next you’ll be describing all the alterations you make as you go along?
    :)

  4. Alex Says:

    Great paper. I’m not a guru in VOIP but I’d like to make the following scenario with exactly your hardwares/software (Asterisk) and phone lines (2 X100P cards , Asterisk installed on a machine, 2 phones line - France Telecom and Free Telecom - and a routeur).

    ++ My mother lives in Marseille, my sister studies Telecommunication in Rennes and I live in Paris. I have the materials describe above. My mother want to talk with my sister in Rennes every night with a unlimited time, she calls me (my Asterisk server) and precises my sister phone number to Asterisk and in the same time lets her phone number. Then she hangs up. My server Asterisk then dials my sister phone number and my mother phone number using the Free Telecom line only if possible or with the two line in case I have too an unlimited credits time with FT line. As soon as my sister and mother pick up the phone, Asterisk switches on my sister and my mother and lets them talk together for an unlimited time. ++

    Is it possible to do this with Asterisk ? If no what will be your solution ?

    Thanks.

    Alex.

  5. Samuel Tardieu Says:

    The short answer is: you will be able to do what you want.

    You cannot use Asterisk to place two simultaneous calls on a unique Free line and connect them. A PBX is not supposed to use this kind of features over an analog line.

    However, connecting your Free and France Telecom lines is really easy. The scenario you describe is perfectly reasonable.

    However, rather than using your France Telecom line, why not find another person with the same setup as you and use her Free line at the same time as yours and connect both your PBX together over the Internet? You can even do that automatically (without looking for someone) by using services such as Jeff Pulver’s fwdOUT. This way, both outgoing calls will use Free lines, yours and another one.

    But be careful: your contract with Free Telecom may explicitely forbid you to use this kind of setup. More
    likely, you have accepted to pay a surcharge if this kind of setup is detected. Why is that so? Operators such as Free Telecom are being paid for every incoming call; they do have to pay for every outgoing one.

  6. Alex Says:

    Thanks Samuel.

    I understand. I know that Free Telecom does forbid such scenario on their contract, it was just for verifying my idea. Anyway I don’t suggest anyone to set up this scheme with the Free Telecom line.

    Also, if I summarize, the scenario is entirely possible if I have 2 free lines at home, isn’t it ?

    Regards.

  7. Samuel Tardieu Says:

    Sure!

  8. jipé Says:

    Hello,

    Is it possible to buy this cart ( DIGITX100P) in France?

    Thanks

  9. Samuel Tardieu Says:

    I don’t know, it is certainly possible to order it from the US and have it shipped to France as I did.

  10. Asteriskmanual.de Says:

    nice How-to-guide…

    we like it

  11. Wei Says:

    I am testing the Asterisk PBX installed under Fedora FC3 kernel 1.2.6.9-1.667 with 2 x100p cards connected with PSTN lines. It seams everything is fine bu the following problems found. Please advise how to configure the zaptel.conf, zapata.conf, and extensions.conf. My scenario is the following:

    Asterisk PBX installed in the computer with FC3;
    2 x100p FXO cards inserted in the PCIs, which can be connect with phone lines.
    1 or more sip phones connected with the PBX through Ethernet.

    I installed the zap drivers and configured the files as follows:

    /etc/zaptel.conf:

    loadzone = us
    defaultzone = us
    fxsks=1,2

    /etc/asterisk/zapata.conf:

    context=defauls
    signalling=fxs_ks
    callerid=asreceived
    group=1
    channel => 1,2

    /ect/asterisk/extensions.conf:

    [globals]
    CONSOLE => Console/dsp
    CONSOLE => Zap/1

    IAXINFO=guest

    TRUNK=Zap/g2
    TRUNKMSD=1

    [sip]
    exten => 8101,1,Dial(SIP/8101,20,rt)
    exten => 8101,2,Hangup()

    exten => 8102,1,Dial(SIP/8102,20,rt)

    ignorepat => 9

    exten => _9.,1,Dial(Zap/1/${EXTEN:1}@192.168.1.160,30,rtT)

    [default]
    include => international
    include => local
    include => sip
    exten => _9.,1,Dial(Zap/1/${EXTEN:1}@192.168.1.160,30,rtT)

    /etc/asterisk/sip.conf:

    [8101]
    type=friend
    username=8101
    secret=secrect
    canreinvite=no
    host=dynamic
    dtmfmode=rfc2833
    qualify=200
    nat=yes

    I compiled the zap driver:

    #modprobe zaptel
    #modprobe wcfxo
    #ztcfg

    Everything is fine up to now. I plug the line in the first x100p card and run the asterisk. Then I dialed the outside phone number from sip phone. It works. But when I plug out the line and plug it in the second x100p card and dialled the phone number but it sound busy and the screan of the pbx showed the following information:

    – Executing Dial(”SIP/8101-3b0a”, “Zap/1/17324941234@192.168.1.160|30|rtT”)
    in new stack
    Apr 26 09:00:00 NOTICE[3213]: app_dial.c:973 dial_exec_full: Unable to create channel of type
    ‘Zap’ (cause 0)
    == Everyone is busy/congested at this time (1:0/0/1)
    == Auto fallthrough, channel ‘SIP/8101-3b0a’ status is ‘CHANUNAVAIL’

    Please let me know what is wrong and how to correct it. Thanks a lot.

  12. Samuel Tardieu Says:

    Sorry, I don’t have the time for private Asterisk consulting right now. You should post your question onto the Asterisk users mailing-list.

  13. Olf Says:

    I know that Eikonex sells Digium Cards in France.
    shop.eikonex.net

  14. damien Says:

    salut

    je suis francais,j’ai vu que tu l’étais aussi. pourrais tu m’envoyer cette documentation en francais si tu l’as.

    a bientot

    I’m french, like you. could you send me this documentation in french if you have it.

    see you

    damien

  15. Samuel Tardieu Says:

    Sorry Damien, I haven’t translated this document (which is certainly not a documentation, only an explanation of my setup).

  16. Dave Says:

    Nice one :)

    You can use a good short cut with our free distribution for asterisk :
    http://www.xorcom.com/rapid

  17. Kristinn Reykdal Says:

    Nice Asterisk setup there :) I was just wondering if you could make (some) of your asterisk configuration files available for the public?

    best regards.
    KR

  18. Samuel Tardieu Says:

    Kristinn: my configuration files are not that original, with the notable exception of extensions.conf. The latter is almost empty and redirects everything with an AGI script I wrote in Python which handles everything (it was easier to do for me than coding very complex rules directly in extensions.conf).

    For example, when I pick up my home phone, the following rules are applied:


    [fromsam]
    exten => _X.,1,SetAccount(sam)
    exten => _X.,2,AGI(/usr/share/asterisk/pycode/appli.py,
    dial,${EXTEN},costly_calls_ok,from_france)

    The costly_calls_ok flag allows me to use non-gratis lines, and from_france tells my Python script that numbers not in the international format are to be converted if outgoing peers are used.

  19. arshad Says:

    i have no experience in voip but i wouldlike to use your system not in france in pakistan can u guied me what i can do is it possible or not …
    thanks arshad

  20. JP FOLLEGOT Says:

    You wrote : “I have seen one report of someone using it directly with a MGCP client with a regular ADSL modem, but in this case you loose the Freebox other benefits such as TV.”

    As I cannot get TV services I am interested indeed in how to use Free Telephony without a FreeBox.

    Can you let me know ?

  21. Samuel Tardieu Says:

    JP: the mail I referreded to is this one.

  22. nad Says:

    hi guys
    i am not a linux person , i am treing to learn it now , and i am treing to get asteriks with sues …..but how can i install it..? do you think i should get anather version of linux..?>
    i just do not know how to install applications on linux…help….
    i leave here my e-mail if anyone really wants to help.

    thanks
    nadirm63561@yahoo.com

  23. walter Says:

    deseo bajar un software telecom france para chat en sala francesa

  24. Joel Says:

    Hi Samuel,
    What special parameters have you done to interface your FXO to Free ??? On my system, interfacing to FT does work, but If I plug my FXO to Free, It does not work. When I dial a number, I got strange noise, and no ring at the other end; For incoming call, the line does ring at home, but Asterisk does not answer it …

  25. Thought Leadership Says:

    Outstanding Questions on VoIP

    Here is what is wrong with current thinking on VoIP…

  26. jdavid Says:

    I’d be interested to know if your soekris acts as mere router or if it is also handling a pppoe connection to your provider.
    I believe bridging the adsl modem while keeping the voice service up and running might be quite complicated taking NAT
    for granted.
    I’m actually using a tecom AH4021 with quite limited busybox telnet access with no idea, at this time, how to use their
    brctl utility.

    regards
    jd

  27. Samuel Tardieu Says:

    jdavid: it is acting as a router. My ADSL connection is handled by the dedicated Freebox hardware (which does IP, VoIP and TV over ADSL).

  28. Samuel Tardieu Says:

    Joel: no special parameter. It just works :)

  29. 脚鱼的窝 » Blog Archive » PC和电话 Says:

    [...] 随着电脑的越来越强大,很多事情都能让电脑来完成,今天来谈谈电话。 简单的说,所有电话的功能现在电脑都可以完成,打/接电 话,传真,留言。Windows下有这样的软件,不过都是商业的,一个字,钱,而且windows实在不适合干这个,你想想,正打电话呢,蓝屏了,咋办? 所以嘛,当然用Linux,全部免费,只要你的机器有Modem,声卡可选,最好是用一台破机器当服务器,顺便当个网关和做其他服务。 http://linuxgazette.net/120/smith.html http://www.rfc1149.net/blog/2005/03/23/asterisk_build_your_own_pbx/ http://www.asterisk.org/ http://asteriskathome.sourceforge.net/ [...]

  30. Serge Says:

    Hello,
    Would it be possible to see your appli.py code? I’m testing your solution with a freebox.

    Regards

    Serge

  31. francois Says:

    Hi,
    What is really the X100P card, isn’t a simple modem after all? is it possible to set up the same system by using a modem?
    anyway good job, i wanna do the same. is it possible to have your configurations files? i have the exact same configuration at home.
    cheers

  32. redouane Says:

    Hello. which port did you use to connect Asterisk to your Freebox? FXS or FXO?

    Thanks

  33. Samuel Tardieu Says:

    Serge: the code contains too much hard-coded values to be useful for anyone else
    francois: yeah, hacking a linmodem should be doable
    redouane: FXO of course, the Freebox is seen as a regular analog phone line.

  34. redouane Says:

    freebox has a telephone plugged into which made me think it was a FXS connector

  35. Samuel Tardieu Says:

    If you want to connect to the Freebox, you need a FXO interface. If you want to connect to an analog phone, you need a FXS interface. See this page for more info.

  36. redouane Says:

    Gotcha!

    Thanks

  37. Bengali Says:

    Hi,

    I have got a FreeBox too and I connected to a x100p fxo card (bought on Ebay).
    My problem is that hangups from incoming calls on my Free PSTN line are not
    well detected. Did you experience such issues ?

    Here’s my zaptel.conf:
    fxsks=1
    loadzone=fr
    defaultzone=f

    and my zapata.conf:
    [channels]
    busycount=4
    context=default
    signalling=fxs_ks
    usecallerid=yes
    echocancel=yes
    callgroup=1
    pickupgroup=1
    immediate=no
    rxwink=300
    channel=>1

    If you think that a parameter is irrelevant or should be changed
    let me know
    I don’t have any other FXO card, any other PSTN line,so
    I have difficulties to determine what ’s involved in this
    Thanks
    Luc

  38. Samuel Tardieu Says:

    Bengali: I take your defaultzone=f is a copy-paste mistake, it should read defaultzone=fr.

    Don’t you have to use busydetect=yes as well? I don’t remember what the default is.

  39. bengali Says:

    Thanks for replying,
    yes defaultzone=f was a typo and should have been read defaultzone=fr
    For busydetect I tried to enable it but it didn’t change anything.
    I guess that the PSTN line coming out from the Freebox is not a traditional one
    and might need some tweaking.
    I have also tried tips from http://www.asteriskguru.com/tutorials/resolving_hangup_detection_problems_fxo_tdm_voicemail.html
    without any success. Too bad,
    Asterisk is so much fun.

  40. MJM Says:

    Hi. I am trying to run Asterisk at the office and I have a question. How, using AGI with php, Asterisk within the dial plan would send a request to another server who will consult the SQL database and get back to Asterisk with a response. Should they talk using web page!. An addition to your diagram will be appreciated showing the result.

    Thank you,

    MJM

  41. Xavier de Labouret » Blog Archive » Mettre en place son propre PBX à la maison Says:

    [...] C’est par là. [...]

  42. Dominique Says:

    Hi Samuel,

    I am French too.
    I am contemplating to quickly (before the end of June) implement a system that should automatically call a tel number and deliver a pre-recorded message (such as wav, stored on my pc). The call should be initiated based on an event.
    It should be able to call up to 3 to 4 tel numbers at the same time and potentially receive calls (at least on one of the lines).

    Until I discovered Asterix, I intended to buy a software (Voiceguide), buy a tel card (4 to 8 lines), write some code (so that when the event occurs, the call(s) is initiated) and make connections through VoIp provider.

    I would like to know :
    1/ if Asterix can do the job,
    2/ if in that case, it would also be necessary to have a tel interface card,
    3/ if it is a complex implementation (I do some Python programming, Python is close to Perl), and what are the major steps I should do in this respect (should I install Asterix@Home, how to initiate automatic calls, how to tell Asterix which tel numbers to call,….)
    4/ and if such a project can be done quickly. How long would it take ?
    5/ Any advices ? Which VoIp provider to choose (I am located in France)

    Many thanks for reading me and for answering or at least giving me some clues (I could not find any website easily readable by a newbie)
    Thank you in advance and congratulations for your nice blog

  43. Samuel Tardieu Says:

    Dominique : this is totally feasible, without any programming, using the “outgoing call” feature of Asterisk. As far as the VoIP provider is concerned, you should try out Wengo.

  44. redouane Says:

    I wonder if it is feasible to free up a incoming pstn lines by transfering to an internal extensions. So when people call they don’t get a busy tone on that analogic lines.

    Thanks

    Redouane

  45. Samuel Tardieu Says:

    redouane : why use an analog line at all when you can avoid it?

  46. Dominique Says:

    Thank you very much Samuel for your swift answer.
    I need some advices:
    - Can Asterisk be run on Windows (as seen in voip-forum.org although not mentioned on the Asterisk.org website) ?
    - If Linux preferable (yes ? No ?), which Linux distribution should be used ? Redhat ? or just Asterisk@Home which includes CentOs?
    - I understand if I just want to do VoIp, I don’t need an interface telephone card ? Right ?

    Thank you very much

  47. redouane Says:

    This does not answer my question. Mainly because that analog line is widely used and published on the telephone directory.

  48. benoit Says:

    Hi Samuel,

    I’m living in north of France. I bought few weeks ago two gigitnetworks X100p cards. I put them on a PC with AAH 2.8.

    I just asking you if with your card you collect callers number

    I try with AAH 2.8; Mandriva 2006 + asterisk 1.2.7 or Trixbox 1.0

    I answer the line but I never get the caller’s number.

    If I put an analogic phone on this line I get the caller’s number on it.

    My question is simple :

    Do you collect the caller’s number on your PSTN interface with FT ?

    If yes, can you tell me if you had a problem to collect it and how do you solved it ?

    What are your version of asterisk and Co ?

    Thank you for the time you spend (or waste) to answer me.

    Sincerely

    Please excuse my english, I’m a french who speak only two languages : The french and the Ch’ti

  49. benoit Says:

    Hello,

    Nobody with X100P Digitnetwork and asterisk who collect phone numbers ?

    Thanks

  50. redouane Says:

    What kind of digital card can you plug into Asterisk to get a Numeris (RNIS or ISDN) dual channels line?

    Thanks!

    Redouane

  51. nsmal Says:

    hello

    i want to spy on a chennel listen the voice conversation between two person.

    i also want talk to one of them but others will not listen my voice.

    how can i do this
    and also let me know wether chanspy will solve it.

    Thanks.
    Nsmal

  52. JR Says:

    Hi,
    I installed an fxo card, but I only wanna use my landline for outbound calls but asterisk@home is picking up my phone. How do I stop asterisk from answering the phone? I wnat it to answer sip calls but not zaptel calls. thnks

  53. pepito Says:

    I’d like to use trixbox for VOIP of course but also for DTMF recognition. Does trixbox can inform an other program that a DTMF code is received and transmit the value?.
    Of course I can do that by hard, but it’s more esthetic to use soft.
    Thanks

  54. Alexander Says:

    Hi, Sam. I live in Rio de Janeiro (Brasil) and have read your blog. I found lots of good information and hints about Asterisk usage and configuration. But there’s a doubt of mine that I could not see: is it possible to use an IP phone outside one’s LAN, connected to Asterisk PBX inside this LAN? This question is due to my family being split between Brasil and London. I would like to set up an Asterisk PBX at home, but having an extension at my sister’s home at London. So, I would be able to call her anytime, and the reverse, as an internal connection using VoIP over the Internet. Is such procedure possible?

    Thanks for your kind attention.

Leave a Reply


Creative Commons License