chan_sip vs pjsip: Migration Runbook and Setting Map
The main difference in chan_sip vs pjsip is that chan_sip uses one [peer] section per device, while PJSIP splits each device into endpoint, aor and auth objects. chan_sip is removed in Asterisk 21, so extensions and trunks must move.
- chan_sip was deprecated in Asterisk 17 and removed in Asterisk 21, and FreePBX 17 is PJSIP-only, so any upgrade path forces the migration.
- Each chan_sip peer becomes at least three PJSIP objects: endpoint (media and routing), aor (registration contact limits) and auth (credentials).
- Both drivers default to UDP 5060, so move one of them (for example chan_sip to 5160) before running them side by side.
- In FreePBX an extension number cannot exist in both drivers at once, so pilot one extension at a time and keep the old config and a backup for rollback.
- Trunks need manual rebuilding as registration, auth, aor, endpoint and identify objects, and Fail2ban jails must be updated to watch PJSIP log lines.
What is the real difference between chan_sip and PJSIP?
chan_sip is the legacy SIP channel driver configured in sip.conf. Each phone or trunk is a single [peer] section that mixes credentials, media, NAT and registration behaviour. It was deprecated in Asterisk 17 and removed in Asterisk 21.
chan_pjsip is built on the PJSIP library and configured in pjsip.conf. It splits every device into separate objects, so one registration can be shared, reused or matched in different ways. FreePBX 13 added chan_pjsip as an option, and later releases made it the default for new extensions. FreePBX 15 and 16 support both drivers, and FreePBX 17 is PJSIP-only.
The object model is the main thing to learn. Most migration errors come from misplacing a setting on the wrong object, not from the settings themselves.
| PJSIP object | Job | Typical settings |
|---|---|---|
| transport | Socket Asterisk listens on | type=transport, protocol=udp, bind=0.0.0.0:5060, external_signaling_address, local_net |
| endpoint | Call behaviour for one device or trunk | context, disallow/allow, aors, auth, direct_media, dtmf_mode, force_rport, rtp_symmetric |
| aor | Where the device can be reached | max_contacts, qualify_frequency, remove_existing, contact (for static trunks) |
| auth | Credentials | auth_type=userpass, username, password |
| identify | Match inbound packets by source IP | endpoint, match |
| registration | Outbound registration to a provider | server_uri, client_uri, outbound_auth, retry_interval |
How do sip.conf settings map to PJSIP objects?
Use this table as a one-to-one translation sheet while you read through sip.conf. Settings that have no equivalent are listed in a later section.
| chan_sip (sip.conf) | PJSIP equivalent | Object |
|---|---|---|
| host=dynamic | max_contacts=1 (or more) | aor |
| secret= | password= with auth_type=userpass | auth |
| username= | username= | auth |
| context= | context= | endpoint |
| disallow= / allow= | disallow= / allow=, same syntax | endpoint |
| nat=force_rport,comedia | force_rport=yes, rtp_symmetric=yes, rewrite_contact=yes | endpoint |
| qualify=yes | qualify_frequency=60 (seconds) | aor |
| canreinvite=no | direct_media=no | endpoint |
| dtmfmode=rfc2833 | dtmf_mode=rfc4733 | endpoint |
| insecure=invite / host=1.2.3.4 | identify section with match=1.2.3.4 | identify |
| register => user:pass@host | registration with client_uri, server_uri, outbound_auth | registration |
| bindport / udpbind | bind= on the transport | transport |
| externip / localnet | external_signaling_address, external_media_address, local_net | transport |
What does a minimal working pjsip.conf extension look like?
This is the smallest config for one registering phone. The endpoint names its auth and aor, and by default Asterisk identifies the inbound request by the username in the From header matching the endpoint name.
On plain Asterisk, put this in pjsip.conf. On FreePBX, do not edit pjsip.conf directly because it is regenerated. Use the GUI or pjsip_custom.conf.
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0:5060
; behind NAT, add:
;external_signaling_address=203.0.113.10
;external_media_address=203.0.113.10
;local_net=192.168.1.0/24
[1001]
type=endpoint
context=from-internal
disallow=all
allow=ulaw,alaw
transport=transport-udp
auth=1001
aors=1001
direct_media=no
force_rport=yes
rtp_symmetric=yes
rewrite_contact=yes
dtmf_mode=rfc4733
[1001]
type=auth
auth_type=userpass
username=1001
password=UseALongRandomSecret1
[1001]
type=aor
max_contacts=1
remove_existing=yes
qualify_frequency=60 How do I verify the PJSIP extension is working?
Reload the module, then check each object type. A phone that shows Unavailable in the endpoint list but has no contact has not registered. A contact with status Unavail means the OPTIONS qualify is failing, which usually points to NAT or a firewall.
- Reload with module reload res_pjsip.so (or fwconsole reload on FreePBX).
- Run pjsip show endpoints and confirm the endpoint exists and shows Not in use.
- Run pjsip show aors to confirm max_contacts and the contact count.
- Run pjsip show contacts to see the registered address, port and RTT status (Avail or Unavail).
- If registration fails, run pjsip set logger on and watch with sngrep. A 401 with no retry means a wrong password. A 401 or 403 on a phone that does send credentials usually means the endpoint was not identified, so check that the From user matches the endpoint name.
asterisk -rx "module reload res_pjsip.so"
asterisk -rx "pjsip show endpoints"
asterisk -rx "pjsip show aors"
asterisk -rx "pjsip show contacts"
asterisk -rx "pjsip set logger on"
sngrep -d any port 5060 How do I avoid the chan_sip and PJSIP port conflict on 5060?
Both drivers default to UDP 5060. Whichever loads second fails to bind, and the symptom is usually a log line about being unable to bind, with the other stack's phones working and the new ones silent. Running both in parallel requires distinct ports.
In FreePBX, go to Settings > Asterisk SIP Settings. Set the chan_sip port (for example 5160) in the Chan SIP tab and the PJSIP port in the Chan PJSIP tab. Keeping the production phones on their current port and moving the new stack avoids repointing everything. Which stack to move depends on which one your phones already use.
On plain Asterisk, chan_sip uses bindport in the [general] section of sip.conf, and PJSIP uses bind= in the transport.
Phones moved to the new driver must be repointed to the new server port, and firewall and NAT rules must allow the added port.
; sip.conf (legacy, moved aside)
[general]
bindport=5160
; pjsip.conf (new)
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0:5060Which FreePBX conversion method should I use?
FreePBX offers three routes. All of them convert extensions only. None of them rebuilds trunks, custom sip_general settings or provider registrations, so those need manual work.
One FreePBX rule drives the order of operations: an extension number cannot exist in both drivers at once. You switch the device driver on the existing extension, or create the new PJSIP extension after removing or changing the old one. You cannot create a second extension 1001 next to the first.
| Method | Best for | Carries over | Does not carry over |
|---|---|---|---|
| Convert to PJSIP option on the extension (or Chan_SIP to PJSIP converter in Connectivity) | Many standard extensions at once | Extension number, secret, voicemail, CID, most core settings | Custom sip_general, sip_custom overrides, odd per-device options |
| Per-extension Device driver change | Pilot extensions and one-by-one cutovers | Extension and its dialplan routing | Anything stored only in chan_sip custom fields |
| Bulk Handler export, change tech column, import | Large or scripted moves | Everything in the export CSV | Trunks, registrations, anything not in the CSV; needs a clean test import first |
Which behaviour differences break phones after migration?
Most failures come from behaviour, not syntax. These are the ones that cause tickets.
chan_sip identified a caller by peer name or IP, and PJSIP identifies by the From user, then by identify objects, so a mismatch yields 401 or 403 responses. Realtime peers do not behave identically in PJSIP, and host=dynamic does not exist because max_contacts replaces it.
call-limit has no equivalent. Use device state busy detection and the endpoint's device_state settings, or limit channels in the dialplan. BLF and MWI depend on the mailboxes= setting on the endpoint and on subscription handling, so re-test them. Auto-provisioned phones often carry the old port in their templates and need updating.
On FreePBX, sip_custom and sip_additional files are chan_sip specific. Customisations stored there are silently dropped for a converted extension, so diff them before and after.
| Symptom | Likely cause | Fix |
|---|---|---|
| 401 or 403 on REGISTER | Endpoint not identified, or wrong auth | Match From user to endpoint name, check auth link |
| Phone registers then goes Unavail | qualify or NAT problem | Set force_rport, rewrite_contact, check firewall |
| Registered but no phone ring | Wrong port in provisioning template | Update the template and re-provision |
| One-way audio | Missing external_media_address or local_net | Set both on the transport |
| BLF lamps dead, no MWI | Subscriptions or mailboxes missing | Set mailboxes= and test NOTIFY with sngrep |
| Fail2ban never bans | Jail watches chan_sip log lines | Use a PJSIP-aware filter on the security log |
How do I migrate trunks and run the pilot with a rollback?
A chan_sip trunk with register=> becomes five objects. Build them by hand, test them on the new port, and only then change routes.
Provider registration needs a registration object with client_uri, server_uri and outbound_auth, plus auth, aor, endpoint and an identify with match for the provider IP. Set from_user and from_domain on the endpoint if the provider needs a specific From header, and set contact on the aor if the provider is static.
- Back up with fwconsole backup, and copy sip.conf, pjsip.conf and the asterisk database.
- Open a maintenance window, and define go/no-go criteria before you start (for example all test calls pass and no registration failures after 30 minutes).
- Move chan_sip to its own port, for example 5160, with old configs untouched.
- Convert one or two pilot extensions and repoint those phones to the new port.
- Test registration, inbound and outbound calls, voicemail and MWI, BLF, attended and blind transfers, hold, DTMF into an IVR, and one-way audio. Watch with pjsip set logger on and core show channels.
- Build the PJSIP trunk beside the old one and test inbound and outbound before you change the routes.
- Update the firewall and Fail2ban jails for PJSIP logs, then move the remaining extensions in batches over a few days.
- Rollback: switch the device driver back for the affected extensions, point phones and provisioning templates to the old port, and restore the backup if the database was damaged.
Common questions
In which Asterisk version was chan_sip removed?
chan_sip was deprecated starting in Asterisk 17 and removed in Asterisk 21. Asterisk 18, 19 and 20 still include it, so you have time on those versions, but not on Asterisk 21 or later.
Can chan_sip and PJSIP run at the same time?
Yes, on Asterisk 20 and earlier and on FreePBX 15 and 16, provided they listen on different ports. Give each a distinct port, such as 5060 for PJSIP and 5160 for chan_sip.
Why does PJSIP need three objects for one extension?
Separating endpoint, auth and aor lets several endpoints share credentials, and lets one aor hold several contacts. It also makes identification, registration and media behaviour independent, which chan_sip could not do in one peer.
Do I have to recreate FreePBX trunks when moving to PJSIP?
Yes. The converters handle extensions, but trunks, registrations and custom sip_general settings must be rebuilt by hand on the PJSIP side and tested before routes are switched.
How do I replace call-limit in PJSIP?
PJSIP has no call-limit option. Use device state busy detection so a busy endpoint reports in-use, or enforce a limit with a dialplan check such as GROUP or GROUP_COUNT before dialling.