Asterisk Dialplan: Advanced Dialplan Pattern Matching (X., _9NXX, etc.) (Latest Versions)
Updated guide for modern Asterisk (PJSIP era): advanced dialplan pattern matching (x., _9nxx, etc.) with real configs, common mistakes, and troubleshooting steps.
In Asterisk, the dialplan pattern matching engine is the foundation of how calls are routed, filtered, and controlled.
While basic extensions route simple calls, real-world telecom systems rely on advanced dialplan patterns to:
- Route outbound PSTN numbers correctly
- Separate local, national, and international dialing
- Block unauthorized or fraudulent destinations
- Normalize numbers before sending to SIP providers
- Control call flow based on business rules
Mastering dialplan matching is essential for building secure, scalable, enterprise-grade Asterisk deployments.
How Asterisk Matches Extensions Internally
When a call enters a context, Asterisk evaluates extensions in this order:
- Exact extension match
- Pattern match (starting with most specific)
- Special extensions like
i,t, orh
Because of this priority system, incorrect pattern ordering can silently route calls to the wrong destination.
Basic Pattern Symbols Refresher
_X → any single digit 0-9
_. → one or more digits (wildcard)
_N → digits 2-9
_Z → digits 1-9
[123] → specific digit set
Patterns always begin with an underscore:
exten => _X.,1,Dial(...)
Real-World Dialing Pattern Design
Enterprise dialplans typically separate calls into categories:
- Internal extensions → 3–4 digits
- Local PSTN → 10 digits
- National mobile → country format
- International → prefixed with 00 or +
Example production dialplan:
; Internal calls
exten => _2XXX,1,Dial(PJSIP/${EXTEN})
; Local 10-digit numbers
exten => _XXXXXXXXXX,1,Dial(PJSIP/provider/${EXTEN})
; International numbers
exten => _00.,1,Dial(PJSIP/provider/${EXTEN})
Number Normalization Before Dialing
SIP providers often require numbers in strict E.164 format.
Dialplan normalization ensures compatibility:
; Remove leading 0 and add country code
exten => _0XXXXXXXXX,1,Set(NUM=+91${EXTEN:1})
same => n,Dial(PJSIP/provider/${NUM})
Without normalization, providers may reject calls with 404, 484, or 403 errors.
Blocking Fraudulent or Premium Destinations
Dialplan patterns are also a security control layer.
; Block premium numbers
exten => _1900.,1,Playback(call-not-allowed)
same => n,Hangup()
; Block international dialing except approved
exten => _00.,1,Playback(invalid)
same => n,Hangup()
Without outbound filtering, SIP fraud can cause massive financial loss.
Pattern Priority and Overlap Problems
Overlapping patterns create hidden routing bugs.
Example mistake:
exten => _X.,1,Dial(provider)
exten => _00.,1,Playback(blocked)
Here, _X. captures international numbers first,
making the block rule useless.
Correct order:
exten => _00.,1,Playback(blocked)
exten => _X.,1,Dial(provider)
Advanced Pattern Techniques
Using Pattern Groups
exten => _[6-9]XXXXXXXXX,1,Dial(PJSIP/provider/${EXTEN})
Routes only valid mobile numbers.
Length Validation
exten => _XXXXXXXXXX,1,Goto(valid,1)
exten => _X.,1,Playback(invalid)
Prevents accidental short dialing.
Debugging Dialplan Matching
Show Dialplan
dialplan show
Trace a Live Call
core set verbose 5
This reveals:
- Which pattern matched
- Which priority executed
- Why routing failed
Real Production Failure Examples
- Outbound calls rejected due to wrong number format
- International fraud because of missing block pattern
- Calls routed to wrong trunk due to overlapping patterns
- Short dialing accidentally reaching PSTN
MYLINEHUB Architecture Insight
In MYLINEHUB telecom systems:
- Dialplan patterns enforce outbound security policies
- Number normalization ensures provider compatibility
- Campaign dialing uses validated routing logic
- AI-driven calls still depend on correct dialplan matching
Because of this, dialplan pattern design is treated as a core architecture layer, not just configuration.
Key Takeaway
Advanced dialplan patterns control:
- Call routing accuracy
- Security against fraud
- Provider compatibility
- Enterprise telecom scalability
Engineers who master dialplan matching gain full control over how every call behaves inside Asterisk.
Want to see API-driven CRM + Telecom workflows in action? Try the WhatsApp bot or explore the demos.
Comments (0)
Be the first to comment.