Prerequisites
- Familiarity with configuring Freeswitch 1.2 or newer with mod_sofia.
- Freeswitch 1.2 or newer is installed and running with mod_sofia as well as appropriate permissions and behind a secure firewall.
- A valid OnSIP Hosted PBX account.
- An OnSIP Trunking enabled user.
Step 1: Gather information for the OnSIP Trunking User
You will need the following information from the OnSIP Trunking User in theOnSIP App as Admin :
- Username
- Auth Username
- SIP Password
- Domain
You can find this information in the user detail pages under the Users tab in the Phone Settings section.

Step 2: Create an OnSIP Trunking user profile with OnSIP Trunking details
In your $PREFIX/freeswitch/conf/sip_profiles/external/ directory create a file
such as "onsip-trunk.xml" and populate the following parameters with your OnSIP Trunking credentials, for example:
<include>
<!--gateway name required, you will use this in the outbound dialplan -->
<gateway name="onsip-trunk.com">
<!--/// set to onsip auth_username ///-->
<param name="username" value="example_hiro"/>
<!--/// set to onsip user_name ///-->
<param name="from-user" value="hiro"/>
<!--/// set to onsip domain ///-->
<param name="from-domain" value="example.onsip.com"/>
<param name="realm" value="example.onsip.com"/>
<!--/// set to onsip password ///-->
<param name="password" value="VPG3hockrifv"/>
<!--/// *optional* set to your inbound extension ///-->
<param name="extension" value="15135555555"/>
<!--/// don't change these ///-->
<param name="outbound-proxy" value="sip.onsip.com"/>
<param name="expire-seconds" value="3600"/>
<param name="caller-id-in-from" value="true"/>
<!--/// if behind weird firewall, uncomment : ///-->
<!--<param name="ping" value="25"/>-->
</gateway>
</include>
Save and exit your "onsip-trunk.xml" file.
Reload mod_sofia with the new OnSIP Trunk details using reload mod_sofia from the FreeSwitch cli.
Verify registration from the FreeSwitch cli by typing:sofia status
Step 3: Edit your outbound dialplan in the $PREFIX/conf/dialplan/ directory with outbound dialing modifications.
In your outbound dialplan set the outbound CallerID name.
- The outbound "From:" section of an outbound SIP Invite request should look like this:
From: "15135555555" <sip:hiro@example.onsip.com >;tag=as04cfd8dfWhere 15135555555 is your inbound DID.
This can generally be accomplished by a line such as:
<action application="set" data="effective_caller_id_name=15135555555"/>
Where "onsip-trunk.com" is a defined and registered external gateway.
Here is a sample configuration :
<include>
<extension name="domestic.example.com">
<!-- The following line detects 11 digit outbound calls -->
<condition field="destination_number" expression="^(\d{11})$">
<!-- This sets the outbound Caller ID as "15135555555"-->
<action application="set" data="effective_caller_id_name=15135555555"/>
<!-- This sets the outbound gateway as "onsip-trunk.com" ,
which was defined in your OnSIP Trunking user profile
as the "gateway name" parameter.-->
<action application="bridge" data="sofia/gateway/onsip-trunk.com/000$1"/>
</condition>
</extension>
</include>
Save and exit your outbound dial plan configuration.
Reload the new dial plan by using reload mod_dialplan_xml from the FreeSwitch cli.
Step 4: Edit your inbound dial plan in $PREFIX/conf/dialplan/ directory to route inbound calls
Now that outbound calls work, you should make sure that your inbound dial plan appropriately routes incoming calls. This can generally be accomplished by a line such as:<condition field="destination_number" expression="^(15135555555)$">
Which will match the telephone number in the inbound SIP invite.
Where “15135555555” is the number routed to your account.
Here is a sample configuration:
<include>
<extension name="public_did">
<!-- This identifies the incoming call destined for 15135555555 -->
<condition field="destination_number" expression="^(15135555555)$">
<action application="set" data="domain_name=$${domain}"/>
<!-- This transfers the call to the "default" context
and passes along a data parameter of "1000". -->
<action application="transfer" data="1000 XML default"/>
<!-- Alternatively the following line will route the call
directly to the internal extension "1000".
The "%" is used to indicate that the end point is
registered locally. -->
<action application="bridge" data="sofia/internal/1000%" />
</condition>
</extension>
</include>
Save and exit your inbound dial plan configuration.
Reload the new dial plan by using reload mod_dialplan_xml from the FreeSwitch cli.
Step 5: Make test calls
Verify connectivity and correct signaling by placing test calls against a land line or cell phone.
You may need to make minor adjustments to your dialplan depending on your individual configuration.
Comments