Multi-Tenant Configuration in FreeSWITCH
In this article we will be going over the basics of setting up a multi-tennant environment in FreeSWITCH
Directory
We will need to create a new directory for our second tennant. The default configuration is a good place to start from, so copy over the default.xml file and the default directory to the domain name of your new company.
cp default.xml dopensource.com.xml
cp -r default dopensource.com
Now, change the domain name, group name, and include directory with vim dopensource.com.xml
<domain name="dopensource.com">
...
<group name="dopensource.com">
...
<X-PRE-PROCESS cmd="include" data="dopensoruce.com/*.xml"/>
By default, each user is set to use the default context. We will need to change this if we want each company to have a different context. You can either change this in each users include file, or remove this line from those files and set it in the global directory xml file.
To remove all of the user_context
lines from the user’s include files, run this sed command.
sed -i '/<variable name="user_context" value="default"\/>/d' /etc/freeswitch/directory/dopensource.com/*
Then add the user_context setting in the directory xml file with vim dopensource.com.xml
<variables>
<variable name="record_stereo" value="true"/>
<variable name="default_gateway" value="$${default_provider}"/>
<variable name="default_areacode" value="$${default_areacode}"/>
<variable name="transfer_fallback_extension" value="operator"/>
<variable name="user_context" value="dopensource.com"/>
</variables>
Now when a user registered to our system via dopensource.com
, their calls will be processed in the context dopensource.com
. We will need to create this context for this to work though.
Dialplan
Now that we have setup our Directory, it is time to create a seperate context for our new company. We will start from the defaul.xml file as a base.
cd /etc/freeswitch/dialplan/
cp default.xml dopensource.com.xml
cp -r default dopensource.com
Now, we will need to change the name in dopensource.com
to reflect our new context with vim dopensource.com.xml
<context name="dopensource.com">
We also want to adjust the include directory.
<X-PRE-PROCESS cmd="include" data="dopensource.com/*.xml"/>
FreeSWITCH should now be configured to host a second company and seperate it into a new context. You can repeat this process for as many domain names as you like.
You will need to change your dns settings to make sure the domain name you use in your directory is actually routable to your FreeSWITCH server. Also, don’t forget to register to this domain name when setting up your phone.