SIP to PJSIP Trunk

We have a customer that we use FreePBX purely for SIP trunking to their phone system. We migrated their server to a newer version of FreePBX and in so doing converted their trunk to PJSIP. I have inbound calls working but I cannot get outbound calls from their system to successfully send through our FreePBX. The system is recognizing it as an “inbound” call, and warning about there being no inbound route. Before, chan_sip trunks could have an outbound and inbound configuration, which I think is the crux of the issue.

pastebin.freepbx.org/view/raw/bc7d86e3


It is an inbound call to the trunk in question. If you want to route these calls back out through other trunks with no restriction, set Context for this trunk to from-internal . If the calls are to be restricted in some ways, you can either adjust your Outbound Routes accordingly, or use a custom context.

Yea, try from-internal as Context that should work. If it gives exten issue try to set it to ‘s’

The inbound and outbound thing was necessary because chan_sip lacked the ability to cope with trunks which originated calls from different addresses from those to which outgoing calls are sent. The match (permit) setting for chan_pjsip addresses that problem more cleanly.

There are both “inbound” and “outbound” calls for this customer that use the same WAN IP, so I need a trunk that is from-pstn for the inbound calls. How would freepbx differentiate if I create a duplicate trunk using the same SIP Server IP, only with a from-internal context?

If you can get the customer system to register to FreePBX with two trunks, you can Match Inbound Authentication on Auth Username to distinguish the trunks. If that’s not possible or not suitable for your application, please describe the two systems in detail and how you want them to interoperate.

IP authentication is required. The current setup is our carrier > FreePBX > Customer Phone system, and vice versa if they are making outbound calls.

Inbound works fine - Our carrier sends the call to our FreePBX instance, trunk accepts, hits an inbound route that is routed to the trunk that has the customer WAN IP as the SIP server. Then their phone server answers and handles the rest.

Outbound should work like: they make a call from their handset, goes through their phone server, FreePBX accepts the call as coming from their WAN IP through their trunk, sees it as from-internal and hits a specific outbound route that looks like their caller IDs that are being sent and sends it through our carrier.

I don’t see why you are having trouble. The Context of a trunk only affects how inbound calls are handled. The customer-facing trunk has context from-internal, so calls arriving there are processed by your outbound routes and sent to the carrier. The carrier-facing trunk has context from-pstn, so calls arriving there are processed by your inbound routes and sent to the customer.

I presume that the issue is because there is an outbound trunk that is from-internal, and an inbound trunk that is from-pstn, but when their phone system is sending calls outbound to FreePBX it doesn’t know which trunk to use since they have the same SIP Server IP. So I don’t think any calls are even hitting the from-internal trunk for the reason that it has the same IP as the other. I’m just not familiar with a way to work around it.

Can’t you just use the same trunk on the customer side for both in and out?

I don’t understand how that would resolve the issue. The current issue is that any calls coming from their phone system into FreePBX is hitting the from-pstn trunk, even though it needs to hit the from-internal trunk in order for it to work properly.

Inbound calls coming from our carrier into FreePBX are correctly routing to the from-pstn trunk because that’s where the inbound route points to. But calls from their phone system are not hitting the right trunk in FreePBX.

So you have one customer trunk and at least one carrier trunk. What is going wrong (calls from carrier hitting the customer trunk, calls from customer hitting the carrier trunk, something else)?

The customer trunk should have Context from-internal and the carrier trunk(s) from-pstn.

I currently have two FreePBX trunks for this customer. The first is for calls from our carrier. It hits our carrier trunk, matches with an inbound route, then the inbound route sends it to another FreePBX trunk on the same system. This trunk is from-pstn and sends calls to their office IP address, which is where their phone system is located. This process works properly and I have no issues with it.

The second is for calls coming from the customer phone system. I have a separate FreePBX trunk that is from-internal that ideally calls from the customer phone system would go to, but the problem is that when those calls come in they are being matched by the from-pstn trunk - I’m assuming because both trunks have the customer IP address as the SIP server.

Why do you need that? Just set the Context on the to-customer trunk to from-internal.

If you really need to distinguish calls to two trunks from the same IP address and port, you could match by username, provided that they send caller ID in some header other than From. Or, if the customer PBX can authenticate, match the trunk by Auth Username, in which case they can put the calling number in From.

1 Like

You’re right. I realized as I was typing my previous response that I only needed one customer-facing trunk so I deleted the duplicate and changed it to from-internal and that resolved the issue.

Thanks @Stewart1 for talking me through it. Appreciate it!

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