Installing a FreePBX with FritzBox as trunk on a Raspberry Pi

Full-blown telephony solutions are just a few steps away, and that all with open-source components and your AVM FritzBox as a trunk to connect via your existing ISDN or analog lines and DECT or analog telephones. With a US$35 investment into a Raspberry Pi, FreePBX, an Asterisk variant, and this manual. 

What you can expect from FreePBX with a FritzBox:

  • Powerful full-blown telephony system with conference calls, pickup function, ring groups, voicemail, interactive voice systems, follow me functions etc. pp. for probably 10-15 extensions, ideal for SOHO applications
  • All with your existing (or cheap to buy) hardware

Prerequisites:

  • A Raspberry Pi Model B and an SD card
  • A FritzBox Fon WLAN (here I am using the 7390)

Instead of buying a Raspberry Pi you could also install a PBX on your Synology Diskstation NAS. Even though I own one, I decided for the Raspberry since I don’t want to have the harddisk of my NAS to always run and also Synology only supports Asterisk without the much easier to use FreePBX configuration interface.

Steps to install:

  • Download the Raspberry Pi pre-compiled FreePBX package (so-called IncrediblePi) from here. Look after the latest version IncrediblePi-Debian package, download and extract. Follow the installation instructions inside (in readme file) to create an image onto your SD card.
  • Boot up your Raspberry Pi connected to your FritzBox’s LAN network with the prepared SD card and find out the IP address of your Raspberry Pi (e.g., by looking into the fritz.box network overviews).
  • Within fritz.box, create an IP telephone device, e.g. extension 620, and connect the incoming ISDN/analog line to it (for incoming and outgoing calls). I called my IP telephone/line “PBXCongstarLine1”. Repeat this step for further trunk lines.
  • Login into your FreePBX/Asterisk installation with a web browser (in my example: 192.168.178.36), username and password are both “admin” as default.
  • For each trunk line under 3. go to Connectivity/trunks in the FreePBX interface and enter the following parameters and submit changes and apply config afterwards:

Trunk name: e.g. PBXCongstarLine1
Outbound caller ID: Your external caller ID, e.g. 0234567890

Trunk name: e.g. PBXConstarLine1 (as you like)
Trunk details:
host=192.168.178.1 (your FritzBox IP)
username=620 (or the extension you got for your FritzBox IP telephone)
secret=*the password you chose in FritzBox*
type=peer
qualify=yes
dtmfmode=rfc2833
fromdomain=fritz.box
fromuser=620
disallow=all
allow=alaw&ulaw&g726
insecure=port,invite

User Context: 620
User Details:
context=from-trunk
secret=*password as above*
type=user
insecure=port,invite
fromdomain=fritz.box
disallow=all
allow=alaw&ulaw&g726

    • Go to Settings/Asterisk SIP settings and fill in the following parameters:

NAT: no
IP configuration: Public
Codecs: Activate ulaw, alaw, GSM and G726
Add another field down at other SIP settings with “insecure” = “port,invite”

  • Reboot your Raspberry Pi, typing in reboot.
  • After reboot, login to the FreePBX interface, you should now see an online IP trunk.
  • Now start adding phone extensions for each phone under Applications/Extensions within your FreePBX web interface.

Extension: e.g., 10
secret: 1234abc *take a safe one*
dtmfmode: RC2833
canreinvite: no
context: from-internal
host: dynamic
type: friend
nat: no
port: 5060
qualify: yes

  • Now if one of your phones is a DECT hardware telephone connected to your FritzBox (and not a SIP phone that can directly connect to your FreePBX installation), you need to create a Internet/SIP trunk line on your FritzBox for each telephone. In German FritzBox go to “Eigene Rufnummern” (own telephone numbers) and add an Internet line with the following parameters:

Telephony provider: Other
Internet telephone number: 10 (your FreePBX extension number)
username: 10 (same)
password: 1234abc
Registrar: 192.168.178.36 (your Raspberry Pi IP address)

  • Assign your hardware phones connected to your FritzBox to this trunk line by assigning incoming and outgoing numbers of the respective telephony device to this line under telephone devices (“Telefoniegeräte”).
  • Now you have to tell FreePBX how to dial out with your extension to the world by adding routes. Go to Connectivity/Outbound routes and enter the following parameters to let FreePBX dial every minimum 4 digit telephone number via the external trunk line (adjust accordingly for your number patterns):

