What is the best way to connect multiple FreePBX together?


I have a SIP provider with 20 channels that can be shared between multiple numbers.

Because of the number of businesses and phone numbers, I’d like to keep the FreePBX installs seperate, but pool all incoming and outgoing calls via my own SIP trunk package (with the supplier).

That way, I can pool all the channels, so for example, if I have 100 channels (to keep things simple), and company A only uses 40 but sometimes needs 60 and company B uses 50 but sometimes needs 60 - I don’t have to buy 120 channels, I can just buy the 100 channels and get an alert if I ever reached anywhere near total capacity (which I never would, as these aren’t call centers)

So what I was thinking was having the main central FreePBX, then having child FreePBX installs per seperate business (so they could have their own internal extensions and call transfers etc yet is trunked through my central FreePBX for outgoing calls.

Is this possible?

I was thinking of having something like this:

                     Main Routing FreePBX Server

      Company 1                      Company 2                 Company 3


I initially thought of setting up extensions on my Main Routing FreePBX server, so that Company 1 Company 2 and Company 3 could connect via Trunks to that server? But it doesn’t seem to be working, and before I go too indepth with this I figured I’d check to see what general opinion is on doing this kind of thing?


This is doable. I’ve done the same scenario, sort of. I have configured a “Call Router” so to speak, that is nothing more than a fresh FreePBX Distro install with inbound DIDs, outbound routes, and trunks configured to my provider. That system is what routes all the phone calls of my other FreePBX systems. The “child” FreePBX servers just handle endpoint registrations, etc.

I connect them all to my Call Router using an IAX trunk on both ends.

How do you get two trunks to connect to each other? I thought trunks just connected to an account on another server?

Also, why IAX over PJSIP?

Let’s say you have PBX1 and PBX2.

You need an IAX trunk on PBX1 that connects to PBX2 and an IAX trunk on PBX2 that connects to PBX1 to establish a connection between the two boxes.

As far as why IAX over PJSIP - I think it’s a matter of preference, but IMO IAX is much easier to work with when connecting FreePBX boxes together.

Give this a read:

I would also go with IAX and DUNDi

DUNDi? How would that tie in?

So from reading that article, you never actually create the authentication accounts as such - but as long as the authentication details MATCH each other, the two trunks connect?

Shortly after starting this thread and before the first reply, I actually got it up and running by simply creating an Extension on the Root Server and then connecting a trunk on a Child Server to the root?

But I want this doing properly. So I should definitely not do it this way, and create two matching trunks?

Is this just ‘the proper way to do it’ and has no added benefits, or does it help things like Caller ID pass through etc?

Thanks again

That is correct John. You need an IAX connection (no authentication details needed) on both ends of the systems you are connecting together.

I will say that I have had issues with caller ID pass through using these methods in the past though, and never really have gotten it to work 100% of the time. Maybe someone can chime in on that aspect here.

So does caller ID work sometimes? Or not at all when using that method?

It would be quite crucial for it to work I think.

And are you talking about inbound or outbound? It works inbound on the Trunk > Extension method I’ve setup now (which is the most important direction for it to be working on)

The best way to go would be IAX.

DUNDi is then used basically to route calls between PBXs.
Take a look at this link for an introduction

I would comment that all of dundi iax2 whatever although marginally possible, will cause you blood sweat and tears in the long run as asterisk is intrinsically a back2back user agent, so will always be a serious resource iser and just generally be a PITA to manage.

What does work however (and is designed be just what you were asking for) is a SIP proxy, I use kamailio/siremis .but any one will do. No muss no fuss, all calls in and out go through the proxy, One point of ingress to ids/firewall protect, the ability to cluster several proxies with or without BGP (but that makes it much cleaner) or perhaps add SRV lookups to your dns domain source

Woah this opens a whole new can of worms

It seems kamailio is really cool!

So does that open itself up via the firewall and then let freepbx’s connect to it?

Whats a basic simple standard structure of that kind of setup? (Ive had a scan across their site already)

No, the firewall/ids would be all up to you , but you only need to alliw your nachines and vsp’s in so the rules are simple nd the Asterisk box only needs to allow rhe proxy in any external extensions wiuld be also proxied. through to the correct pbx, plenty of info out there for kamailio/asterisk integration and for the cli averse there is Seremis

So simply, wverything goes through the.proxy machines and you just

There is also the fact that IAX2 is no longer developed officially. It’s community based. It has a lot less documentation and support available for it and what it was meant to solve before is not longer a problem that needs solving.

Additionally, DUNDi has been dead for years. It was a hobbyist idea that never gained any real traction anywhere. IAX2 had/has more traction in the industry than DUNDi.

Finally, Asterisk is a B2BUA not a SoftSwitch/SIP Proxy/Router. “Switching” your calls through Asterisk is added extra channels and legs to your call that are just more points of failure and problems. Not to mention more chances for the media to be touched, lost or somehow screwed up.

When you do it like this, with Asterisk being a “switch” the route is Carrier <–> Asterisk. That’s it. That’s as far as an inbound call from a carrier cares about. The Asterisk box it peers with. It doesnt know/care about anything beyond that. Same with outbound calls, the phones are only going to know/care about the Asterisk/PBX box they are connected to. As far as they are concerned as long as that Asterisk box accepts their call, it’s a call at that point to the device. It won’t know that call is being hopped through 1 or 2 more Asterisk boxes because each new hop is a new call that’s just a bunch of channels being bridged together over multiple servers.

This is not how any ITSP/VoIP provider should be handling calls between the PSTN and their end users.

OK thanks guys - now I know how definitely not to do it, and also maybe not to use IAX and definitely not to use DUNDi?

So to summarise, before I go off and spend my time learning Kamailio and Seremis (which looks awesome so I will definitely make time for it):

Are we saying Kamailio basically structures like this:

External SIP Provider > Kamailio >>> Asterisk 1 / 2 / 3 etc?

yep, exactly that , the DIDs will be unique , so just ‘route’ them individually or by regex through the appropiste ‘trimk’ to the individual PBIi’s
Similarly asterisk[223] >>> proxy > prodir of choice , often determined by ‘least cost’ but you can easily do it some other way.

That’s incredible, and could drastically reduce the overheads caused by running Asterisk just as a routing device!

I did notice (but not sure if I’m imagining it) I could feel the delay almost in connecting the call - going through both Asterisk servers just felt a bit more ‘clunky’ - i’m guessing you don’t have this effect with running a SIP proxy.

There’s almost no delay. Since Kamailio has been mentioned before, the same server specs running Kamailio vs running Asterisk will always see Kamailio handle 1,000’s of SIP transactions without really pushing the needle up or breaking a sweat. At the same time those would bring Asterisk to it’s knees or slow it down by a lot.

Generally the proxies are handling 1,000’s of SIP transactions and “load balancing” them between the Asterisk server farm so each server can handle processing calls without crapping its pants.

1 Like

Again, you CAN’T use Asterisk as a “routing device”, it doesn’t route , it is a B2BUA, so is always in the path, even when you allow redirection of the RDP session it creates for the media (not just voice and video are suppported)

So do you usually have a Kamailio server in the cloud and your Asterisk servers on private networks behind NAT firewalls?