How to force a route on a per extension basis
Wednesday, March 25, 2009 at 2:23PM There are a variety of reasons why someone would want to restrict extensions to use certain trunks, and with freePBX it’s easy to do. The method I’m going to show is not the only way, but I think it’s the easiest to understand.
The logic behind this method is two parts. First is to have calls from the extension you want to route go to a custom context in extensions_custom.conf, where it will add a leading key digit or digits. Then a custom outbound route is created and designed to catch calls with those key digit(s)with the trunk you want to use at the top of the sequence. The call flow works like this- the user dials an outside number where the custom context then adds a leading key digit to what they dialed. It’s then caught by the custom outbound route, where the key digit(s) are stripped off and sent to the trunk you want to use. Got it? Lets begin.
In this example, I’ve decided to make the key digit the number ‘9’ to all seven, ten or eleven digit calls (the normal North American calling dialplan). The user will not have to dial the leading nine, and anything not matching the North American dialplan (internal extensions, 411, 911, etc) will not be affected.
Step 1: Create a custom context within extensions_custom.conf:
[pstn-trunk]
exten => _1NXXNXXXXXX,1,goto(from-internal,9${EXTEN},1)
exten => _NXXNXXXXXX,1,goto(from-internal,9${EXTEN},1)
exten => _NXXXXXX,1,goto(from-internal,9${EXTEN},1)
include => from-internal
You can name this context anything you like, but it helps to make it meaningful. In this case, I named it [pstn-trunk] because I want to force the extension to use the PSTN trunk. As you can probably deduce from the code above, all 1+10 digit, ten, and seven digit numbers will get ‘9’ added to the string and sent to the from-internal context. All other numbers dialed will be sent to from-internal unmodified.
Step 2: create outbound route to catch calls pre-pended with '9' with a meaningful name and with these strings in the dial patterns:
9|1NXXNXXXXXX
9|NXXNXXXXXX
9|NXXXXXX
This will catch calls from that extension and strip off the leading '9'. Make sure the trunk you wish to use is placed on the top of the trunk sequence, and put the outbound route ahead of any general outbound routes.
Step 3: Finally in the device options of the extension(s) you want to modify, enter the custom context name into the context field, the above example would be pstn-trunk.

Reader Comments (1)
*NOTE: The comments below are refugees from my previous iWeb hosted account.
Mark Reisenhauer:
EXCELLENT, EXCELLENT!!! This was just what I was looking for, thank you!
Thursday, March 26, 2009 - 09:58 PM
Kristy He:
This is a very big help for us, Thank you! My company would like to use different callerID information available depending where we call. We call one area and callerID is x, when we call a different area we have callerID display y. Do you know if this is possible? Thanks again! Regards, Kristy He
Monday, April 13, 2009 - 09:49 AM
Jeff Howe:
Kristy, If I understand correctly what you are trying to accomplish, this can easily be done using outbound routes and a bit of code. The requirement is your installation uses freePBX AND you don't use passwords for your outbound routes.
_____________________________________
Summary: Create and configure outbound routes with CID info and dialplans and add code to extensions_override_freepbx.conf.
Step One: Within the freePBX gui, create an outbound route for each CID, adding the custom CID information into the 'Route Password' box and check the 'Intra Company Route' box. Modify dialplan entries to send pattern matched calls through the route.
Step Two: Add the code below to the extensions_override_freepbx.conf file (located in /etc/asterisk/ in CentOS installs)
[sub-pincheck]
exten => s,1,Set(CALLERID(all)=${ARG3})
exten => s,n,Return()
; end of [sub-pincheck]
That's it! Crafting dialplans will likely be the most challenging part of this easy customization, so make sure you test each CID modified route. - Jeff
Monday, April 13, 2009 - 04:56 PM
Kristy He:
This is what we needed. I follow your clear instructions with a test route and it appears to work perfectly! Very easy and quick, thank you for your help!
Tuesday, April 14, 2009 - 09:21 AM
Jason P.:
So glad I stumbled onto your site. I've been attempting to do this for weeks in a commercial environment without success. This solution is perfect. Thank you!
Wednesday, April 15, 2009 - 07:14 AM
Bill F.:
We're splitting one PBX between two entities, each with their own trunk. This does the job. Thanks.
Friday, April 17, 2009 - 03:23 PM
wiseoldowl:
One thing to keep in mind is that your method as shown will still allow users to call forward using trunks they would not otherwise be allowed to use. If that's not desirable you may want to see this document on the FreePBX site (which also gives some additional methods for doing this sort of thing):
http://www.freepbx.org/support/documentation/howtos/how-to-give-a-particular-extension-different-or-restricted-trunk-access
Friday, May 1, 2009 - 03:26 AM
Jeff Howe:
Thanks for pointing this out, I missed that thread on the freepbx forum and will check it out. - Jeff
Friday, May 1, 2009 - 01:58 PM