Route name: e.g. All calls
Dial Patterns/match pattern: XXXX.
Trunk sequence for matched routes: Select the appropriate trunk line, e.g., PBXCongstarLine1

  • Now configure the incoming calls behaviour in Connectivity/Inbound routes and select the profile “Default any DID/any CID” to configure all incoming calls at the same time:

Set Destination: Extensions / 10

  • Now whenever a call is incoming, extension 10 will ring. All longer telephone numbers that you type into your phones will be routed external. Try to call your mobile, and try to phone internally between your extensions by dialling extension code 10, or 20. All should work by now. It might be that a reboot after full installation might help to get everything going.
  • A tip: If things are not working you should look into the log files of Asterisk. The easiest way is to go to Admin/Module admin and install the Reports module called “Asterisk Logfiles”. You can now supervise any calls under Reports/Asterisk Logfiles. If you need more detailed log details, you can install the module “Asterisk CLI”. Once installed, go to “Admin/Asterisk CLI” and then execute the command “sip set debug on”. The aforementioned log file will include all SIP details of all calls being handled.
  • Another hint: It might be that when you call your FreePBX  from external (e.g, your mobile) you get a free ring tone, but your properly assigned extension does not ring (in the log file you’ll find an error “Spawn extension (from-internal, 620, 8) exited non-zero on ‘SIP/10“. There is a bug in the current FreePBX installation, you can read it here. For me this resolves sometimes after waiting, and I cannot reproduce this error properly. Hope the developers fix this, but don’t worry, at least it is not your fault.

Please let me know if this manual proved to work for your setup as well and if you are using the Raspberry Pi FreePBX successfully in a live setting.

 

 
P.S. thanks to lgaetz at pbxinaflash forum we have now an easy and correct version of my manual!

Tags: , , , , , , ,

9 comments

  1. Hi, cannot get that configuration running with FB 7170. Box wont be going online at all. I tried:

    username=620
    type=peer
    secret=secret
    qualify=yes
    insecure=port,invite
    host=192.168.2.1
    fromuser=620
    fromdomain=fritz.box
    dtmfmode=rfc2833

    username=620
    type=peer
    secret=selter
    qualify=yes
    insecure=port,invite
    host=192.168.2.1
    fromuser=620
    fromdomain=fritz.box
    dtmfmode=rfc2833

    Now my trunk is online but not registered (I dont know if this has to be) but still not able to make or receive call…any idea?

    Thanks

    Tom

  2. Hi Tom, this behavior typically resulted from a wrong insecure setting when I was trying to get it to work. Did you make sure to follow this step:

    Go to Settings/Asterisk SIP settings and fill in the following parameters:

    Add another field down at other SIP settings with “insecure” = “port,invite”

    Please share if you find the solution – seems to be a small community if people using FritzBox as trunks for FreePBX/IncrediblePBX.

  3. Hi Mick,

    Add another field down at other SIP settings with “insecure” = “port,invite”

    I already did that before…I did follow exact your instruction

    You might wanna look at this log file:

    [2013-09-16 16:32:01] VERBOSE[3021][C-00000011] netsock2.c: == Using SIP RTP TOS bits 184
    [2013-09-16 16:32:01] VERBOSE[3021][C-00000011] netsock2.c: == Using SIP RTP CoS mark 5
    [2013-09-16 16:32:01] VERBOSE[5845][C-00000011] pbx.c: — Executing [040***@from-internal:1] ResetCDR(“SIP/202-00000014”, “”) in new stack
    [2013-09-16 16:32:01] VERBOSE[5845][C-00000011] pbx.c: — Executing [040***@from-internal:2] NoCDR(“SIP/202-00000014”, “”) in new stack
    [2013-09-16 16:32:01] VERBOSE[5845][C-00000011] pbx.c: — Executing [040***@from-internal:3] Progress(“SIP/202-00000014”, “”) in new stack
    [2013-09-16 16:32:01] VERBOSE[5845][C-00000011] pbx.c: — Executing [040***@from-internal:4] Wait(“SIP/202-00000014”, “1”) in new stack
    [2013-09-16 16:32:02] VERBOSE[5845][C-00000011] pbx.c: — Executing [040***@from-internal:5] Progress(“SIP/202-00000014”, “”) in new stack
    [2013-09-16 16:32:02] VERBOSE[5845][C-00000011] pbx.c: — Executing [040***@from-internal:6] Playback(“SIP/202-00000014”, “silence/1&cannot-complete-as-dialed&check-number-dial-again,noanswer”) in new stack
    [2013-09-16 16:32:02] VERBOSE[5845][C-00000011] file.c: — Playing ‘silence/1.ulaw’ (language ‘en’)
    [2013-09-16 16:32:03] VERBOSE[5845][C-00000011] file.c: — Playing ‘cannot-complete-as-dialed.ulaw’ (language ‘en’)
    [2013-09-16 16:32:05] VERBOSE[5845][C-00000011] pbx.c: == Spawn extension (from-internal, 040***, 6) exited non-zero on ‘SIP/202-00000014’
    [2013-09-16 16:32:05] VERBOSE[5845][C-00000011] pbx.c: — Executing [h@from-internal:1] Hangup(“SIP/202-00000014”, “”) in new stack
    [2013-09-16 16:32:05] VERBOSE[5845][C-00000011] pbx.c: == Spawn extension (from-internal, h, 1) exited non-zero on ‘SIP/202-00000014’

    Anything you can see from here?

  4. Hi,
    I am wrestling a couple of days with asterisk and fritzbox, but I am not so enthousiastic about FreePBX. It does not show up as de documentation tells me. So, I would rather know how you conf-files look like, especially sip.conf and extensions.conf. Could you send them to me, please. I would appriciate that very much.
    Kind regards,
    Roel

  5. Hi Roel, Unfortunately currently I don’t have a set of configuration files at hand. If you follow my instructions within FreePBX, you can then look into the (automatically generated) conf files. Sorry not to be of better help, but maybe another user can send one?

  6. Eleftherios Chamakiotis

    Hi and thank you for your tutorial, at least I now know that I’m not the only one trying to make this work!

    First a couple of things on my configuration: I have two FB 7170, one with an analog (PSTN) line and one with an ISDN line. Both also have two analog phones connected to them.

    I followed your suggested setup, but I have two problems:
    1) Most of the time, when I call one of my phone numbers from my mobile (or other external line), I get a “username mismatch” in the logs. If I change a setting in the configuration of the telephone devices on both FB and save the config, or restart the FBs, everything works fine until I do “sip reload” in Asterisk (due to a config change). Then I get the “username mismatch” again. My understanding is that it has something to do with the fact that FB configures the 620, 621 etc extensions as SIP extensions, but asterisk considers them as trunks… Am I making any sense? Any advice?

    2) I have two sets of SIP/DECT phones connected to asterisk, one Snom M3 and one Siemens Gigaset N300A IP. The Snom phones work fine (both outgoing and incoming, internal and external). The Siemens phones though work fine for internal calls and can receive external calls fine, but when making external calls, they don’t get the “ringing” signal (while waiting for the callee to answer) and they also miss a couple of seconds when the callee picks up. Any clues as to why this happens?

    Sorry for my long comment, I hope you can help me out…

    P.S. Funniest thing is that that the same FBs, with the same phone lines and internal devices (analog phones and SIP/DECT ones) and almost the identical configuration, works fine on my old Trixbox setup…! I just want to get rid of an old computer running Trixbox and replace it with a Raspberry…

  7. Mundl Sackpower

    Hello, First I want to thank your for this very good and helpful tutorial.

    I’m using two Fritz!Boxes, one FB 7270 with an USB-Modem-Stick for VOIP-Phonecalls and one FB 7240 with an USB-Stick as a GSM-Gateway. I’m now struggling for some days with two problems:

    1) I can call out without problems, but incoming calls never come to the IP-Phones (in my case SNOM 300 Phones). I did take care about the SIP Setting “insecure”=”port,invite”, but this also did not help.

    2) I cannot call from an DECT-Phone registered with the FB 7240 to the IP-Phone registered with the FreePBX-Installation on the Raspi. Fritz!Box gives the DECT-Phone the internal number **610 and I don’t know how to call to this?

    Any help on this two issues would be appreciated very much.

    Thanx, Sackpower

  8. The bug you mentioned at “another hint” is really hurting me. after a restart everything works fine. but when i change the dailplan everything went down. and i receive the described error on all incoming calls. the post you linked in your description is quite old (from 2011) so i am concerned that they will fix it.

    has anyone new information on this?

    why is an call from external interpreted as an call from internal. if i deactivate ALL “eigene rufnummern” on the fritzbox directing to the freepbx host, the error disappears.

  9. i have tried this and it works fine for voice. i am having problems with faxing.
    ISDN line with 3 numbers in fritzbox 7170. one onumber in each port and faxing on analog machine works fine. delete each analogue port and create three extensions 620-622 to asterisk. Voice is fine, faxing does not work. has anyone got any ideas, please?

Leave a Reply

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