How to force an extensiont use a specific outbound trunk

Anyone know in 2.4.1 how I can make an extension use a specific trunk for outbound calls?

see the third party customcontext module

Thanks, I’ll check that out. In the meantime there is another way.

  1. Set the outbound route Dial Patterns to something like:

  2. Set the Dial Plan (in the voip phone or voip phone adapter) to add the prefix (999 in this example) by adding <:999> in front of each of the dial pattern sections like:

When you dial on that line it will alway add the 999 prefix and when asterisk sees the 999 prefix the appropriate route will be used and it will strip off the 999

Works great

You could also add a custom context to extensions_custom.conf that looks like this:


exten => _1NXXNXXXXXX,1,goto(from-internal,999${EXTEN},1)
exten => _NXXNXXXXXX,1,goto(from-internal,999${EXTEN},1)
exten => _NXXXXXX,1,goto(from-internal,999${EXTEN},1)
include => from-internal

Then from FreePBX, put the phone in the “from-fred” context and make an outbound route that strips the 999 and send the rest to the Telco.

I heard the the custom conf was broken in 2.4 and up?

I followed the advice above to prefix all calls with 999 and then put 999| in front of all of my current dial rules for a new outbound route. It works great, and all of the calls get routed via the correct trunk.

The only problem is that now I can’t call from that device to another extension. It looks like it’s sending calls to the extension out via the outbound trunk instead of routing it internally.

Here are my current dial rules in the outbound route:


(In case you’re wondering, the dial rules for the outbound trunk adds the area code for the last entry)

Any ideas for the best way to strip the 999 and have the internal call not match that outbound trunk?

Also, I can’t input any codes like 97 for voicemail, presumably because what actually gets passed to Asterisk is 99997.

fyi: in your outbound route you can reduce it to be just the last 3 rules.

The problem is you followed the directions above and configured the phones dial plan to prefix 999 to everything you dial . Which while a nice trick as you’ve found out is a bad move because the phone wil prefix EVERYTHING dialed with 999 that means local extensions, featurecodes, etc. The only thing that should have been prefixed was the dial patterns that will go out a trunk.

Yeah. The top lines are a remnant of a previous configuration. I was just too lazy to delete them.

I actually didn’t set the 999 prefix in the dial plan. I did it in the GUI for the Grandstream ATA. Do you have any suggestions for how to set it in the Asterisk or FreePBX config? Should I just try the custom context module? I heard that it was broken in the current stable version (2.4).

What I am trying to accomplish is that business calls go out on one carrier SIP account, and home calls go out a different account. I imagine I can take the time to study how the Asterisk dial plan works, but that might take me weeks. If you have any suggestions, I would be very thankful.

I assume that this is a similar solution for having multiple businesses use the same phone system but different SIP trunk providers. You can have multiple contexts that would keep everything separate, right? But it looks like FreePBX is only set up to use the “default” context. I don’t know enough to know what I am talking about, apparently, so thanks for your patience. :slight_smile:


I Highly recommend the customcontext module instead. the 999 prefix in the dial plan is what you did do in the GUI for the ATA as it has it’s own dial plan. I’d remove all that as it will come back to haunt you later in life (or a few hours from now).

My suggestion above was to add that code to extensions_custom.conf. Then go to FreePBX and in the extension’s setup, change the context to “from-fred”. Then create a separate outbound route with the 999| in the dial plan. The phones should not be touched.

Custom Contexts will work also.

Just found this thread… and this worked really well! Thanks!