Passing prefix to the trunk



I’m trying to setup an outbound routing that will allow me to dial a prefix (ie: 9) before a number to dial a long distance on the PSTN.

The thing is that I would like Asterisk to dial a prefix on the trunk before placing the call (to benefit of lower long distance rates).

For example:

  1. I dial 9-514-123-4567 on my softphone
  2. Asterisk selects my PSTN trunk but dials the number as follow: 555-1234-514-123-4567 (555-1234 is a special number I must dial before long distance numbers to save money, no pause is necessary between the 2 phone numbers).

I only have 1 SPA-3000 and 1 PSTN. I know it’s easy to achieve what I described above in the Trunk settings, but I also want to be able to dial local numbers through the PSTN, which don’t need the 555-1234 number to be added before the local number.

Anyone know how to acheive this?

Thanks a lot!


If you could qualify the calls (by area/country code) that would or would not use the 555-1234 number, you could use context to add or not add the extra digits.

I’d figure out which is the smaller or easier group of digits to classify. (Probably the local numbers.) Put those digits into their own context like this:

exten => _NXXXXXX,1,Macro(diallocal)

exten => _NXXNXXXXXX,1,Macro(diallocal)

exten => _1NXXNXXXXXX,1,Macro(diallong)

exten => _1888NXXXXXX,1,Macro(diallocal)
exten => _1877NXXXXXX,1,Macro(diallocal)
exten => _1866NXXXXXX,1,Macro(diallocal)
exten => _1855NXXXXXX,1,Macro(diallocal)
exten => _1800NXXXXXX,1,Macro(diallocal)

exten => _011.,1,Macro(diallong)

exten => _1900NXXXXXX,1,Congestion
exten => _1NXX976XXXX,1,Congestion

Then you’d create macros that would dial the calls for you either putting in the digits, or leaving them out:

exten => s,1,Dial(ZAP/1/${MACRO_EXTEN})
exten => s,2,Congestion
exten => s,102,Busy

exten => s,1,Dial(ZAP/1/5551234${MACRO_EXTEN})
exten => s,2,Congestion
exten => s,102,Busy

Use a series of include statements in your default context. Each context is checked until a match to the digits that you dialed is made. The order that the include statements are listed is the order in which they checked. After a match is made to digits dialed, your call moves to that context and runs the listed macro.

The order that you list the include statements is EXTREMELY important.

For example, this is wrong:


include => local7
include => local10
include => longdistance
include => tollfree
include => international
include => blockedcalls

The blockedcalls numbers that are 10 or 11 digits long would match the dialing scheme of the local10 or longdistance contexts FIRST (before the blockedcalls context), and the calls would proceed.

This is correct.


include => blockedcalls
include => local7
include => local10
include => longdistance
include => tollfree
include => international

The blocked calls are matched immediately, and their treatment is followed. (In this case, they are given the congestion treatment.)

You should check each list of numbers from the smallest, most inclusive group of numbers dialed up to the largest. This will make sure that the calls are blocked or placed using the most cost effective manner.


That sounds wonderful… However, I’m still a newbie using Asterisk@Home and I’m not quite sure in what config file to add this information.

I’m learning fast, don’t worry! :laughing:


This is stuff you’d put into the extensions.conf file.

It’s all part of putting together the dialplan which is, apparently, THE STEP that is most often skipped. Without a good clear idea about how you want your dialplan to operate, it’s a silly idea to dive right in. You’d probably end up doing a ton of configuration only to have to strip it all out and do it again…

There’s a ton missing from this dialplan snippet too. Consider:

How would Asterisk deal with a three digit number like 411 or 911?

How would Asterisk deal with the fact that the carrier at 555-1234 is busy?

For a really good primer about how dialplans are put togther, read this over. … sions.conf


Thanks! That really helps!

I changed my Asterisk configs so many times that my system started to act weird. Since I’m not in production mode yet, I decided to format and start over again (with more knowledge of the system).

I will try to implement your ideas.