PJSIP SIP Trunk Configuration

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

PJSIP SIP Trunk Configuration

A SIP trunk connects your Asterisk system to the PSTN via a VoIP provider. This snippet shows a complete, working PJSIP trunk configuration with all five required sections: auth, registration, endpoint, 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 codec preferences, the dialplan context for inbound calls (from-trunk), and caller ID behavior. direct_media=no forces all RTP 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

No notes yet. Be the first to contribute a tip or example.

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