Asterisk PBX Complete Guide

Comprehensive reference for Asterisk CLI commands, configuration, dialplan examples, and troubleshooting

56+
CLI Commands
25+
Troubleshooting Tips
8
Sections

1. What is Asterisk?

Asterisk is the world's most popular open-source PBX (Private Branch Exchange) and telephony framework. It was created by Mark Spencer in 1999 and first released under the name "Zapata Telephony." Originally developed by Digium, it is now maintained by Sangoma Technologies (which acquired Digium in 2018).

Written in C and running primarily on Linux, Asterisk powers millions of phone systems worldwide — from small business phone systems to large carrier-grade telecom infrastructure. It turns an ordinary computer into a full-featured communications server.

Asterisk supports a wide range of VoIP protocols including SIP (Session Initiation Protocol), IAX2 (Inter-Asterisk eXchange), PJSIP (the modern SIP stack), and DAHDI (Digium Asterisk Hardware Device Interface) for analog and digital telephony trunks (T1/E1/PRI/BRI).

Current Versions

  • Asterisk 18 — Long Term Support (LTS), supported until October 2025
  • Asterisk 20 — LTS release, supported until October 2027
  • Asterisk 21 — Standard release with latest features
  • Asterisk 22 — Latest development branch

2. Key Features

SIP Trunking

Connect to SIP providers for inbound/outbound calling over the internet

IVR (Auto Attendant)

Interactive Voice Response menus to route callers automatically

Call Queues (ACD)

Automatic Call Distribution to agents with hold music and announcements

Voicemail

Full voicemail system with email notifications and visual voicemail

Conference Calling

Multi-party audio and video conferencing (ConfBridge application)

Call Recording

Record calls for compliance, training, or quality assurance

CDR / CEL

Call Detail Records and Channel Event Logging for billing and analytics

AGI / ARI / AMI

Asterisk Gateway Interface, REST Interface, and Manager Interface for integration

Music on Hold

Play music or messages to callers on hold using MP3 or WAV files

WebRTC Support

Browser-based voice and video calls via WebSocket and SRTP

Codec Support

G.711 (ulaw/alaw), G.729, G.722, Opus, GSM, Speex, and more

Security

TLS/SRTP encryption, ACLs, fail2ban integration, and SIP security events

3. Architecture & Key Configuration Files

All Asterisk configuration files are typically located in /etc/asterisk/. Below are the most important files:

FilePurpose
asterisk.confMain Asterisk configuration: directories, options, and system settings
sip.confLegacy SIP (chan_sip) configuration: peers, trunks, registrations
pjsip.confModern PJSIP configuration: transports, endpoints, AORs, auth
extensions.confDialplan: call routing logic, IVR menus, ring groups
voicemail.confVoicemail settings: mailboxes, passwords, email notifications
queues.confCall queue configuration: strategies, timeouts, members
musiconhold.confMusic on hold classes and audio file locations
cdr.confCall Detail Records configuration and backend settings
cdr_mysql.confMySQL CDR backend configuration
cdr_pgsql.confPostgreSQL CDR backend configuration
modules.confModule loading/unloading: which Asterisk modules to load at startup
rtp.confRTP port range and settings (default 10000-20000)
features.confCall features: transfer, parking, pickup codes
manager.confAMI (Asterisk Manager Interface) user configuration
http.confBuilt-in HTTP server for ARI and WebSocket
ari.confAsterisk REST Interface user configuration
logger.confLogging configuration: log files, console output, syslog
confbridge.confConference bridge profiles and settings
res_odbc.confODBC database connection settings for realtime
extconfig.confRealtime configuration mapping (database-backed config)

Important Directories

DirectoryPurpose
/etc/asterisk/Configuration files
/var/lib/asterisk/sounds/Sound prompts (en, es, fr, etc.)
/var/lib/asterisk/moh/Music on hold audio files
/var/lib/asterisk/agi-bin/AGI scripts
/var/spool/asterisk/voicemail/Voicemail recordings
/var/spool/asterisk/monitor/Call recordings
/var/log/asterisk/Log files (full, messages, etc.)
/var/run/asterisk/PID file and control socket

