Good question. You need to understand a little about FreeSWITCH dialplans in order to set this up the way I do it. This only for the scenario where FreeSWITCH is public and the gateway is on a remote network behind a NAT.
First I create an extension on Fusion and register the gateway to Fusion using the extension as the SIP user. In the example below it is 5800 using the Internal SIP profile (5060).
Once it's registered incoming calls from FreeSWITCH's perspective (from the gateway to FS) are pretty easy. Calls should just hit the domain context. So find out how many digits the gateway is sending and program FS accordingly.
Outbound calls (from FS to the gateway) require a little dialplan work. The trick is to lookup the registered contact and grab the public IP and Private IP of the gateway.
XML:
<extension name="sip_trunk" continue="true">
<condition field="destination_number" expression="^5551234567$">
<action application="set" data="called_contact=${sofia_contact(*/5800@${domain_name})}" inline="true"/>
</condition>
<condition field="${called_contact}" expression="^.*sofia.*sofia.*$" break="on-true"/> <condition field="${called_contact}" expression="^.*sip:.*@(\b(?:\d{1,3}\.){3}\d{1,3}\b)" break="never">
<action application="set" data="called_contact_internal_ip=$1" inline="true"/>
<anti-action application="set" data="called_contact_internal_ip=unknown" inline="true"/>
</condition>
<condition field="${called_contact}" expression="^.*fs_path=sip%3A\d+%40((?:\d{1,3}\.){3}\d{1,3}.*)" break="never">
<action application="set" data="call_timeout=45"/>
<action application="export" data="nolocal:absolute_codec_string=PCMU" inline="true"/>
<action application="set" data="called_contact_public_ip=$1" inline="true"/>
<action application="bridge" data="sofia/internal/sip:5551234567@${called_contact_internal_ip};transport=tcp;fs_nat=yes;fs_path=sip:5551234567@${called_contact_public_ip}"/>
</condition>
</extension>
In this example the Destination_number is hard coded (555-123-4567). You would need to match your destination number with a regex, store that as a variable then insert that variable into the bridge statement.
Sorry this isn't a complete cut and paste solution, but it should get you pointed in the right direction.