Hi! We're Here to Help

Tetyana Kisyelova
Tetyana Kisyelova
  • Updated

Setting a SIP Trunk in an Asterisk PBX

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 my.commpeak.com 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.

  1. Navigate to the configuration directory:
    cd /etc/asterisk
  2. 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=peer
context=from-trunk
host=sip.commpeak.com
username=”trunkusername” ; replace with your SIP Username
secret=”trunkpassword ; replace with your SIP Password
fromuser=”trunkusername” ; replace with your SIP Username
fromdomain=sip.commpeak.com
insecure=invite
qualify=yes
dtmfmode=rfc2833
disallow=all
allow=ulaw, alaw, g729
nat=yes
canreinvite=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.

  1. Access the Asterisk CLI (Command Line Interface):
    asterisk -rvvv
  2. 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.

  1. Navigate to the configuration directory:
    cd /etc/asterisk
  2. Open the `extensions.conf` file:
    sudo nano extensions.conf
  3. 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/VoipProvider/${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.
  4. 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.

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.