Complex multi-PBX setups with Asterisk

The greatest feature of the Asterisk IPBX is the dialplan. Basically, sources (extensions, incoming calls, inteal applications) and destinations (outgoing calls, extensions at other PBXs, inteal applications) are mapped as contexts on this dialplan thingy. The dialplan lives on the extensions.conf file, or those that are included, such as extensions_custom.conf on FreePBX setups.If you already write your own dialplan, consider yourself an Asterisk hacker and you’ll probably want to stop reading. However, if you wonder how to interconnect multiple Asterisk PBXs, especially when using a Web-based administration interface such as the ones found on Elastix, Trixbox and home-brewed FreePBX-based solutions, then keep reading, I hope it’s edifying and entertaining.Assume you have three locations which need PBX service. In my case, those are Quito, Cuenca and Guayaquil. They are interconnected using a telco E1 connection, full-data. They’re on separate private /24 blocks, but they see each other just fine.First of all, ask yourself if you really need to provide PBX service to each location. I mean, do you need to offer point-to-point communications even when the third party is down? But then, isn’t your E1 connection a single point of failure? You need to decide this before deciding to offer local PBX services, since it’s obviously cheaper to maintain just one PBX. And if you only need one PBX, then you might also stop reading.That said, the advantages of providing a local PBX are:

  • Faster response for applications such as voicemail, directory, IVRs et al.
  • Ability to take profit of local PSTN connections, for example, an existing FXO
  • In case of failure of one site, you can communicate the others, provided the communication channel is stil there
  • Administration becomes delegable if your setup is big enough to justify local admins

If you want to take advantage of having a local PBX, then you’ll create the local extensions in the local PBX. Let’s assume that Alice and Bob work on Cuenca, so they have their extensions 100 and 101 created there. Mallory works on Guayaquil, so he’s 200 in the local PBX and Charlie is 300 on Quito. So, go ahead and use FreePBX to create the SIP extensions on each PBX!Next step is to create IAX2 trunks. IAX exists to interconnect Asterisk PBXs. To our eyes, using IAX instead of SIP or whatever means we get full semantics on signalling among the PBXs, no headaches with caller IDs, channel usage et al. So, the process is a bit creepy on FreePBX, we need to go to Basic -> Trunks, Add IAX2 Trunk and define PEER and USER details. So basically we should interchange the information from PEER on one side to USER on the other side, fill the blanks so you get something like:

PEER details:

USER details:

USER details:

PEER details:


Set meaningful names for Trunk name and USER context, since those would be useful later. Right now you have local PBX services, and IAX trunks among the PBXs, but they’re not aware neither of the existence of more extensions on the other side, nor the dial rules to get there. Here we go with Outbound routes.You should create n-1 trunks and n-1 routes for any n-PBX Asterisk setup. Go ahead and create two outbound routes on each of your PBXs, using the prefix for each location, for example 1xx for Cuenca, 2xx for Guayaquil and 3xx for Quito. The ‘xx’ thingy has a special meaning on Asterisk’s dialplan, check FreePBX’s online help for details, but using ‘Nxx’ where N is the prefix for each location should do just fine. For each outbound route select the matching trunk.Great, you can now dial 2xx from Cuenca or Quito and you should get to Guayaquil via the IAX trunks. The only issue is that, when you have a respectable amount of extensions, you need to centralize your extensions directory. If you don’t use an LDAP directory, which you should do, you’ll run into problems when provisioning the personal directory to your users.So, finally, FreePBX has this thingy called “Custom Extensions” which you can create as a regular extension and after you do that you can assign a dial rule for that. So, instead of CUSTOM/XXX as the dial rule, use IAX2/foo-peer/XXX. Be advised that by setting this up this way, your whole work with outbound routes is useless, and you have to create the extension in all PBXes, but this is easily solved using LDAP.Alright, so that’s it. You now have multiple Asterisk PBXes, local service on each site, IAX2 trunks among them, calling routes active for all your extensions and some scenarios for ‘centralized’ extension management. Check my other posts under the Asterisk tag for more Asterisk awesomeness.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s