2 FreePBX servers; only one of them has an external trunk

I have 2 FreePBX servers
PBX_A:192.168.22.3
PBX_B: 192.168.21.240
These are connected each other with chan_pjsip trunk with the following configuration.
PBX_A:
TrunkName=ToSperc
Maximum calls =100
UserName=ToSperc
Secret=xxx
Authentication= Outbound
context= from-internal
SIP server=192.168.21.240
SIP port=5060
From Domain=192.168.21.240
FromUser=2000
Match Permit=192.168.21.240

PBX_B:
TrunkName=ToSperc
Maximum calls =100
Secret=xxx
Authentication= Inbound
context= from-internal
SIP server=192.168.22.3
SIP port=5060
From Domain=192.168.22.3
FromUser=2000
Match Permit=192.168.22.3

by this I am capable to make internal calls between to servers.

only PBX_B has external trunk and I want PBX_A to use this to make calls.
I set in PBX_A an outbound route with dial pattern the same as PBX_B uses to make external calls and I set match sequence to point the trunk between PBX_A and PBX_B.

In PBX_B I set a custom destination
Target=from-internal,${EXTEN},1
Description=Allow passthrough Martiou to external

After that, in PBX_B I set an Inbound Route with CID=2000 and Destination Custom Destinations->Allow passthrough Martiou to external

But any external call from PBX_A fails.
I think I misconfigured something in PBX_B. Probably in Inbound Route?
Any suggestions?

Thanks in advance.

It seems to me that you have a routing loop, as your target its the point in the dialplan where the call from A originally entered.

Why did you need to do more than make the context be from-internal?

when I just set context=from-internal
then I try to call an external number from 22.3 FreePBX, is arrives to 21.240 server. but it redirected to an internal extension of 21.240 server and the default ringing group is ringing.

That would mean that a local user on B would not be able to call that external number.

local user in B is able to call external numbers, I checked it.
I think that when A makes an external call it arrives to B but B is handling it as inbound call, so routes it to internal extension.

how to overcome it? any ideas?

On B, turn on pjsip logger. Make a failing call from A to an external number (that you don’t have to redact, such as a local McDonald’s). Paste B’s Asterisk log for the call at pastebin.com and post the link here.

In that case, your endpoint definition, for B, on A, is not being matched.

NB never allow external callers to call external numbers. In general service providers are never authenticated, so you should never let anyone external be able to initiate a billable call.

At the end I change the trunk context=from-trunk in PBX_B for the trunk that connects with PBX_A.
After that I created in PBX_B a Custom destination with target ext-local,${EXTEN},1.
I created an inbound route to route extension from PBX_A to PBX_B with DID=_1XX and target the custom Destination.
And ony more inbound route to route external calls from PBX_A through PBX_B with DID= _X./_interconnection and target the trunk from SIP provider.
I don’t know if it is the bests solution, but at the moment it works.