PJSIP Trunk Template (Asterisk)

Created by Daniel Kauffer, Modified on Thu, 25 Jul at 3:50 PM by Daniel Kauffer

In this guide, we will provide you with a generic example of the pjsip.conf configuration file for use with Asterisk PBX. 

This file contains settings that define how Asterisk interacts with your SIP Trunk provider and handles incoming and outgoing calls. 

Please note that this is only an example configuration, and you may need to modify the settings based on your specific requirements and setup. 



pjsip.conf example:


;=============== TRANSPORTS ============================================


[transport-udp]

type = transport

protocol = udp

bind = 0.0.0.0

external_media_address = (Your PBX Public IP)

external_signaling_address = (Your PBX Public IP) 

external_signaling_port = 5060

local_net = 192.168.0.0/255.255.0.0 (change this IP Based on your PBC local network)


[transport-tcp]

type = transport

protocol = tcp

bind = 0.0.0.0

external_media_address = (Your PBX Public IP)

external_signaling_address = (Your PBX Public IP) 

external_signaling_port = 5060

local_net = 192.168.0.0/255.255.0.0 (change this IP Based on your PBX local network)


;=============== SIP TRUNK ===========================================


[megacall]

type=endpoint

transport=transport-udp

context=from_megacall

disallow=all

allow=alaw

allow=ulaw

outbound_auth=megacall

aors=megacall

direct_media=no

send_pai=yes

send_rpid=yes



[megacall]

type=auth

auth_type=digest

password= (password)

username= (username)

realm=gw.megacall.es


[megacall]

type=aor

contact=sip:18.153.197.168


[megacall]

type=identify

endpoint=megacall

match=18.153.197.168





Firewall


Signalling: Make sure you allow ALL traffic from the following IP Address: 18.153.197.168


RTP: By default, we will always send this traffic through the same Signaling IP, however, we recommend allowing all traffic from ANY IP in Port Range: 10000-20000.



Here are the steps you can take to meet the requirements:


  • Allow traffic from the signalling IP address:
  1. Log in to your firewall/router configuration page.
  2. Look for the option to add a new firewall rule or allow traffic.
  3. Add a new rule to allow traffic from the IP address 18.153.197.168 for the SIP signalling traffic.
  4. Save the changes to the firewall.


  • Allow traffic for the RTP Port Range:
  1. Log in to your firewall/router configuration page.
  2. Look for the option to add a new firewall rule or allow traffic.
  3. Add a new rule to allow traffic for the RTP port range 10000-20000 from any IP address.
  4. Save the changes to the firewall.



Note: The steps to configure your firewall/router may vary depending on the manufacturer and model. It's important to consult the documentation or support for your specific device.



You can also edit your Asterisk configuration:


To configure Asterisk to allow signalling only from IP 18.153.197.168 and RTP traffic from any IP through ports 10000-20000, you can follow these steps:

 

  1. Open the Asterisk configuration file, sip.conf, using a text editor such as vi or nano.

 

  1. Find the section [general] and add the following line:
bindaddr=18.153.197.168

This will bind Asterisk to listen only on IP 18.153.197.168 for SIP signalling.

 

  1. Find the section [udp] and add the following lines
; RTP ports range 
rtpstart=10000 
rtpend=20000 

; Allow RTP traffic from any IP 
icesupport=yes

This will allow RTP traffic from any IP through ports 10000-20000.

 

  1. Save the sip.conf file and reload the Asterisk configuration by running the command:
asterisk -rx "reload"


Now Asterisk should only allow signalling from IP 18.153.197.168 and RTP traffic from any IP through ports 10000-20000.




DNS SERVER


If you have a virtual phone number with your SIP Trunk service, you may need to add a configuration setting to ensure that inbound calls can be properly routed. Asterisk, the software that powers your PBX, does not support DNS server lookups for inbound calls, so it's important to disable this feature by adding the following line to the "sip_general_custom.conf" file:

srvlookup=no

This setting will prevent Asterisk from attempting to resolve virtual phone numbers using DNS, which can cause issues with call routing. By disabling srvlookup, your PBX will rely on the SIP Trunk service to properly route incoming calls based on the configured phone number.



To implement the DNS server requirement, you can follow these steps:

  1. Open the "sip_general_custom.conf"  file in a text editor.
  2. If the srvlookup parameter is not already present, add it to the file with the value set to no.
  3. Save the changes to the file and close it.
  4. Restart the Asterisk service to apply the changes.


To restart the Asterisk service, you can use the following command, depending on your operating system:


For CentOS/RedHat:


systemctl restart asterisk
Generic


For Ubuntu/Debian:


service asterisk restart
Generic



After completing these steps, Asterisk will no longer perform DNS server lookups for inbound calls, as specified by the SIP Trunk provider's requirements



Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article