Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

SIP Trunk Configuration in FreePBX

Posted: July 5, 2024 9 min read

Introduction

Session Initiation Protocol (SIP) trunking is a digital method used for making and receiving phone calls and other digital communication over an internet connection. The term “trunk” in SIP trunking refers to virtual phone lines that enable phone calls over the internet to anyone with a phone number. SIP trunks not only handle voice calls but can also be used for multimedia communication, integrating voice, video, and messaging services. SIP trunks are gradually replacing analog and ISDN phone lines, with many countries now planning to phase out ISDN services.

How Does SIP Trunking Work?

Previously, businesses utilized ISDN circuits or copper lines, which were physically set up on their premises. SIP trunking, however, substitutes these analog phone lines with a digital alternative. This is achieved by dividing calls into ‘digital packets’ and transmitting them across a data network. The different elements of the SIP trunking system are detailed below.

SIP Trunks

SIP trunks group together multiple SIP lines, typically exceeding 20 in number. These trunks serve as intermediaries between a company’s phone connections and its Internet Telephony Service Provider (ITSP). You can envision the SIP trunk as a simulated phone line linking a residence or business to a telephony service provider. It facilitates two-way communication between the corporate network and various other phone and data networks. To illustrate, you can link your PBX to the Public Switched Telephone Network (PSTN).

SIP Channels

SIP channels represent the digital alternative to traditional phone lines, providing the capability for two concurrent calls—one incoming and one outgoing. Unlike physical phone lines, additional SIP channels can be easily added as required without the necessity for wiring.

SIP Protocol

The Session Initiation Protocol comprises a collection of communication guidelines utilized for establishing and terminating data connections over the Internet. It facilitates the initiation of voice communication sessions online, allowing users to engage in conversations via phone calls, video calls, or messaging services.

SIP Providers

SIP services like voice calls, video conferencing, and instant messaging are provided by SIP providers, who bundle one or more SIP connections and integrate them with a company’s on-premise private branch exchange (PBX). These SIP connections are then channeled through a SIP trunk, allowing calls and other digital communications to take place over an internet connection. The choice of SIP provider depends on the specific services required by a business. While all SIP providers offer SIP trunking to businesses with a PBX, only a handful of them furnish an Internet Protocol PBX (IP PBX) for companies lacking an existing PBX system. This enables businesses to rely solely on phone connections to harness the benefits of SIP trunking.

sip trunking Working

Learn more about SIP Trunking here.

Now that you have a clear understanding of what SIP trunks are and how they work, let’s get started on setting up a trunk in FreePBX.

Login to FreePBX GUI Panel

The first thing we need to do is log in to FreePBX. If you haven’t installed FreePBX yet, it’s highly recommended to check this article on how to install FreePBX on Ubuntu. To access FreePBX, go to:

https://your_server_ip/admin/config.php

Replace your_server_ip with the IP address of your FreePBX server.

After navigating to the URL, enter the correct credentials, which include the username and password.

Once logged in, you will be brought to the FreePBX Dashboard.

Enable The Chan_SIP Channel Driver

To configure a SIP_Chan-based SIP trunk in FreePBX 16, you need to enable the Chan_SIP channel driver, as it is deprecated by default.

  1. Go to the Settings tab.
  2. Navigate to Advanced Settings.
FreePBX Advanced Settings Dropdown Item

Scroll down to the SIP Channel Driver section, or use the search function:

  • CTRL + F (Windows/Linux)
  • Command(⌘) + F (MacOS)
  1. Choose both from the dropdown menu.
FreePBX chan_sip_driver

  1. Click the Submit button to apply changes.
  2. Click the Apply Config button to reload the Asterisk PBX modules as shown below.

Apply Changes FreePBX

Downloading FreePBX Modules

Before setting up the trunk, ensure all FreePBX modules are updated:

  1. Go to the Admin tab.
  2. Click on Module Admin.
  3. Check for updates and install all available updates.

FreePBX Admin Tab

If you don’t want all modules, then the only module required is config edit which enables you to write custom dialplans in FreePBX instead of going to the server settings. so make sure, you get that by downloading that from the Module Admin Tab.

FreePBX Admin Module Inside

Inside the Module Admin, you will see something like the above. There You have to move the Module Updates, and you will find several FreePBX modules, Select the Standard and Extended as shown in the Picture and click Check Online, You will get several options after clicking the Check Online Button.

FreePBX Dowload All Modules

You have to click The Download ALL Button to download all the necessary modules. You have to click download all because not all modules are downloaded at once, so make sure you download the Config Edit Module as it is super important.

Setting Up the SIP Trunk

With the Chan_SIP driver enabled and modules updated, you are now ready to set up the SIP trunk.

Accessing the Connectivity Tab

  1. Navigate to the Connectivity tab.
  2. Click on Trunks.
