Sip Trunk passing CID and getting calls from PSTN

Hello everyone,

Right now I have a SIP Trunk which is shown “online” on the Dashboard.
The Trunk and all Extensions use pjsip.
The Outbound Route is working like expected and it’s possible to call PSTN Numbers from the registered Extensions in FreePBX.

The problem hat every call passing the Trunk gets the same number but I want the extension number to be passed to the trunk so that it’s possible to call back the extension which placed the call.

I tried to register the Extensions with internal Numbers (300 e.g.). And tried to assign a DID from the range which I received from my Trunk provider. (Add Inbound DID). But I can’t call it regardless of the inbound Routes set.

My goal is the following:

Lets assume my Trunk provider gave me a range from 00000300 to 00000900.
I want every extension to get 300, 301, 302 … and it needs to be callable from the internal network. (Which is working)

When someone calls a PSTN number, i want FreePBX to pass the whole number, depending on the extension, to the called phone. So that the called phone can see “Missed call from 00000303” and if it recalls, the extension 303 rings.

Someone else asked for something like this a couple of weeks ago. I don’t recall the exact solution, but it involved writing some custom code and including a custom context that set the extension outbound caller ID.

The advantage of doing it this way is that you now manage your entire enterprise from a single bit of code. If you are really tricky, you could also set it up so that certain extensions get the “base” enterprise phone number and others get their “personalized” extension/DID.

The more I think about this, the more is actually seems like a pretty good idea. The difference between just setting the Caller ID in the extension to the “direct dial” number and using the local extension when calling internally is the new wrinkle.

If you aren’t comfortable with doing this work yourself, you can always include a feature request using the “Issues” link at the top of the page.

I guess you need to check with your Telco if they allows to change the outgoing CallerID.

Of course. It wouldn’t make a lot of sense to request a feature that one couldn’t use. There are plenty of places that either limit or allow foreign Caller ID facilities, but since the CID (in this case) would be one of the ones assigned to his DIDs, one would hope that it would be allowed.

Have you looked at this: Customize outgoing caller name and caller ID - PBX GUI - Documentation ?


I’ve searched but i couldn’t find it.

Can someone tell me the magic lines ? :slight_smile:

Regarding my other problem: if my CID isn’t passed, my Trunk Provider doesn’t support it right ?


Because people sometimes mis-type this:

  • DID (your number) is passed to you by your provider on most VOIP and ISDN trunks. There is no facility for passing DID to you on POTS lines. You need to manage the DID on these lines.

  • CID (the person calling you) is passed to you by your provider. There are several ways to do this in VOIP and FreePBX handles most of them. On POTS, the information is usually passed between the first and second “ring”. This is one of the reasons why many POTS systems’ phones do not ring on the first ring. The caller sends a ring, then their caller ID information, and thus generate a 5-ish second delay.

  • CID (your Caller ID) must be formatted correctly when sent to your provider. If it is not, or if your provider does not allow you to set your Caller ID, they CID they use will be the one they set up for your account. Most POTS providers (local Telco hard lines) do not allow Caller ID to be set anywhere but the Central Office. Some VOIP providers do not limit your outbound Caller ID at all (you can send anything you want). Others will allow you to set the Caller ID fields (name and number), but the number must match one of the numbers assigned to your account.

So, if your caller ID isn’t passed, it could be that your are not sending a valid caller ID and they are overriding the one you sent, or that they are just setting the CID based on their corporate policy. Call them and ask them which is the case and adjust from there.

1 Like

You cannot send the extension number only a valid number that you own. In each extensions use the outbound did option to set the number that you want to show to your clients for each extension.

No - that’s not correct.

If your VOIP provider allows foreign Caller ID values, you can send anything you want. I regularly misconfigure my testing server to send one of my outbound providers the actual three digit extension number instead of the office’s phone number. It’s always a mistake (I don’t want my extension numbers out on the Internet), but somehow I manage to do it about every third reinstall.

As I said above - the values for Caller ID are a matter of what your provider is willing to allow you to do. Some are very strict. Other’s couldn’t care less. You need to talk to your provider and find out what their policy is.

Ok, I contaced my SIP Provider:

The CID needs to be declared as additional Header
P-Preferred-Identity, Format (E.164).

Edit extensions.conf as follows:

exten => _X.,1,Set(CALLERID(number)=SIPID)
exten => _X.,n,SipAddHeader(P-Preferred-Identity: sip:[email protected])
exten => _X.,n,Dial(SIP/${EXTEN}@sipgate-out,30,trg)
exten => _X.,n,Hangup

But this is just for Asterisk. I don’t want to edit the config Files, I can’t image that there isn’t an option at the FreePBX webinterface. Is this possible to tweak from the interface ?

You can accomplish this by creating a new context in extensions_custom.conf. Set your outbound route context to “sipout” and you should be fine.

I recommend you look through your extensions*.conf files and see if there isn’t already a reference to this. If there is, you can use the existing context as your outbound context and you’re all set. If the SipAddHeader() line isn’t there and you want to contribute to the project, I suggest adding a Feature Request through the “Issues” link at the top of the page.

Configure in each extension the outbound cid field, enable the trustrpid and sendrpid also in each extension but in the sip trunk’s options and I think you are good to go.

Ok, I tried it like mentioned from cynjut and astbox, but neither of this ways is working for me.

I don’t want to pass just one CID to the Trunk, I want to pass every unique extension CID to the Trunk, so when I call to PSTN, I want them to be able to call back the Extension.

But this "[sipout]
exten => _X.,1,Set(CALLERID(number)=SIPID)
exten => _X.,n,SipAddHeader(P-Preferred-Identity: sip:[email protected])
exten => _X.,n,Dial(SIP/${EXTEN}@sipgate-out,30,trg)
exten => _X.,n,Hangup"
is reading like it sets all CID to XXXXXXX when using the Trunk.