Alternative to custom contexts using dial patterns?

Ok, so I have three extensions (2001, 2002, and 2003) and they are for taking incoming calls during our TV show 3 nights a week. All our office extensions fall somewhere in the range of 1001 to 1999. I do not want the extensions in the 2000 range to be able to call the extensions in the 1000 range and vice-versa.

I believe this can be done using custom contexts, but I was wondering if there were any other alternatives. I then had a big brainstorm and thought I figured it out … I said to myself “I already have an outbound route called BARRED that blocks a bunch of blacklisted numbers, so I will block the extensions that route with a dial pattern!”

So, for example, to block extension 2001 to 2003 from calling extensions in the 1000 range, I entered 1XXX/_200[123] in the dial patterns section of my outbound BARRED route. Talking to myself again, I said “Boy, am I smart!”. I then tested my brilliant idea, only to find out I was not as smart as I thought I was … it did not work!

Now correct me if I am wrong, but I am thinking it did not work because internal-to-internal calls don’t use outbound routes (seems pretty obvious to me now)! They probably get checked to see if they are internal and get routed internally long before they ever reach any kind of outbound route.

So now comes my thought on an alternative to custom contexts…

Is there anyway to check all internally routed calls against a dial pattern, and if the dial pattern matches send it to a recording (like “wrong-try-again-smarty”) and then hangup. If there is no match to dial pattern, then the call would just carry on as normal.

The reason I am asking, is that I like dial patterns, and I find them VERY easy to use and setup … being able to check an internally dialed call against a dial pattern is a whole lot easier (for me anyways) than trying to setup custom contexts.

If anybody has any thoughts on this I would like to hear them.



when you define an outbound route to block inter-extensions, you probably have to ensure the callerid is set correctly (2XXX or 1XXX in your case) so that it could hit the pattern 1XXX/_200[123].

btw, to route calls back to your dial plan, you can also use local channel as well eg dial (local/1000@context)


I don’t think that is the issue because I have several outbound routes and several trunks, and I can successfully route the calls (or block them) wherever I want based on the extension.

For example, NXXNXXXXXX/_200[123] on my BARRED outbound route will block extensions 2001, 2002 and 2003 from calling 10-digit numbers in the US. So I think the issue is that internal extension-to-extension calls never make it to the outbound routes (since they are not outbound) and therefore you cannot allow/deny internal calls thru outbound routes!

I have a client that i did something similar for.

It may take me a bit to grab it but I’ll log in and give you an example as soon as I get a chance. Probably not till the end of the day.

for me it got kind of complicated. literally had to make up a visio chart to keep it all straight in my head lol.

Are you using a GUI of any type or straight conf. files.

I use FreePBX, but I have no problem editing .conf files directly if I need too.



We run a system with a number of tennants / deprtments, but we use contexts extensively to partition off the groups of phones.

What we do is create a context with one or more pattern matches. Each context represents one call group or call type that we want to allow.

eg. to make it simple

; Calls to 1000-1999
exten => _1XXX,1,Dial(SIP/${EXTEN})

; Calls to 2000-2999
exten => _2XXX,1,Dial(SIP/${EXTEN})

; Emergency Calls
exten => 911,1,Dial(SIP/reliable-sip-trunk/911)
; backup if SIP is down
exten => 911,n,Dial(DAHDI/g1/911)

We then include each dail pattern context we want the group to have access to in their own context.

; 1000-1999
include => exten-1xxx
include => exten-e911

; 2000-2999
include => exten-2xxx
include => exten-e911

; Operator / Front desk
include => exten-1xxx
include => exten-2xxx
include => exten-e911

Then to add or remove the ability to dial a specific group or service you just include the context with the dial pattern for that service. I fint that this seems to be the best way of managing multiple tenants with a text editor.

If you are dealing with a large number of groups / departments, you can use a #include => group-dialplan-filename.conf to keep each groups total dial plan manageable and readable.

This has allowed us to run dozens of tenants / departments and keep them segragated and manageable with a text editor

Thats my thoughs anyway.


@chazelton… Looking forward to seeing your solution for this.

@MrFridget… I am just now reading up on the asterisk language, but this will definitely help get things going in the direction I want! Thanks