Secure Trunking using chan_pjsip

    Overview

    In this section, we will guide you through the steps to configure Asterisk to implement secure trunking for outbound calling. To configure the asterisk using chan_pjsip to connect to your Plivo Zentrunk, locate the root configuration of Asterisk on your machine. These locations vary from platform to platform. In this case (Debian Jessie GNU/Linux System), the root configuration is present at /etc/asterisk.

    With the root configuration directory located, two major configurations need to be done-

    1. Create an endpoint for Trunk
    2. Create a Dial Plan
    3. Reload the configuration / Restart Asterisk

    Step 1: Create an endpoint for Trunk

    Create a new endpoint named zentrunk_endpoint_out at /etc/asterisk/pjsip.conf. You can use this endpoint to connect Zentrunk.

    pjsip.conf

    Endpoint to connect Zentrunk

    [zentrunk_endpoint_out]
    type=endpoint
    transport=transport-udp
    aors=zentrunk_aor
    disallow=all
    allow=ulaw
    outbound_auth=zentrunk_auth
    
    [zentrunk_aor]
    type=aor
    contact=sip:xxxxxxxxxxxxxxxx.zt.plivo.com:5060
    
    [zentrunk_auth]
    type=auth
    auth_type=userpass
    password=mitesh123
    username=mitesh
    
    [transport-udp]
    type=transport
    protocol=udp
    bind=0.0.0.0:5060
    
    • [zentrunk_endpoint_out]: This is an endpoint definition.

    • [zentrunk_aor]: This defines the Address of Record to be used by endpoint - zentrunk_endpoint_out. This tells Asterisk where an endpoint can be contacted. For that you will need to configure contact with the url which will point to Zentrunk as below:

         contact=sip:<"TERMINATION SIP DOMAIN" of your ZENTRUNK's Outbound Trunk> :5060
      
    • [zentrunk_auth]: This defines authentication for zentrunk_endpoint_out. When the Trunk challenges for the INVITE from Asterisk, this section will be used to authenticate.

    • [transport-udp]: The endpoint zentrunk_endpoint_out will use transport mentioned under this section.

    To test outbound calls using the above mentioned Trunk Configuration you may need an internal phone extension. For that, you may configure phone extension 6001 as mentioned below in pjsip.conf itself.

    Internal extension / phone configuration

    [6001]
    type=endpoint
    context=Zentrunk
    disallow=all
    allow=ulaw
    auth=6001
    aors=6001
    
    [6001]
    type=auth
    auth_type=userpass
    password=password1234
    username=6001
    
    [6001]
    type=aor
    max_contacts=1 
    

    You can register any SIP enabled phone with username: 6001 and password: password1234

    Step 2: Dialplan

    Next, you should set-up a dialplan. Below mentioned dial plan will dial out to ZENTRUNK using zentrunk_endpoint_out when 6001 (the SIP phone registered with username 6001) dial a number. Note that we have mentioned context=Zentrunk under endpoint 6001.

    Add below dial plan in extensions.conf under directory /etc/asterisk.

    extensions.conf

    [Zentrunk]
    exten => _X.,1,Set(CALLERID(all)="Your Plivo Number" <Your Plivo Number>)
    exten => _X.,n,Dial(PJSIP/${EXTEN}@zentrunk_endpoint_out)
    exten => _X.,n,Hangup()
    

    Step 3: Reload Configurations

    1. Execute the following command in your terminal to connect to the asterisk CLI:
       $ Asterisk -rvvvv 
      
    2. Execute the below command to reload chan_pjsip:
       $ pjsip reload
      
    3. Reload dialplan using below command:
       $ dialplan reload
      

    Caution: Configuration for transport type sections can't be reloaded during run-time without a full module unload and load. You need to restart Asterisk completely for your transport changes to take effect. We have one transport type section in the above configuration that is transport-udp. To restart asterisk please follow the below step.

    Restart Asterisk

    Execute the below command from the Linux command line to restart Asterisk.

    $ systemctl restart asterisk