4. Essential CLI Commands

Connect to the Asterisk console with asterisk -rvvv and use these commands. Prefix with asterisk -rx to run from the Linux shell.

CommandDescription
asterisk -rvvvConnect to running Asterisk console with verbose level 3
asterisk -rx 'core show channels'Run a CLI command from the Linux shell without entering console
core show channelsShow all active channels (current calls)
core show callsShow total number of active calls
core show versionDisplay the current Asterisk version
core show uptimeShow Asterisk uptime and last reload time
core show settingsDisplay global configuration settings
core show sysinfoShow system resource information (RAM, CPU, etc.)
core reloadReload all configuration files without restarting
core restart nowRestart Asterisk immediately (drops all calls)
core restart gracefullyRestart after all current calls complete
core stop gracefullyStop Asterisk after all current calls complete
core stop nowStop Asterisk immediately
core set verbose 5Set console verbose level (0-10)
core set debug 5Set debug level (0-10) for troubleshooting
sip show peersShow all registered SIP peers with status
sip show peer <name>Show detailed info for a specific SIP peer
sip show registryShow SIP trunk registrations and their status
sip show channelsShow active SIP channels
sip set debug onEnable SIP message debugging (very verbose)
sip set debug offDisable SIP message debugging
sip reloadReload SIP configuration (sip.conf)
sip qualify peer <name>Send OPTIONS to check if peer is reachable
pjsip show endpointsShow all PJSIP endpoints
pjsip show endpoint <name>Show details for a specific PJSIP endpoint
pjsip show registrationsShow PJSIP outbound registrations
pjsip show contactsShow PJSIP contacts (registered devices)
pjsip set logger onEnable PJSIP SIP message logging
pjsip set logger offDisable PJSIP SIP message logging
pjsip reloadReload PJSIP configuration
dialplan showShow the entire dialplan (can be very long)
dialplan show <context>Show dialplan for a specific context
dialplan reloadReload the dialplan (extensions.conf)
module showList all loaded modules
module load <module>Load a specific module
module unload <module>Unload a specific module
module reload <module>Reload a specific module
logger reloadReload the logger configuration
logger show channelsShow current logging channels
queue showShow all call queues and their members
queue show <queuename>Show details for a specific queue
queue add member <channel> to <queue>Dynamically add a member to a queue
queue remove member <channel> from <queue>Remove a member from a queue
voicemail show usersShow all configured voicemail users
database showShow all AstDB entries
database put <family> <key> <value>Add/update an entry in AstDB
database get <family> <key>Retrieve a value from AstDB
database del <family> <key>Delete an entry from AstDB
manager show usersShow AMI (Asterisk Manager Interface) users
channel originate SIP/100 extension 200@defaultOriginate a test call from ext 100 to 200
channel request hangup <channel>Request hangup of a specific channel
bridge show allShow all active bridges
cdr show statusShow CDR backend status
stun show statusShow STUN server status
rtp set debug onEnable RTP debugging
rtp set debug offDisable RTP debugging

5. Common Issues & Fixes

