Monday, December 29, 2014

Lync 2013 + Asterisk PBX integration

Lync 2013 + Asterisk Integration

Integrating Lync 2013 with Asterisk.

In this Blog I am going to explain how to integrate Lync 2013 with Asterisk PBX ( Elastix)
Assuming already lync 2013 in place and Asterisk pbx installed. I have the following setup.
1)      Lync 2013 Standard Edition Server Installed in Hyper-v
2)      Asterisk PBX ( Elastix) has been installed in  in Hyper-v
If Lync 2013 is not installed in you environment please try to Download the one and follow this step by step guide to install the Lync 2013
In my Environment I am using Elastix as my PBX you can download elastix for free check it out
Guide to install Elastix PBX
Asterisk PBX Side Configuration
if you want to integrate any PBX with Lync we have to create an SIP Trunk for the Integration. Now we will create an SIP trunk in the PBX.
Before proceeding further we have to make few changes in the PBX Configuration. As you know the lync will be working on TCP we have to Bing our PBX to TCP to do this we have to edit the file under etc/asterisk/sip_custom.conf file we have to add this two. After adding this restart the asterisk service to restart asterisk /etc/init.d/asterisk restart

Once you success fully installed the Elastix pbx if you type your PBX Ip address you will see this page enter the credentials  to login.

Then click on the PBX to configure the SIP trunk
Now click on the trunks
 Then  click on the Add SIP trunk
On the Outgoing setting, type trunk name, on the peers detail,
And no need to enter any Incoming settings just Leave it Blank.
host=IP Address of Lync/mediation server IP Address.
port=5060 Lync Mediation server Listening Port.
Once you added the Sip Trunk in PBX if you want to check enter this command asterisk –r
The type this command sip show peers here it is I can see my sip trunk.
We have created the SIP trunk in the PBX end now we will be creating PBX extensions
Click on  Extension  and create the PBX Extension
Enter the Extension Number ex: 1000 and the Display name.

Change the Transport to TCP Only because the Lync will work on TCP
Now we will be configuring the outbound rules for calling to Lync enter the name
 Create the Route Pattern in my case I have created the 10 digit extension in Lync  

At Lync End Configuration 

Open the Topology Builder. And change the TCP port to 5060 if it is listening on different port

Adding the SIP Trunk to the Lync Topology

To add the SIP Trunk to the Topology as a new PSTN Gateway, add a new PSTN Gateway as follows in Topology Builder:
Define the PSTN Gateway FQDN = IP Address of the external SIP Trunk
Define the Root Trunk (the associated trunk can be defined at the same time you create the PSTN gateway)
Trunk Name: <IP address of the SIP trunk>
Listening port for IP/PSTN Gateway: 5060   (in this case unencrypted TCP is being used; use 5061 for TLS encrypted)
Transport: TCP
Associated Mediation Server:  <Lync Front End Pool + Lync Site>
Associated Mediation Server port:  5060
Once the sip trunk added don’t forget to Publish the Topology.
Now open the Control Panel to create the dial plans.
Under control panel select the Voice Routing to create the Dial plan. Under Dial plan create an new site/pool plan.

Select the Register server

Enter the details
Under Associated Normalization Rules Select New. Here I have created two new Normalization rules one for my PBX Extensions (Ex: 1000) and one for Lync Extensions (ex: 1234567890).
As my extension length is 4 I have selected exactly 4 and we have to add + here because lync will know only E.164 (ex:+1000) as my pbx will not accept the + when the incoming call is coming I will delete this + in the later stage.
The second normalization rule is for my Lync extensions. Now it’s time to add the routes in the routes we will associate the SIP trunk which we have created. Select the route. Under the associated PSTN Usages select the SIP which we have created earlier.
Now it’s time to configure Trunk  Configuration as I said earlier PBX will not understand +1000 it doesn’t know this format in the Trunk configuration we will remove the + when sending the calls to PBX.
Check this if you are not removing the + sing this is what the out put
chan_sip.c:25627 handle_request_invite: Call from 'Lync1' ( to extension '+1000' rejected because extension not found in context 'from-internal'.
Under Called number Translation rules
 Select New
Now It’s time to Test the call in between Lync and Asterisk PBX.
Call between Pbx and Lync.

 between Lync and PBX
I thought to share Integration between Lync and Asterisk. Hope this help who are looking for Lync asterisk Integration. Any Comments are Welcome :)  


  1. Good Setp by Setp Guide

  2. Hi, thanks for sharing this guide.
    I setup Skype For Business (SFB) to communicate with my Asterisk servers and all seems to work fine, no errors. Except that the Comfort Noise (CN) isn't heard in the Polycom phones when calling from SFB client to a phone in Asterisk. The SFB client does generate CN in the computer side, but not the phone called to.
    The Polycom phones (IP335) do generate CN fine when making regular calls between phone or externally through Asterisk.
    The SFB server doesn't show any errors or warning in the logs.
    My Asterisk server are 1.8 and 11.2 versions. Same result for both.
    Not having Comfort Noise can be disruptive when having a conversation.
    Has anyone experieced this issue? Care to share the fix?

    SFB ------ Asterisk(VM) ----- Asterisk(Physical, TDM cards)----PSTN

  3. What if you have the cloud release of Lync ? I am using Microsoft Lync Onlice Service (O365) and it is impossible to do a trunk, so this options are not possible on the cloud...

  4. Only option valid there seems to be SimLync.... I am using SimLync with my Elastix and Lync install, but as far as I known SimLync also works with Office365 Online Services....

  5. Great Article
    I'm working on an integration to test Asterisk + S4Business Cloud Connector Edition.
    I followed this procedure but the calls are not passing through.
    Did you try similar scenarios?.