Asterisk inbound and outbound routing
Route design starts with the digits received, the caller's entry context and the destination that caller may reach. Preserve those distinctions when translating a public number into an internal extension or preparing an outbound provider request.
Source-reviewed, 18 October 2026. Prepared from the cited documentation. Examples have not been independently tested by Phone Guides. Scope: Asterisk 22/PJSIP, a preconfigured provider endpoint, and direct file-based dialplans. Provider formats and permissions must come from that service's documentation.
Map the incoming route
Record the provider-delivered number format before writing the match. It might differ from the number a person dialled. Confirm the intended delivery field and format from provider documentation, then inspect the actual dialplan entry in your own system. Do not equate the caller's displayed identity with the called destination.
The following original illustration sends the exact provider-delivered token 5550100 to the internal endpoint 6001:
[pg-provider-in]
exten => 5550100,1,Dial(PJSIP/6001,20)
same => n,Hangup()
5550100 is a fictional incoming token, not an assigned public number. Replace it with the exact value documented and delivered for your service. Assign the trunk endpoint's inbound context to pg-provider-in through its supported configuration path. Do not assign office accounts to that context as a shortcut.
The context has no paid outbound route. Inspect any includes elsewhere before concluding that this is also true of the complete system. The official dialplan security guidance explains why entry-context reachability is the permission boundary.
Design outbound permission before a dial string
Decide which accounts may make which calls, in what number format and through which provider. Start with a narrow intended destination set. Account authentication establishes an identity, while the dialplan decides which destinations that identity may reach.
The following is an explanatory expression, not a ready-to-paste route:
Dial(PJSIP/<provider-formatted-number>@<trunk-endpoint>,30)
Replace the angle-bracket terms only after defining the trunk endpoint, its address/contact and the provider's required number format. This expression deliberately has no wildcard or automatic include that would grant external calling. The official PJSIP dialling guide describes endpoint/AOR and explicit-URI forms.
Keep normalisation visible
| Field | Decision to record |
|---|---|
| Digits dialled by the user | Internal extension, national format, international format or an access prefix |
| Digits sent to the provider | Exact format required by the service |
| Caller identity | Authorised identity and provider acceptance policy |
| Incoming destination | Exact delivered token and chosen internal route |
| Failure handling | What happens on no route, busy, unavailable or unanswered calls |
Do not remove a prefix merely because another country's example does so. Explain every digit transformation with input/output examples appropriate to the service. A pattern should express the permitted format, not hide an unknown numbering requirement.
Inspect and verify each direction
After a file-based change, reload and use dialplan show pg-provider-in to inspect the loaded inbound route. For an outbound route, inspect the context assigned to the authorised office accounts and all its includes. The context/priority reference describes lookup; the Dial reference describes application results.
On your own deployment, check one inbound call, one permitted outbound call and one denied destination. Record identity, ringing, answer, audio and hangup separately. Include unanswered/unavailable handling before declaring the route complete. Do not promise failover or emergency-service suitability from one successful ordinary call.
Preserve the prior configuration for reversal. If the result differs from the design, use first troubleshooting checks rather than adding a catch-all route. Return to Asterisk documentation.