FreePBX Connectivity Tab
FreePBX-SIP-Trunk-Dashboard
  1. Click on Add Trunk
  2. and select Add Trunk as shown below.
  3. After Clicking Add Trunk, you have to select the Add SIP (chan_sip) Trunk as shown below in the picture.
FreePBX-CHAN_PJSIP-TRUNK-ADD-Button

After that, follow the below guides.

General Settings

In the General tab, fill in the following details:

  1. Trunk Name: Give your trunk a recognizable name.
  2. Outbound CallerID: Set the caller ID that will be sent when making outbound calls as shown above in the picture. It is optional but recommended.

FreePBX chan_sip general tab

SIP Settings

Outgoing Settings
  1. Switch to the Outgoing tab.
  2. Set the Trunk Name to a unique identifier.
  3. Under the PEER Details section, enter the SIP settings provided by your VoIP provider. These typically include the following:
host=***provider ip address***
username=***userid***
secret=***password***
type=peer

click Submit and Apply Changes as described in other sections.

These settings are for the outgoing call(you will make a call).

chan_sip sip settings tab FreePBX

You have to enter the Registration String for this trunk. Follow these steps to do that:

  1. Go to the Admin tab.
  2. Click on Config Edit.
  3. Search for the file sip_registrations_custom.conf
  4. Enter the registration string provided by your VoIP provider in the following format:
username:password@voip_provider_domain
  1. Click Submit to save the changes.
  2. Click Apply Config to apply the new settings.

By following these steps, you will have successfully entered the registration string for your SIP trunk, enabling proper communication between your FreePBX system and your VoIP provider.

Incoming Settings
  1. Switch to the Incoming tab.
  2. Set the User Context to a unique name.
  3. Under the USER Details section, enter the necessary settings:
secret=***password***
type=user
context=from-trunk

This is most often the account name or number your provider expects. This USER Context will be used to define the below user details.

Registration String

  1. In the Registration tab, enter the registration string provided by your VoIP provider. The format usually looks like this:
FreePBX sip incoming tab

username:password@voip_provider_domain

Many providers will require you to provide a DID number, ex: username:password@switch.voipprovider.com/didnumber in order for any DID matching to work.

Just Set The Registration String as described above, so you can omit the User details and also the User Context.

Saving the Trunk

  1. After filling in all the necessary details, click the Submit button.
  2. Click on the Apply Config button at the top to apply the new settings.

Configuring Outbound Routes

To use your new SIP trunk for outbound calls, you need to configure an outbound route:

  1. Go to the Connectivity tab and click on Outbound Routes.
  2. Click on Add Outbound Route.
FreePBX Outbound Route

In the Trunk Sequence for Matched Routes section, select the SIP trunk you just created as shown below.

FreePBX OutBound Route
FreePBX Dial Pattern Settings
  1. Fill in the Route Name and set the Dial Patterns according to your needs.

A Dial Pattern is a unique set of digits that will select this route and send the call to the designated trunks. If a dialed pattern matches this route, no subsequent routes will be tried. If Time Groups are enabled, subsequent routes will be checked for matches outside of the designated time(s).

Rules:

Xmatches any digit from 0-9
Zmatches any digit from 1-9
Nmatches any digit from 2-9
[1237-9]matches any digit or letter in the brackets (in this example, 1,2,3,7,8,9)
.wildcard, matches one or more characters, not recommended
prepend:Digits to prepend to a successful match. If the dialed number matches the patterns specified by the subsequent columns, then this will be prepended before sending to the trunks.
prefix:Prefix to remove on a successful match. The dialed number is compared to this and the subsequent columns for a match. Upon a match, this prefix is removed from the dialed number before sending it to the trunks.
match pattern:The dialed number will be compared against the prefix + this match pattern. Upon a match, the match pattern portion of the dialed number will be sent to the trunks
CallerID:If CallerID is supplied, the dialed number will only match the prefix + match pattern if the CallerID being transmitted matches this. When extensions make outbound calls, the CallerID will be their extension number and NOT their Outbound CID. The above special matching sequences can be used for CallerID matching similar to other number matches.
Dial Patterns

After that hit Submit and Apply Changes Button.

Configuring Inbound Routes

To receive calls on your new SIP trunk, configure an inbound route:

  1. Go to the Connectivity tab and click on Inbound Routes.
  2. Click on Add Inbound Route.
FreePBX Inbound Route
  1. Fill in the DID Number and CID Number fields if needed.
  2. In the Set Destination section, select where you want the incoming calls to be routed (e.g., an extension, IVR, ring group).
Inbound Route FreePBX

3.  Submit and Apply Changes.

You have created both the sip trunks for incoming and outgoing calls.

Conclusion

By following these steps, you should have successfully set up a chan_sip SIP trunk in FreePBX. This setup will allow your PBX to connect to an external VoIP provider, enabling both inbound and outbound calls.

Leave a Reply

Your email address will not be published. Required fields are marked *