In this guide, you will learn how to configure a SIP trunk to use it with your Asterisk PBX.
Prerequisites
Make sure you have the following:
an installed and running Asterisk PBX server
a SIP account from CommPeak
The SIP credentials and domain details that you need are available in your account at CommPeak Portal in Setup -> SIP Accounts:
User - click SHOW under Username/IP in a SIP account line
Password - click Reset Password if you forgot it
Domain - sip.commpeak.com
Adding a SIP Trunk
Step 1: Access Asterisk
Access your Asterisk server via SSH (Secure Shell). Enter a command like this:
ssh user@your_asterisk_server_ip
Step 2: Locate SIP Configuration File
Asterisk PBX configurations are stored in .conf files, usually located in the /etc/asterisk directory. You will need the sip.conf file.
Navigate to the configuration directory:
cd /etc/asterisk
Open the sip.conf file using a text editor. Here we're using nano, but you can use your preferred editor:
sudo nano sip.conf
Step 3: Edit SIP Configuration File
In the sip.conf file, you'll find configurations for general settings, users, and trunks. You'll need to add the information about a new trunk with CommPeak's details at the end of your sip.conf file:
[CommPeak] type=peercontext=from-trunkhost=sip.commpeak.com username=”trunkusername” ; replace with your SIP Usernamesecret=”trunkpassword ; replace with your SIP Passwordfromuser=”trunkusername” ; replace with your SIP Usernamefromdomain=sip.commpeak.com insecure=invitequalify=yesdtmfmode=rfc2833disallow=allallow=ulaw, alaw, g729nat=yescanreinvite=no
Save and exit the file. In nano, you can do this by pressing Ctrl + X, then Y to confirm, and finally, Enter to save and exit.
Step 4: Reload SIP Modules
To apply the changes, reload the SIP modules on Asterisk.
Access the Asterisk CLI (Command Line Interface):
asterisk -rvvv
Then reload the SIP modules:
sip reload
Step 5: Verify SIP Trunk Registration
After reloading, you can verify if the trunk registration was successful by checking the SIP peers:
sip show peers
This will display a list of all the SIP peers. For the CommPeak trunk, the status should say OK if the trunk is registered correctly.
Step 6: Configure Dialplan
To use this SIP trunk, you must set up your dialplan in extensions.conf. It controls how incoming and outgoing calls are handled and routed.
Navigate to the configuration directory:
cd /etc/asterisk
Open the `extensions.conf` file:
sudo nano extensions.conf
Add a new context or modify an existing one to include the new trunk. The context must match the one you set in the sip.conf file (in our example, we used from-trunk).
Here's an example of how you might configure an outgoing rule:[outgoing]exten => _X.,1,Dial(SIP/CommPeak/${EXTEN})
In this example, outgoing is the context, _X. is a pattern that matches any number, and ${EXTEN} is the dialed number. The Dial application is used to connect the call to the SIP trunk.
Save and exit the file.
Step 7: Reload Dialplan
Now you need to reload the dialplan for the changes to take effect:
dialplan reload
Step 8: Test the SIP Trunk
Finally, you can make a test call to verify if everything is working correctly. You can do this from a registered SIP device (a softphone or an IP phone) that is configured to use your Asterisk PBX.
Remember to use the context that you defined in the extensions.conf file (outgoing in our example) for your SIP device.
Troubleshooting
If you encounter any issues, you can use the Asterisk CLI for troubleshooting. The sip debug on command will provide detailed information about the SIP communication, which can be useful for identifying problems.