IssueCauseFix
404 Not Found on callsExtension not in dialplanCheck extensions.conf, ensure the extension exists in the correct context
Registration failed (401/403)Wrong credentials, IP, or portVerify username, secret, host in sip.conf/pjsip.conf peer definition
One-way audioNAT/firewall blocking RTPSet nat=force_rport,comedia in sip.conf; configure externaddr and localnet
No audio at allRTP ports blocked by firewallOpen UDP ports 10000-20000 in firewall; verify rtp.conf port range
Echo on callsFull-duplex sound card issue or high latencyEnable echo cancellation (echocancel=yes in DAHDI); reduce latency
Call drops after 30 secondsSIP ACK not reaching AsteriskCheck NAT/firewall settings; set qualify=yes; verify SIP ALG is disabled on router
Codec mismatch (488 error)No common codec negotiatedAdd allow=ulaw,alaw (or desired codecs) on both sides; check disallow=all first
503 Service UnavailablePeer unreachable or not registeredCheck network connectivity; set qualify=yes to monitor; verify peer is online
chan_sip deprecated warningsUsing legacy SIP driver on Asterisk 17+Migrate to PJSIP (pjsip.conf) which is the current recommended driver
High CPU usageToo many codec transcodingsUse the same codec on both sides to avoid transcoding; check for infinite loops in dialplan
Calls connect but DTMF not workingDTMF mode mismatchSet dtmfmode=rfc2833 (or auto) on both sides; ensure matching DTMF settings
SIP REGISTER timeoutDNS resolution failure or network issueVerify DNS or use IP directly; check network route; increase registration timeout
MusicOnHold not playingMOH files missing or wrong formatEnsure files exist in /var/lib/asterisk/moh/; use WAV 8kHz mono or native format
Voicemail not recordingPermissions or storage issueCheck /var/spool/asterisk/voicemail/ permissions; verify voicemail.conf settings
CDR records not being writtenCDR backend misconfiguredCheck cdr.conf, cdr_mysql.conf or cdr_pgsql.conf; ensure database connection works
Asterisk won't startConfig syntax error or port conflictRun asterisk -C /etc/asterisk/asterisk.conf -cvvv to see startup errors
Peer shows UNREACHABLEQualify OPTIONS not getting responseCheck firewall; set qualifyfreq to a reasonable value; verify peer IP
Context mismatch / calls rejectedIncoming calls routed to wrong contextVerify the context= setting in the peer definition matches your dialplan
TLS/SRTP handshake failureCertificate issue or mismatched settingsVerify certificate paths in sip.conf/pjsip.conf; ensure both sides support TLS
Fax failures (T.38)T.38 re-INVITE rejectedEnable t38pt_udptl=yes in peer config; ensure fax detect is configured
Parking lot not workingFeatures.conf misconfiguredCheck features.conf parking settings; ensure parkext and parkpos are correct
Queue agents not receiving callsAgent not logged in or pausedVerify agent is added to queue and not paused; check queue penalties
AGI script not executingPermission or path issueEnsure script is in /var/lib/asterisk/agi-bin/ with execute permissions (chmod +x)
AMI connection refusedManager.conf not configuredEnable AMI in manager.conf; set bindaddr, permit/deny ACLs; restart Asterisk
WebRTC calls failingWebSocket or ICE configuration issueEnable WebSocket transport in PJSIP; configure STUN/TURN; use valid TLS certificates

6. Sample Dialplan Examples (extensions.conf)

Example 1: Basic Internal Calling

[internal]
; Internal extensions 100-199
exten => _1XX,1,NoOp(Calling extension ${EXTEN})
 same => n,Dial(PJSIP/${EXTEN},30,tTrR)
 same => n,GotoIf($[${DIALSTATUS} = BUSY]?busy:unavail)
 same => n(busy),Playback(vm-isonphone)
 same => n,Hangup()
 same => n(unavail),VoiceMail(${EXTEN}@default,u)
 same => n,Hangup()

; Voicemail access
exten => *98,1,VoiceMailMain(${CALLERID(num)}@default)
 same => n,Hangup()

Example 2: IVR Menu (Auto Attendant)

[ivr-main]
exten => s,1,Answer()
 same => n,Wait(1)
 same => n,Set(TIMEOUT(response)=5)
 same => n(menu),Background(custom/welcome-menu)
 same => n,WaitExten(5)
 same => n,Goto(s,menu)

; Press 1 for Sales
exten => 1,1,Goto(queue-sales,s,1)
; Press 2 for Support
exten => 2,1,Goto(queue-support,s,1)
; Press 3 for Directory
exten => 3,1,Directory(default,internal,f)
; Press 0 for Operator
exten => 0,1,Dial(PJSIP/100,30)
 same => n,Hangup()
; Invalid input
exten => i,1,Playback(invalid)
 same => n,Goto(ivr-main,s,menu)
; Timeout
exten => t,1,Goto(ivr-main,s,menu)

Example 3: Outbound Dialing via SIP Trunk

