Multiple Asterisk Instances

I have a scenario where I’d like to provision several businesses on Asterisk. I would also like to be able to do things like provide per user number blocking. I’m aware of contexts in Asterisk, but it does not seem that contexts are adequate to do this.

Take this for example:


#include “restricted-user1.conf”
#include "dialplan-user1.conf"
include => local

#include "dialplan-user2.conf"
include => local

include => c_user1
include => c_user2

exten => _1900X,1,Answer
exten => _1900X,Playback(not-authorised)
exten => _1900X,Hangup

This is about the best I can come up with and it doesn’t work. I have blocked 1900 numbers for user1, and that works fine.
However, for all users to be able to call all other users, at some point I have to include them in some global area (ie local). When I do that user2 gets access to user1’s dial plan, and of course user2 suddenly gets his 1900 numbers blocked as well.

This is unless of course I am missing something with Asterisk and contexts.

I saw a few people asking about the possibility of running multiple instances of Asterisk on the same system. People generally thought they where crazy and asked why that would want to do such a thing. “Thats what contexts are for” they said.

I have tried it and it seems to work well. We’re only using Asterisk for processing SIP calls so I can’t see there being an issue of contention over hardware. The root directory of asterisk can be configured from the Makefile, and everthing installs nicely under that (except for music on hold which required a mod to the conf file). For my own testing, I put each instance under /home/asterisk-N and each instance was owned by a separate user. Each user had $HOME:/usr/sbin in their path so that they ran their own asterisk binary and when I execute ‘asterisk -r’ it knows what asterisk server to connect to for that user.

I seen articles about setting up v-servers for use with Asterisk. I don’t see why you need it. I think it would just add unecessary overhead.

A big question remains of how many instances of asterisk can be run on a given hardware platform. 10? 50? The asterisk process itself doesn’t seem to take much memory, and you can strip out some of the unecessary modules so that they don’t load. Aterisk Business Edition is supposedly able to handle either 120 or 250 simultaneous calls, keeping in mind that Asterisk acts as a B2BUA and is involved in all the calls from INVITE to BYE. Admittedly that’s on a single instance. I think it very possible that you would hit the 250 simultaneous user limit before you hit the limitation of running many asterisk instances.

One problem that arose would be what would you do if user-A wanted to reach user-B, but they where provisioned on different instances of Asterisk? They wouldn’t know about each other and would supposedly have to go out to the PSTN and back in again. I think a combination of ENUM would handle this very nicely. When asterisk can’t find the number in it’s own dial plan, it forwards the SIP packet to SER. SER does an ENUM lookup and determines the host, port and protocol where that user can be reached, and forwards the SIP packet again.

We have our phones registering directly with Asterisk as well. If there where multiple instances of Asterisk running on the same platform, they’d all need to be running on different port numbers. Couldn’t have them ALL on port 5060. That’s easy. You just configure each Asterisk instance with a different server port number, and then do NAPTR/SRV lookups on your phones. Each business/set of phones probably would have to have it’s own DNS sub-domain however (to get different port numbers). Something like and

So… any thoughts? It sure would be easier if Asterisk just allowed all this to be done through contexts!!

doug at

Running multiple instances of Asterisk on the server is not a good design and may cause issues, especially when it comes to scaling. The reason that this is not working is that local includes the other users context, so of course they we be able to dial on the other users dialplan.

What you need to ensure is that you have an internal numbering plan that makes sense. So, for example, choose an extension range for all internal users (ie - 3000 through 3999). Then have each of your SIP endpoints registered as a unique extension (ie - user1 = 3000, user2 = 3001). Then, your ‘local’ context should look something like this:

exten => 3XXX,1,Dial(SIP/${EXTEN})

Leaving the rest of your contexts as is. This will allow for local dialing without giving access to each users dialplan.

That’s not going to work.

Our extensions are provisioned as SIP users, NOT as extension numbers. That is the way we want it. Our dial commands look like:

exten => 3XXX,1,Dial(SIP/user1)

As far as I can tell, there isn’t a variable to map a SIP user name to an extension number. Is there?

Also, we aren’t assigning extensions to users. We are assigning full 10 digit PSTN numbers. We don’t want to assign extensions. There is no guarantee that all numbers will be contiguous.

Of course local includes both users contexts. It has to! How else will be users be able to reach each others extensions???

[quote=“dgarstang”]That’s not going to work.

Our extensions are provisioned as SIP users, NOT as extension numbers. That is the way we want it.[/quote]

Then you are going to make what you need to do a bit more problematic in terms of internal dialing, but not impossible. Asterisk itself will not provide the mapping necessary, but you may do this yourself by creating a MySQL (or Postgres or whatever) table that contains the following fields:

  • Internal dialable extension
  • 10 Digit number (could be the same as the internal dialable extension if you want everyone dialing 10 digit numbers for internal calls)

Then, you may do something like this:

exten => 3XXX,1,MySQL(Query resultid ${connid} query-string) [of course substituing for your environment]
exten => 3XXX,2,MYSQL(Fetch fetchid ${resultid} var1 var2 … varN)
exten => 3XXX,3,Dial(SIP/${var2})

exten => (some extension logic for user a)
include => internal_dial

exten => (some extension logic for user b)
include => internal_dial[/code]

Extension could be anything you want it to be in terms of dialing strings (4 digits, 10 digits, whatever) if your numbers are not contiguous, no big deal as you may handle the error for an invalid number and playback a message that it is an invalid extension. The point is, if you want internal dialing from a standard handset, then you need to assign numbers to the people. If everyone is using a softphone and may dial SIP URIs, then you may setup the Asterisk for SIP URI dialing.