Dial extensions when phones use a prefix

Hello everyone,

I have FreePBX 5.211.65-12 and Grandstream GXP-2020 phones and everything is working well except for extension dialing.

I have multiple “lines” as we are a sort of umbrella business and each “line” is attached to a DID on our SIP Trunk. In order to make this work correctly for our HR staff I use a prefix on the outbound route and the phones.

The only issue with this is that when I attempt to dial an extension or feature code the prefix is added in turn making it an invalid destination.

The first solution I came up with was to have a dedicated “Office” account on the phones that do not use a prefix, this wastes one account which we need to use for a DID. The next idea was to just have Account 1 not use a prefix and set that outbound route to not use a prefix either. The second will work just fine I think but I am worried that any local(LAN) calls will tie up that particular DID.

Is there any way to use prefixes on all accounts/routes and still have extensions be available?



I must really be missing something…how is the outbound route even coming into play when dialing an extension.

I guess I’m not really clear as to what you are doing. You speak of “lines” and “sip trunks” somewhat interchangebly. “Lines” really has no relevance to sip trunking. I also think you’re confusing “DID” with a “line”. You can’t tie up a “DID” you can only tie up an extension. From a SIP pont of view, if I call you on 5015551212 and another call comes into 5015551212, the second call hits the server and it is processed, It’s up to you to determine how it’s processed.

Likewise, an outbound call doesn’t tie up a DID.


I am still learning the right terms for telephony, thanks for the clarification on DID/Line.

On my phone I have 6 Accounts(LED Buttons that correspond to an outbound route in my setup) Under each account I have a prefix set to specify which outbound route the PBX will put the call on.

Phone 1, Account 1, Prefix 1
Phone 1, Account 2, Prefix 2

then on the Outbound routes I have a prefix set to match what the phones prefix to all dialed numbers.

So if I hit “Account 1” on my phone and dial 123-456-7890, the phone send 1123-456-7890 to the PBX. The PBX then removes the leading “1” because it matches a dial pattern on that particular outbound route and sends it to the trunk.

I have this set up for each outbound route as shown here: http://prntscr.com/3nfrw9

The issue comes into play when I am attempting to dial and extension, the phone places the prefix so when dialing ext 300 the phone sends 1300 to the PBX which is not a valid destination.

The issue is either in the phone or in the PBX’ interpretation of the pattern.

I think at this point just removing the prefix from the first account on the phone and on the corresponding outbound route is going to get it resolved.

I was just hoping that I could keep my configs somewhat standardized and either use a prefix on all or a prefix on none.

I guess I’m still missing something. If you’re using SIP trunks, they all go out the same way, so how do you differentiate? When you send out something out a SIP trunk, it goes out the SIP trunk. I’d love to see your trunk configuration.

By the way, what kind of phones are you using?


Well you could add an alias to the extension but that is an even bigger convoluted mess.

You don’t need the prefix. Just put the extension of each line button in the CID field in the outbound route.

Thanks SkykingOH, I will try that.

w5waf: I have my trunks and routes configured as basic as I can, the way that I am differentiating is by using a prefix configured on each phone.

The issue I am facing is based on the prefixes configured on the phones and out routes. I am going to remove the prefixes and just have a single extension per DID and use the CID field like SkykingOH suggested. After looking into it a little bit more with rested eyes and everyone here’s help I see that I was using the wrong tool for the job.

I was thinking there might be a way to have FreePBX/Asterisk strip the prefix if it matched NXXX but that didn’t work.

After trying the CID field I realized that in order for that to work for me I still have only one “Line” button(These are SIP Account selection buttons) that can be used to dial an extension. I found a post here on the forums that clarified my question a bit more.

"…, then you need some way to distinguish between calls that stay on your system and calls that do not."

What I would like to do is have the PBX remove the prefix and dial an extension if it matches an existing extension.

Ideally the users should be able to select any “line” dial external numbers and internal extensions. http://prntscr.com/3nosnk

I need a way for the PBX to recognize that an extension was dialed and treat it like an extension instead of sending it to the trunk. I hope this helps clarify the issue.

I gave you two solutions, you could add alias to each extension. But that is not a thrilling prospect.

There is a third solution, you could write a custom extension and put the phone in it’s context. The context would check the digits after the first digit and if internal strip the digit then send it back to FreePBX dial plan.

Lastly the CID in route will indeed work. You just need a route per line key.

The CID in route seems like it should work, I must be doing something wrong though since with that enabled all calls end up matching the first outbound route(although all feature codes and ext dialing works ).

I may not be looking at this the right way, I need all line keys to be almost identical except that key 1 uses route 1, key 2 uses route 2 and so on. I tried setting multiple phones with the same extension which seemed fine except any internal calls from the duplicated ext obviously did not show up as the user.

It seems like I can get one or the other but have yet to get both features to work. I would prefer that each line key on a given phone use the same extension for internal calls and that each route be able to dial any number. Essentially each route is a separate company but we all work in the same office building and need to be able to dial to a desk.

I am certain that this is a failure on my part entirely, I really appreciate everyone’s help and patience on this issue. I am sure by now it is apparent that phone systems are not my strong point but I am doing my best to learn.

in the outbound route enter your match pattern (i.e. NxxNxxxxxx)- and then note that after each pattern there is something caller “caller id” - enter the extension number in that field. if you use different trunks for outbound calls for different extensions, then you would need different outbound routes, all could use the same match pattern but the caller id field would be different. now if you put the outbound caller id you want to pass into the extension definition you should be able to accomplish your goals.

Thanks for the response, I have set the CID field however I need each extension to be able to dial out on all routes and dial extensions. I can’t seem to get that to work the way it needs to.

I have been able to get everything up to this point working and this is all that keeps me from porting our original numbers out to BroadVoice and being done with this project. I think I am to the point that I can’t see the forest for all the trees in the way.

You would be able to use every trunk at every phone.

First, let me ask you a question, is all of this because of caller ID? You want to control what caller ID goes out?

Anyway, to go back to what you want, let’s say you have four trunks for example so on each phone you assign for line appearance keys 1101,2101,3101 and 4101 at extension 101 then at 102 1102,2102,3102 and 4102 and so on for each extension.

Then you make 4 routes for each trunk. In the caller ID fiend you would put the 1102, 2102, 3102 and 4102 on each outbound route. The route match patterns will be the same but the CID will be different. IE NXXXXXX/1102 for extension 102 to dial 7 digits, NXXNXXXXXX/1102 to dial 10 etc.

Then you would create a ring group with “first available” as the ring strategy for each extension, IE 101 would be the ring group number and 1101,2101,3101 and 4101 would all be members of that ring group.

That will do what you want.

Thank you so much. That was the key, after I set it up it made perfect sense. Now I am on to the next problem now. Can you PM on here? If so shoot me a PP email and I would like to tip you sir.