Skip to content
PortalPBX

Asterisk with PJSIP (config files)

Configure the SIP Trunk on Asterisk

Manual PortalPBX trunk setup in Asterisk 16+ with chan_pjsip: registration, authentication, endpoint and dialplan.

Illustration: Asterisk with PortalPBX
Illustrative image.

Before you start

  • Asterisk 16 or later with chan_pjsip and root SSH access.
  • Trunk details provided by PortalPBX.
  • A backup of /etc/asterisk before editing.

Your trunk details

PortalPBX sends them when the trunk is activated. Replace each placeholder with your real value.

SIP server (host or domain)
<servidor-sip>
Port and transport
<puerto> · UDP / TCP / TLS
SIP username
<usuario>
SIP password
<contraseña>
Assigned DID number(s)
<DID>
Authentication mode
Registro / IP
Enabled codecs
G.711 (alaw/ulaw) · G.729*

* G.729 only if enabled on your trunk.

Step by step

  1. 1

    Transport

    In pjsip.conf define the transport; behind NAT add the public IP and local network:

    [transport-udp]
    type=transport
    protocol=udp
    bind=0.0.0.0
    ;external_media_address=<ip-publica>
    ;external_signaling_address=<ip-publica>
    ;local_net=192.168.0.0/16
  2. 2

    Registration and authentication

    Add the registration (if your trunk uses it) and the credentials:

    [portalpbx-reg]
    type=registration
    outbound_auth=portalpbx-auth
    server_uri=sip:<servidor-sip>
    client_uri=sip:<usuario>@<servidor-sip>
    retry_interval=60
    
    [portalpbx-auth]
    type=auth
    auth_type=userpass
    username=<usuario>
    password=<contraseña>
  3. 3

    AOR, endpoint and identify

    Define the trunk destination and endpoint:

    [portalpbx]
    type=aor
    contact=sip:<servidor-sip>
    qualify_frequency=60
    
    [portalpbx]
    type=endpoint
    transport=transport-udp
    context=from-portalpbx
    disallow=all
    allow=alaw,ulaw
    outbound_auth=portalpbx-auth
    aors=portalpbx
    from_user=<usuario>
    from_domain=<servidor-sip>
    rtp_symmetric=yes
    force_rport=yes
    rewrite_contact=yes
    
    [portalpbx]
    type=identify
    endpoint=portalpbx
    match=<servidor-sip>
  4. 4

    Dialplan

    In extensions.conf: inbound per DID and outbound through the trunk:

    [from-portalpbx]
    exten => <DID>,1,Dial(PJSIP/100,30)
     same => n,Hangup()
    
    [salida]
    exten => _X.,1,Set(CALLERID(num)=<DID>)
     same => n,Dial(PJSIP/${EXTEN}@portalpbx,60)
     same => n,Hangup()
  5. 5

    Reload and verify

    Reload and check registration and reachability:

    asterisk -rx "pjsip reload"
    asterisk -rx "pjsip show registrations"
    asterisk -rx "pjsip show endpoint portalpbx"

Recommendations

  • To debug, temporarily enable SIP logging: pjsip set logger on.
  • Prefer G.711 alaw/ulaw; use G.729 only if it is enabled on your trunk and supported by your equipment.
  • Disable SIP ALG on your router or firewall: it is the most common cause of one-way audio and dropped registrations.
  • If your PBX is behind NAT, set the public IP and local network, and open the RTP range your system uses.
  • Restrict SIP access with a firewall and use long extension passwords to prevent toll fraud.
  • Dial numbers in the format stated in your activation sheet (national or international) and check the caller ID.

Common errors

Rejected / 401

Wrong credentials or client_uri.

No matching endpoint

The identify section does not match the source of inbound calls.

488 Not Acceptable

No codec match: check allow=.

Audio en una vía

Check external_media_address, local_net and rtp_symmetric.

Need a hand?

We configure it with you, remotely

If the manual setup does not work, contact support or open a ticket. We review registration, routes, codecs and NAT with you through a secure remote session.

Cookie settings

Choose what you allow. You can change it anytime from “Cookie settings” in the footer.

Necessary

Site security (Cloudflare), and remembering your theme, currency and this choice. Always on.

When you play a video, YouTube (Google) may store data in your browser and receive your IP address.

Cookie policy