[outbound]
; Local calls (10 digits)
exten => _NXXNXXXXXX,1,NoOp(Local call to ${EXTEN})
 same => n,Set(CALLERID(num)=5551234567)
 same => n,Dial(PJSIP/${EXTEN}@my-sip-trunk,60)
 same => n,Hangup()

; International calls (011 + country code)
exten => _011.,1,NoOp(International call to ${EXTEN})
 same => n,Set(CALLERID(num)=5551234567)
 same => n,Dial(PJSIP/${EXTEN}@my-sip-trunk,120)
 same => n,Hangup()

; Emergency
exten => 911,1,Dial(PJSIP/911@my-sip-trunk,60)
 same => n,Hangup()

Example 4: Time-Based Routing

[incoming]
exten => s,1,Answer()
 same => n,GotoIfTime(09:00-17:00,mon-fri,*,*?open)
 same => n,GotoIfTime(09:00-13:00,sat,*,*?open)
 same => n,Goto(closed)
 same => n(open),Goto(ivr-main,s,1)
 same => n(closed),Playback(custom/office-closed)
 same => n,VoiceMail(100@default,u)
 same => n,Hangup()

; Holiday check (alternative)
; exten => s,1,GotoIf($[${DB(holidays/${STRFTIME(${EPOCH},,%Y%m%d)})} = 1]?holiday)
;  same => n(holiday),Playback(custom/holiday-greeting)
;  same => n,VoiceMail(100@default,u)
;  same => n,Hangup()

7. SIP (chan_sip) vs PJSIP Comparison

chan_sip (sip.conf) is the legacy SIP driver deprecated since Asterisk 17 and removed in Asterisk 21. PJSIP (pjsip.conf) is the modern, recommended SIP stack.

Featurechan_sip (Legacy)PJSIP (Recommended)
StatusDeprecated (removed in Asterisk 21)Current & Recommended
Config Filesip.confpjsip.conf
Multiple RegistrationsNo (one registration per peer)Yes (multiple contacts per endpoint)
WebSocket (WebRTC)Limited / Not supportedFull support
Multiple SIP TransportsOne transport onlyMultiple transports (UDP, TCP, TLS, WS, WSS)
Realtime SupportBasicFull realtime with sorcery
Path Header SupportNoYes
Configuration StyleMonolithic (peer/user/friend)Modular (endpoint, aor, auth, transport)
NAT HandlingManual (nat=, externaddr=)Improved automatic NAT handling
Video SupportBasicFull video support including VP8/VP9
SRTPBasic SRTPFull SRTP/DTLS-SRTP for WebRTC
Codec NegotiationBasicAdvanced codec negotiation
PerformanceGoodBetter (pjproject-based)
CLI Commandssip show peers/registrypjsip show endpoints/registrations

Sample PJSIP Endpoint Configuration

; /etc/asterisk/pjsip.conf

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0:5060
external_media_address=YOUR_PUBLIC_IP
external_signaling_address=YOUR_PUBLIC_IP
local_net=192.168.1.0/24

; Extension 100
[100]
type=endpoint
context=internal
disallow=all
allow=ulaw,alaw,opus
auth=100-auth
aors=100
callerid="John Doe" <100>
webrtc=no

[100-auth]
type=auth
auth_type=userpass
username=100
password=SecurePass123!

[100-aor]
type=aor
max_contacts=3
remove_existing=yes
qualify_frequency=30

; SIP Trunk
[my-sip-trunk]
type=endpoint
context=from-trunk
disallow=all
allow=ulaw,alaw
outbound_auth=trunk-auth
aors=trunk-aor

[trunk-auth]
type=auth
auth_type=userpass
username=your_trunk_user
password=your_trunk_pass

[trunk-aor]
type=aor
contact=sip:sip.provider.com

[trunk-reg]
type=registration
outbound_auth=trunk-auth
server_uri=sip:sip.provider.com
client_uri=sip:your_trunk_user@sip.provider.com

8. Useful Resources

Asterisk is a registered trademark of Sangoma Technologies. This guide is for educational and reference purposes. Always refer to the official Asterisk documentation for the most up-to-date information.