Set caller id based on number being dialed

I would like to set a different caller id whenever dialing a specific number. The option to set caller id in Trunk seems to be overridden by the caller id in extension.

I also had one number that I wanted to call with a different Caller ID - it was a service that is “keyed” to the user’s phone number. Here’s how I did it:

Don’t Apply Configuration Changes (click the orange bar) until you complete all the steps below. Replace “custom-some-name” with something a bit more meaningful.

Add a Custom Destination (you have to do this from the Tools tab, like when you are upgrading modules).
In the Custom Destination text box, put custom-some-name,${EXTEN},1 (don’t use the drop-down).
Put whatever you like in the description.
Submit the changes.

Create a Misc. Application
Give it whatever description you like
Give it a Feature Code that is a shortcut you will dial to reach the number. This is what you will actually dial when you want to call the number (think of it as a speed dial).
Make the destination the Custom Application (a.k.a. Custom Destination) you created in the previous step.
Make sure the drop-down says enabled, and submit the changes.

Edit /etc/asterisk/extensions_custom.conf (use nano or Midnight Commander’s editor or whatever you prefer) and add this:

exten => _.,1,Noop(Calling zzzzzzzzzz with Caller ID yyyyyyyyyy)
exten => _.,n,Set(CALLERID(number)=yyyyyyyyyy)
exten => _.,n,Set(CALLERID(name)=myname)     ;Optional, probably ineffective if call goes over PSTN
exten => _.,n,Goto(from-internal,zzzzzzzzzz,1)
exten => h,1,Macro(hangupcall,)

Replace yyyyyyyyyy and zzzzzzzzzz (and myname if you include that line - don’t include the comment) with appropriate values and save the modified file, making sure not to change permissions or ownership.

Now you can Apply Configuration Changes.

Should work for specifying Caller ID on calls to a particular number. Let us know if it works for you.

Now, if you need to intercept people dialing the actual number, then it gets a bit harder. But if it’s only you calling and you can remember to dial the shortcut code, you should be all set.