Skip to content
Phone Guides

Asterisk dialplan contexts, priorities and patterns

A dialplan is a set of instructions grouped into contexts. To understand a route, identify its entry context, the extension that matches, and the instructions executed from there. Then follow any includes or jumps that make more instructions reachable.

Source-reviewed, 18 October 2026. Prepared from the cited documentation. These examples have not been independently tested by Phone Guides. Scope: Asterisk 22 file-based dialplans.

Read an exact extension


[pg-example]
exten => 7000,1,Answer()
 same => n,Hangup()

[pg-example] names a context. 7000 is an exact dialled extension. 1 is the first priority. The next line uses same for the same extension and n for the next priority. This small syntax illustration answers and immediately ends the call; it intentionally has no prompt or outgoing destination.

A phone will not reach it merely because the context exists. Its incoming channel must enter that context or follow a route that reaches it. The official contexts, extensions and priorities guide explains that lookup model.

Inspect what an include makes reachable


[pg-office]
include => pg-internal

An include makes the included context's extensions available to lookup from the including context. It does not copy a security label onto them. Review the full include chain, especially when internal, provider and paid calling routes share a file.

Use dialplan security guidance when deciding which context a trunk or untrusted caller may enter. A context should expose only the destinations that entry point needs. Do not assume a caller is trusted because the request arrived from inside a private network.

Introduce patterns only when they express the intended range

Patterns begin with an underscore. Common tokens include X for any decimal digit, Z for 1-9 and N for 2-9. A bracket expression can restrict individual positions. For instance, _6XXX describes four-digit extensions starting with 6. It does not prove that all those destinations exist or that the caller should reach them.

The . and ! tokens are broader than a fixed digit count and affect matching behaviour. Use the upstream pattern reference to understand their scope and matching order before routing untrusted input. Avoid writing a catch-all paid route as an easy fix for a no-match error.

Intended design Check before using a pattern
Small internal account list Exact extensions may be clearer than a range
Number normalisation Confirm input format before removing or adding digits
External calling permission Restrict both who reaches the route and its destinations
Invalid input Choose deliberate failure behaviour rather than accidental fall-through

Read back and reason through the paths

At the Asterisk CLI, dialplan show pg-internal inspects the internal example context. Follow included contexts separately where needed. Check an allowed number, a number outside the intended range and a caller entering from a different context. These are questions for your deployment; Phone Guides has not run them on your system.

Preserve the previous file, use dialplan reload for a file-based change, read errors and inspect the resulting route. If a management product owns the dialplan, use its supported configuration path. Keep variables, conditions and subroutines out of an introductory route until the simpler lookup is clear.

Continue with first internal call or troubleshooting. Return to Asterisk documentation.