Series: Exchange 2013 and Lync 2013 Integration with AsteriskNOW PBX Pt. 2


In Part 1 of this series I went through the process of setting up our AsteriskNOW PBX. Now in Part 2 we need to connect the AsteriskNOW PBX to our Lync 2013 environment. We will break this down into 4 primary steps. First step will be to configure AsteriskNOW SIP trunk to route calls to Lync, Secondly we need to configure Lync to Normalize and Route calls to AsteriskNOW, third we need to enable Lync users for EV,  and finally we will test calls in both directions.

Let’s open the FreePBX Admin page (http://asteriskserverip), click FreePBX Administration, and then type admin for both the username and password. Once you have connected click on Connectivity, select Trunks, and then choose “Add SIP Trunk”. Input the details below that pertain to your environment. A lot of the articles that I ran into left out 2 very important settings type=friend and insecure=very which caused my communication to fail. Also be sure to clear out both the USER Context and User Details boxes. After entering this data select Submit Changes at the bottom of screen (scroll all the way down) and then the red Apply Config at the top of the screen.

  • host=<IP address of Lync Server or SE FQDN\EE Pool Name>
  • transport=tcp,udp
  • port=5060
  • insecure=very
  • fromdomain=<IP Address of AsteriskNOW PBX Server>
  • type=friend
  • context=from-internal
  • promiscredir=yes
  • qualify=yes
  • canreinvite=yes

***Added the couple of commands below which were brought to my attention by the Anonymous User below and Ariel L (Microsoft)***

Depending on your version you might be able to do this via GUI. If in the GUI you see Settings – Advanced SIP Settings then click on that. Scroll down to "Other SIP Settings" and add the following two lines tcpenable = yes and transport = tcp. If you don't see those then you will need to edit the sip_custom.conf that Anonymous described below. To edit this file you can perform the following commands from Linux shell after logged in as elevated user or root.

vi /etc/asterisk/sip_custom.conf

Hit Insert on the keyboard and type  tcpenable = yes and transport = tcp on 2 separate lines

Hit the Esc key on the keyboard to exit Insert mode and type :wq to save and exit


Now we need to configure our Inbound and Outbound routes. First our Inbound Route. Click Connectivity and select Inbound Routes. In the Description give your incoming route a name (FromLync) and under Set Destination select Trunks and select the trunk we created above (Fabrikam Lync Trunk). Click Submit and then Apply Config.

Next is our outbound route going to Lync. Click Connectivity and select Outbound Routes. In the Route Name give the route a name (ToLync) and under Trunk Sequence for Matched Routes select our Trunk (Fabrikam Lync Trunk). Now the most important part which I skipped over is we need to set our Dial Patterns that will use this Route. When we send calls to Lync they will need to be in E.164 format (e.g. +12673645102) so that Lync will recognize them. In the prepend field under dial patterns we need put our Lync TEL URI (including the +) excluding the extension (e.g. +1267364). Now in the match pattern field put the first digit of your extension followed by X’s for the remainder of the digits. Since I will be using 4 digit extensions starting with 5 I will insert 5XXX. See example below. Next select Submit Changes and then Apply Config. This completes our AsteriskNow configuration and we can now move to the Lync 2013 side.

Now that AsteriskNOW can route calls to Lync we need to configure Lync to accept the calls for EV enabled users and route calls back. We are going to start by creating a SIP Trunk to AsteriskNOW so lets open the Lync Topology builder on one of our Lync Servers. Once the topology build is opened choose Download Current Topology and choose a location where to save the file. Once the Topology Builder shows our servers expand Lync Server \ SiteName \ Lync Server 2013 \ Mediation pools. Right click the mediation pool that we will route this trunk through and select edit properties. Under Listening ports we need to set TCP to 5060-5060 (see below) and click OK.

Now under Shared Components right click PSTN gateways and choose New IP/PSTN Gateway. Under FQDN put the IP Address of the AsteriskNOW server and click next, again click next on the Define the IP Address screen, now on the define root change the listening port and mediation ports to 5060 and the SIP transport to TCP, and finally click finish. When clicking finish in addition to creating the IP/PSTN Gateway it will also create a SIP trunk under Trunks. Your settings should look similar to below based on your environment.

After creating these components we need to publish our Topology. To do this select Action \ Topology \ Publish and select Next \Finish to complete the Publish.

To configure the Voice Routing in Lync open the Lync Control panel on a Lync Server and go to the “Voice Routing” tab. Under Dial Plan we either need to create a new dial plan or use an existing one. The key here is to create normalization rules under the dial plan to convert our Lync numbers from AsteriskNOW to E.164 format and the AsteriskNOW numbers to just 4 digit extensions. If you use the global dial pan you won’t need to assign this to users but if you create a new “User” dial plan you will. I decided to create new,  so click New and then User dial plan. Give it a name and then under Associated Normalization Rules click new and create 2 different translation rules similar to the screenshots below. After you create or edit the Dial plan be sure to click Commit \ Commit All.

Now change over to the Voice policy tab and double click the Global Voice Policy. Under Associated PSTN Usages click new. Give the Usage a name (PSTN Usage – AsteriskNOW) and below Associated Routes select New and again give it a Name (Voice Route – AsteriskNOW Router). In Starting digits for numbers that you want to allow type 3 and click Add. Keep clicking OK until you get back to the Voice Policy main screen and Commit \ Commit All.

Finally lets EV enable some Lync users and test a call. In the Lync Control Panel \ Users \ Click Find. Double click a user you want to EV enable. Under the user properties change telephony to Enterprise Voice, give the user a Line URI in the format tel:+12673655102;ext=5102, select the User Dial plan policy you created earlier (if you edited the Global policy you don’t have to change this), and click Commit. Do this for as many users that are required.

Now to test some calls. From the X-Lite Client (AsteriskNOW extension 3002) let’s call one of our Lync EV enabled users (User1 extension 5102). Success. Now let’s call from Lync to the AsteriskNOW extension 3002. Again Success.

We now have full VoIP connectivity from Asterisk to Lync and back. In the next part of this series we will tie Lync 2013 to Exchange 2013 UM.

Comments (28)

  1. Richard Schwendiman says:

    @Fabrice – yes you can put any number you want. Be sure to change the voice policy and outbound route from Asterisk

  2. Anonymous says:

    Thanks Richard. In my case, I must change the etc/asterisk/sip_custom.conf with two paras:
    tcpenable=yes
    transport=tcp

    It works fine!

    Vu Pham

  3. bluesky1943 says:

    Great Tutorail! Thanks!

  4. Anonymous says:

    @Paul – Just posted 🙂

  5. Anonymous says:

    Can't wait for the Pt. 3!

  6. Daniel R. says:

    Great Tutorial!.. congratulations!.. all work fine here with my implementation (follow your 2 parts)

    and waiting the 3rd part!

    again… great work..   thanks

    Daniel R.

  7. Paul Bayley says:

    Great tutorial – any idea when part 3 is out?

    This has solved so many integration issues we were having – thank you!

    p

  8. Kris says:

    Great instructions Richard.

    Do you know when Lync Online will be able to connect with AsteriskNOW?  It has to be the biggest drawback with Office 365, there being no way to connect to the outside phone world from Lync, without adding an on-premise Lync Server.

    Thanks, Kris

  9. Anonymous says:

    In Part 1 and Part 2 of this series we configured AsteriskNOW PBX and connected it to our Lync 2013 environment

  10. fabrice says:

    Hello
    I followed all but the part 2 did not work

  11. fabrice says:

    Hello in the user setting line url can i put the tel that I want ??.
    and change the voice policy with it ??
    still dont work i have a error voice message
    i tried from xlite to lync and other side
    tks please hhelp

  12. Collin says:

    It didn’t work for me

  13. Tim says:

    Richard,

    Thanks for a great article.

    I can get Asterisk to call Lync extensions but not vice versa. I get an error saying the call cannot be completed do to restrictions on your account.

  14. Tim says:

    Fixed.

    Need to added the PSTN Gateway into the Associated Trunks for the Voice Route.

  15. Farhan says:

    Call from X-Lite to Lync not succeeded (Failed to dial) can anyone help 🙁

  16. Roger says:

    This is brillant. How do i connect to call PSTN number. This is all connected internal. Thanks once again very detailed solution.

  17. Richard, first thanks for you time to write a very detailed article. IMPORTANT: You missed an important point: You must to update Asterisk after the Asterisk configuration, So on the Asterisk logon on the server as root and type "yum update". Thanks.

  18. Umer says:

    Not Working i Cant Call From Xlite to Lync OR Lync To X Lite i have done same as it is step which you defined but cant calll did in this article any step is missing kindly update

  19. Matt says:

    Just set this up in my lab. Excellent walkthrough, thanks very much. The one issue I did run into was Asterisk rejecting calls from Lync which was easy to see in the Asterisk logs. I had to go into Settings > Asterisk SIP Settings and allow Anonymous SIP
    Calls. I don’t see this being required in your guide though, so did I miss something? I would expect that creating the SIP Trunk would no longer make this an anonymous connection.

  20. Matt says:

    Also in case anyone doesn’t have the Asterisk VM connected to the internet. You will receive Fatal Errors when trying to create the Extensions until you connect the VM to the internet and re-run the first boot command via the console (/etc/pbx_first_boot.sh).

  21. André S says:

    You know, I’ve been struggeling with trying to interconnect Asterisk (which has the connection towards the SIP provider) and Lync 2013 a couple of days now without getting it to work (Lync consistently rejected the invite from Asterisk with 400 bad request,
    assuming now it has something to do with the normalization rules). This howto covered everything straight forward from top to bottoms! Your over 1 year old post has definitely saved my (…girlfriends…..) weekend! Thanks a lot for an excellent guide!

  22. James says:

    Richard,

    First…great tutorial. I’m fairly familiar and proficient with Lync, but had never touched Asterisk before and I got basic functionality up and running in about 30 minutes. A couple quick questions:

    1.) If I initiate a call from Lync to an Asterisk extension, and I choose to "decline" the call in X-Lite, Lync reports that the callee is "in another call." Is this normal, or is there a signalling issue going on, do you think?

    2. On the AsteriskX-Lite side, caller ID from a Lync call comes in as "+12345(or whatever extension)@" This makes calling the Lync caller back from the X-Lite client impossible. It works fine on the Lync side, where the 5 digit extension of the Asterisk caller
    is normalized to a simple 12345, which LyncUM can deal with. Any idea on how to manipulate that?

    Once again…really great write-up, the best on the subject I could find!

  23. AlexeyKzn says:

    Hi, two strings is not enough, my asterisk didn’t want to listen tcp port,
    add the third string: tcpbindaddr: 0.0.0.0

    sip_custom.conf
    tcpenable=yes
    tcpbindaddr=0.0.0.0
    transport=tcp,udp

    Pls pay attention, i am not sure, but some people told, that tcp should be before udp.

  24. Tim says:

    @James. You can manipulate the caller ID string which is passed to XLite on the Asterisk server within the dialplan. As I recall you do this by creating a custom context.

    @anyone. Getting this sort of integration working with O365 would be something.

  25. Tom Oneil says:

    @Tim, if you want to integrate it with O365, they only approach I known so far is Simplync
    It allows you to directly register lync client with on-house Lync Servers, or with Lync Online, without the need of gateways… Take a look at
    http://www.simplync.net

  26. Jennifer says:

    We currently have this set up and running where I can call an asterisk phone and vice versa. I was wondering if it was possible to configure the following scenario

    when a external pstn call is made from astericks, have lync reroute that call out a different pstn gateway?
    right now, when we attempt to make an external call, it goes to lync and fails as it is looking for a user with that phone number in lync.