Asterisk PJSIP: SIP Intro (Latest Versions)
Updated guide for modern Asterisk (PJSIP era): sip intro with real configs, common mistakes, and troubleshooting steps.
SIP (Session Initiation Protocol) is the core signaling protocol used to set up, manage, and end voice calls over IP networks.
In Asterisk, SIP is how phones, softphones, SIP trunks, and gateways register, authenticate, and initiate calls. Once SIP sets up the call, the actual audio flows separately using RTP.
Older tutorials often talk about chan_sip. Modern Asterisk (latest versions) primarily uses PJSIP (chan_pjsip). So this article explains SIP concepts in a way that matches today’s Asterisk deployments.
What SIP Actually Does
SIP handles signaling (call control), not audio. SIP messages negotiate:
- Who is calling whom
- Which codecs can be used
- Where to send media (IP/port) via SDP
- Authentication and registration
- Call state (ringing, answered, busy, ended)
Audio is carried by RTP after SIP negotiation completes.
SIP vs RTP (Simple Difference)
- SIP = call setup + control (INVITE, REGISTER, BYE)
- RTP = audio packets (the voice stream)
Many issues are confused because SIP can be “OK” while RTP is broken. Example: call connects but one-way audio happens because RTP is blocked by NAT/firewall.
Key SIP Concepts You Must Know
1. User Agent (UA)
A phone/softphone is a SIP User Agent. It can act as:
- UAC (client) when it initiates a call
- UAS (server) when it receives a call
2. Registrar
Asterisk receives registrations and records where each extension can be reached.
3. Proxy / Trunk Provider
SIP providers route calls to and from the public phone network (PSTN).
4. SDP (Session Description Protocol)
SDP is carried inside SIP messages and contains media details: codec list, IP/port for RTP, encryption capabilities, etc.
Most Common SIP Messages (What You See in Debug)
- REGISTER → phone tells Asterisk “I am reachable here”
- INVITE → start a call
- 100 Trying → request received
- 180 Ringing → destination is ringing
- 200 OK → call answered (includes SDP)
- ACK → confirms 200 OK
- BYE → end call
- CANCEL → cancel call before answer
If you learn these messages, SIP debugging becomes much easier.
SIP Authentication (Why 401 Happens)
SIP commonly uses challenge-response authentication. Asterisk responds with 401 Unauthorized to demand credentials, and the client retries with the proper Authorization header.
401 is not always an error — it is often part of normal authentication flow. The problem is when:
- Credentials are wrong
- Incoming traffic does not match an Identify rule (PJSIP)
- Provider is hitting the wrong endpoint
DTMF in SIP Calls (Why IVR Keys Sometimes Fail)
DTMF (key presses) can be sent in different ways:
- RFC4733 / RFC2833 (recommended and most common)
- SIP INFO
- Inband (inside audio stream, depends on codec quality)
If IVR works internally but fails from trunk/provider, DTMF mode mismatch is a top suspect.
SIP in Asterisk: chan_sip vs PJSIP (Modern Reality)
Historically, Asterisk used:
chan_sip configuration in sip.conf.
Modern Asterisk uses: PJSIP (chan_pjsip) configuration in:
/etc/asterisk/pjsip.conf- or a database-driven system (common in platforms like FreePBX / custom stacks)
If you are learning today: focus on PJSIP, because that is where active development and best practices live.
How SIP Endpoints Map to PJSIP Objects
In PJSIP, a “SIP peer” is not one block — it is typically separated into:
- endpoint → call settings (codecs, context, timers)
- auth → username/password (if needed)
- aor → contact location(s) / registration targets
- identify → match incoming IP/domain to endpoint (trunks)
This is one reason PJSIP is more powerful (and more strict) than old chan_sip tutorials.
Quick Checklist: What You Need for SIP to Work
- Correct endpoint configuration (PJSIP)
- Registration success (for phones) or Identify match (for trunks)
- Firewall allows SIP signaling ports (and TLS/WSS if used)
- Firewall allows RTP port range (audio)
- NAT settings correct (external_media_address, local_net, rtp_symmetric, etc.)
SIP working alone does not guarantee audio works — RTP must work too.
Common SIP Problems Beginners Face
Calls fail immediately
- Endpoint not matched (Identify missing)
- Wrong auth credentials
- Wrong context / dialplan route
Call connects but no audio / one-way audio
- NAT or RTP ports blocked
- Incorrect external address or local_net
IVR keypress not working
- DTMF mismatch (RFC4733 vs INFO vs inband)
Key Takeaway
SIP is the signaling layer that sets up the call. RTP carries the audio after SIP negotiation is complete.
Modern Asterisk deployments should focus on PJSIP, where endpoints are defined using endpoint/auth/aor/identify objects. Once you understand SIP messages (REGISTER, INVITE, 200 OK, BYE), debugging Asterisk becomes dramatically easier.
Want to see API-driven CRM + Telecom workflows in action? Try the WhatsApp bot or explore the demos.