Adding 0 to incoming external calls

Hi everybody,

I know this problem has been discussed several times in this forum, but all the answers I found just didn’t help… usually because they were written for other (older) versions of freePBX.

The version I use is FreePBX / Asterisk 16.13.0

I know, that to add a “0” to the incoming calls I have to add:

exten => _X.,1,GotoIf($[ "${CALLERID(number)}" = "anonymous" ]?nochange)
exten => _X.,n,Set(CALLERID(all)=0${CALLERID(num)})
exten => _X.,n(nochange),Goto(from-trunk,${EXTEN},1)

to extensions_custom.conf

and then I have to add


to where?

The solution I found pointed to Connectivity/Trunks/my sip Trunk/sip Settings/Peer Details
but I can’t find this setting.
Mine looks like:
Connectivity / Trunks / my sip Trunk / pjsip settings

It would really help me if someone could just point me to where I have to add this line to make it work.

Thanks in advance,

In the pjsip Settings for your trunk, General tab, there is a Context field that defaults to from-pstn. Change that to prepend-zero and your custom dialplan will be executed for all incoming calls on that trunk.

However, this seems very unusual and will likely cause various problems. For example, if you forward a call to a mobile, the caller ID that you send on the outbound trunk will likely be in a format that the trunking provider does not accept.

What country is the system in?

Is the PBX configured to require an initial 0 before dialing an external number? If so, why?

The system is located in germany, and yes the PBX is configured to add an initial 0 to external numbers.
For the question why… this is a good question, but I couldn’t tell you the answer. I haven’t set up the system. I am just here to make sure it works. Possible that is has something to do with the provider or with how the phone system we had before worked.

The system is working with 31 extensions numbered from 20 to 46 + some higher ones.

To call an extension you just key in the number. For an external call you have to add 0 to the number you want to call. so, if I want, for example call the number 030 123 456 78 I would have to call 0 030 123 456 78. Most of the numbers we use are saved in the phonebook. The problem is now, when someone with a number which is in the phonebook calls, the name is not shown because the leading 0 which is in the phonebook entry is not transmitted as the incoming number.

So, I need a method to add the incoming 0 to all external numbers to make sure the phonebook is triggered and shows the name of the caller, not just the number.

If it’s only for phonebook matching, CID Superfecta has the ability to modify the incoming CID just for the lookup. You won’t need any custom code. See

This has the advantages of leaving the displayed number unchanged (easier for the end user to recognize) and not breaking follow me / forwarding, but has the disadvantage of not allowing the user to return a call from his device’s history.

IMO, it would be much cleaner to have a system that does not use an initial 0 for external calls, but if you switch over, you’ll have some misdials for a while because users will have the habit of dialing the 0. In many countries you could make the 0 optional, but numbers in Germany have variable length, so it won’t work here. For example, 0039062223333 could be a number in Bebertal with an initial 0, or a number in Rome without the 0.

However, if most of your calls are local, you likely could allow an optional 0 for those. For example in Berlin, 030 123 456 78 could alternatively be dialed 0 030 123 456 78 without confusion, because a number in Greece would have 10 digits after the country code.

Thanks for your help.

The possibility to return a call from the history was the second reason my coworkers wanted the additional 0 in front of the CID, so they got it. It works fine now, if problems appear I’ll have to find a way to fix them but for now it works. As we usually just forward calls to the internal extensions and don’t use follow me I don’t think this will be a problem.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.