HOWTO: creating inbound routes when trunk provider doesn't give DID

Hi all,

I’m new to FreePBX, and was trying to set up inbound routes so each trunk would go to a different destination based on the DID dialed. However, my SIP provider doesn’t set the DID in the ‘To’ header. The DID was showing in the logs as ‘s’, not very useful.

So after some searching, and experimentation, I’ve figured out a reasonably straightforward way to do this. Unfortunately, this requires editing one of Asterisk’s configuration files, since I haven’t yet worked out how to do it in the FreePBX GUI (or if it can be done in FreePBX’s GUI).

DISCLAIMER - this method only works if you have only one DID per trunk with your SIP provider, and have not configured any of your trunks to transfer to other trunks. Fortunately, my own SIP provider allows me to have a separate SIP registration for each of my inbound DIDs.

Step 1 - create custom Asterisk rules to assign the DID

Edit the file /etc/asterisk/extensions_custom.conf (which is typically blank with default FreePBX) and add one of these entries for each trunk:

[from-trunk-5555555]
exten => _.,1,Goto(from-trunk,5555555,1)

For each instance of this entry, replace the ‘5555555’ with the trunk’s actual DID

Step 2 - Assign the context for each trunk

With each trunk’s configuration, click on the ‘pjsip Settings’ tab, then replace what’s in the ‘Context’ field with ‘from-trunk-5555555’ (changing the ‘5555555’ to the actual DID for that trunk).

Save the configuration but don’t reload yet.

Step 3 - Set up the inbound route for each trunk

For each trunk, set up an inbound route and set the DID number to the DID number of that trunk, and set the destination accordingly (an extension, or IVR, or queue, or whatever you wish).

Now click the red ‘Reload’ button at the top.

Step 4 - Test

If you’ve done everything right, you can make an inbound call to each of your SIP provider’s DIDs, and see that these are taking the right path that you chose in the inbound routes.

Unfortunately, this method breaks down if you have more than a single DID from each provider. Have you looked at the signalling of an inbound INVITE to see if the DID is in one of the SIP headers?

Thanks Lorne for the qualifier. Much appreciated. I’ve updated my OP with a disclaimer to reflect this caveat.

If the provider is sending it to ‘s’, it means they’re honouring what you send as your registration, and probably is because you’re using chan_sip.

You can tell the provider to send it to 555555 with the registration string:

user:[email protected]/555555

I’m using pjsip, and am getting ‘s’ as the DID.

Ah, in that case set the ‘Contact User’ to be whatever you want calls to arrive as.

Thanks for that. The popup help for “Contact User” probably needs to be expanded to explain this. I went searching for ways to get the trunk to carry in the DID, and saw that among the advanced options, but all it said was “Contact User to use in request”.

Maybe it could read: "Contact User to use in request. If required, set this to whatever DID value you wish to match for this trunk in your Inbound Routes."

Because that can be incorrect. Nothing states the contact user has to be a DID.

Thanks for the correction, Tom. Point taken.

I was unable to figure this out from my reading of the documentation and the help strings in the UI, so I would suggest that the help string for “Contact User” could benefit from something a bit more explicit so that other users don’t have to ask around and figure out awkward workarounds like I did.