PJSIP SIP Trunk Configuration

Configuration Asterisk 20+ -- Last reviewed 2026-08-22 configuration pjsip trunk sip telnyx Found this useful? Upvote it. ×

PJSIP SIP Trunk Configuration

A SIPSession Initiation Protocol, the standard signaling protocol used to set up, manage, and tear down VoIP calls between Asterisk and phones or carriers. trunkA connection between Asterisk and another PBX or an ITSP/carrier, used to send and receive external calls. connects your Asterisk system to the PSTN via a VoIP provider. This snippet shows a complete, working PJSIPThe modern SIP channel driver in Asterisk (chan_pjsip), replacing the older chan_sip. Configured in pjsip.conf using endpoints, AORs, auths, and transports. trunk configuration with all five required sections: auth, registration, endpointIn PJSIP configuration, the SIP entity Asterisk communicates with: a phone, trunk, or other user agent. Defined by an endpoint section in pjsip.conf., AOR, and identify.

The Snippet

[trunk-auth]
type = auth
auth_type = userpass
username = your_trunk_username
password = your_trunk_password

; Registration - keeps the trunk alive with the provider
[trunk-reg]
type = registration
outbound_auth = trunk-auth
server_uri = sip:sip.provider.example.com
client_uri = sip:your_trunk_username@sip.provider.example.com

; Endpoint - defines how calls are handled
[trunk-endpoint]
type = endpoint
context = from-trunk
allow = !all,ulaw,alaw
outbound_auth = trunk-auth
aors = trunk-aor
direct_media = no
send_pai = yes
send_rpid = yes
trust_id_outbound = yes
from_domain = sip.provider.example.com

; AOR - address of record, tells Asterisk where to send calls
[trunk-aor]
type = aor
contact = sip:sip.provider.example.com
qualify_frequency = 60
qualify_timeout = 3.0

; Identify - matches inbound packets to this endpoint by IP
[trunk-identify]
type = identify
endpoint = trunk-endpoint
match = sip.provider.example.com

What Each Section Does

auth: Credentials for authenticating with the provider. Used by both the registration and outbound calls.

registration: Tells Asterisk to register with the provider so inbound calls get routed to you. The server_uri is the provider's SIP address. The client_uri is your identity on their platform.

endpoint: Defines codecA coder-decoder that compresses audio for transmission, such as ulaw, alaw, GSM, or Opus. Endpoints negotiate which codec a call uses. preferences, the dialplanThe core call-routing configuration of Asterisk, written mostly in extensions.conf as contexts, extensions, and priorities that decide how every call is handled. Full definition → contextA named section of the dialplan that groups extensions. Calls enter a specific context and can only reach extensions visible from it, making contexts the basic unit of call routing and security. for inbound calls (from-trunk), and caller IDThe calling party number (and optionally name) presented on an outbound call, set from the endpoint or manipulated in the dialplan. behavior. direct_media=no forces all RTPReal-time Transport Protocol. Carries the actual audio (media) of a VoIP call after SIP signaling has set it up. through Asterisk, which is required when behind NAT. send_pai and send_rpid pass caller ID information to the provider.

aor: The provider's contact address and health checking. qualify_frequency=60 sends an OPTIONS ping every 60 seconds to detect trunk failures early.

identify: Matches inbound SIP packets from the provider's IP to this endpoint. Without this, Asterisk won't know which endpoint configuration to use for incoming calls.

Outbound Dialing

Reference the endpoint name in your Dial() calls:

[outbound]
exten => _NXXNXXXXXX,1,Dial(PJSIP/1${EXTEN}@trunk-endpoint,120,tT)
exten => _1NXXNXXXXXX,1,Dial(PJSIP/${EXTEN}@trunk-endpoint,120,tT)

Verifying the Trunk

asterisk*CLI> pjsip show registrations

 <Registration/ServerURI......Location/Contact..........>
 ==========================location===========================
 trunk-reg/sip:sip.provider.example.com
                           sip:your_trunk_username@sip.provider.example.com
                                       Registered

asterisk*CLI> pjsip show endpoint trunk-endpoint

If registration shows Unregistered, check: 1. Credentials in [trunk-auth] 2. DNS resolution of the provider hostname 3. Firewall rules for SIP (UDP/TCP 5060) and RTP (UDP 10000-20000) 4. NAT traversal settings if behind a firewall

Provider-Specific Notes

Most SIP trunk providers (Telnyx, Twilio, Bandwidth, VoIP.ms) use this same general structure. The main differences are:

Check your provider's Asterisk integration guide for their specific values.

User Notes

Know a tip or gotcha for this topic? Share it below and help others.

Contribute a note

Share a tip, gotcha, or practical example. Keep it under 2000 characters. No questions (use the Asterisk community forums for support). Wrap code in backticks.

Moderated before publishing. Email never shown.
Related Snippets