FreePBX Inbound Routes for Multiple DIDs: Setup and Fixes
For freepbx inbound routes multiple dids, create one route per number under Connectivity > Inbound Routes, with a DID Number that exactly matches what the carrier sends in the INVITE request-URI. Then add a safe catch-all.
- The DID Number field must match the user part of the INVITE request-URI character for character, so read the INVITE before you build routes.
- Matching order is exact DID first, then pattern, then the blank any-DID route.
- Never point a blank DID and blank CallerID route at a live destination. Use an announcement, a receptionist or Hangup.
- Test with core set verbose 5, pjsip set logger on and dialplan show ext-did, then read which ext-did line the call enters or whether it falls through to the catch-all.
- A 'No matching endpoint found' error means the trunk was not identified. It is not a DID routing problem.
What does the carrier send for each DID, and how do I find the format?
FreePBX does not read the number from a setting on the trunk. The PJSIP stack takes the user part of the INVITE request-URI as the dialed extension, and the call enters the from-trunk context with that string as the extension. The DID Number field in an inbound route is compared against that string, so a mismatch in even one character means no match.
Carriers deliver one of several formats: 10-digit (2125550101), 11-digit with a leading 1 (12125550101), E.164 with a plus (+12125550101), or a short extension-style number such as the last four digits. Some send different formats on different trunks, so check each trunk separately.
Capture a real call rather than guessing. Here is a typical INVITE from a carrier that delivers 10-digit numbers:
- Open the Asterisk console with asterisk -rvvvvv, then run core set verbose 5 and pjsip set logger on.
- Call the number from a mobile phone. In a second shell, you can run sngrep -d any port 5060 for a readable call flow.
- Read the first INVITE in the console and note the user part of the request-URI.
- Find the first Executing line for the from-trunk context, such as Executing [2125550101@from-trunk:1]. The string before the @ is the exact dialed string FreePBX will try to match against your routes.
- Run pjsip set logger off when you are done, because the logger is noisy and slows busy systems.
INVITE sip:2125550101@203.0.113.10:5060 SIP/2.0
From: "ACME CORP" <sip:3105550199@198.51.100.20>;tag=abc123
To: <sip:2125550101@203.0.113.10>
P-Called-Party-ID: <sip:+12125550101@198.51.100.20>
Diversion: <sip:2125550000@198.51.100.20>;reason=unconditionalHow do I set up inbound routes for multiple DIDs?
Build one route per number, and name each one after the number and its purpose, for example '2125550101 Main IVR'. A clear name saves you when you read CDR or the dialplan later.
Go to Connectivity > Inbound Routes > Add Inbound Route and fill in the fields below.
- Description: the number plus its purpose.
- DID Number: exactly what the INVITE carried, with no spaces, no leading or trailing digits and no stray punctuation.
- CallerID Number: leave blank unless you deliberately want to match only one caller.
- Set Destination: extension, ring group, IVR, queue, time condition, voicemail or Terminate Call.
- Optional, under Advanced: CID name prefix, Alert Info, Music On Hold and Language. Leave Language blank unless you need it, because a stray value can change prompts for the whole call.
- Click Submit, then click Apply Config. Skipping Apply Config is the most common reason a new route does nothing.
Which destination should each DID use?
The worked example below assumes a 10-digit carrier format. A CID name prefix such as SALES: and a distinct Alert Info (for example a different ring cadence on desk phones) let staff tell which number is ringing before they answer.
If the carrier mixes formats for one number, create a second route with the 11-digit form that points at the same destination.
| DID | Purpose | Destination | DID Number field | Extras |
|---|---|---|---|---|
| 2125550101 | Main line | IVR (Main Menu) | 2125550101 | Time condition in front for after-hours |
| 2125550102 | Sales | Ring group 600 | 2125550102 | CID prefix SALES: |
| 2125550103 | Fax | Fax extension or Fax Detect to an extension | 2125550103 | No CID prefix |
| 2125550104 | Direct number, one user | Extension 105 | 2125550104 | Voicemail fallback set on the extension |
| 2125550105 | Support, mixed formats | Queue 700 | 2125550105 and a second route 12125550105 | Use the second route only if the carrier mixes formats |
What order does FreePBX match routes in, and how do patterns work?
The generated ext-did context follows normal Asterisk matching. An exact DID wins over a pattern, and a pattern wins over the blank any-DID route. A pattern must start with an underscore in the DID Number field.
Pattern letters: X is any digit 0 to 9, Z is 1 to 9, N is 2 to 9, [1-5] is a set or range, a period (.) matches one or more characters, and ! matches zero or more. A plus sign is a literal character, so it has to appear in the pattern.
| Pattern | Matches | Typical use |
|---|---|---|
| _NXXNXXXXXX | Any 10-digit NANP number | Carrier sends 10 digits |
| _1NXXNXXXXXX | Any 11-digit number starting with 1 | Carrier sends 11 digits |
| _+1NXXNXXXXXX | Any E.164 US number | Carrier sends +1 |
| _X. | Anything of two or more characters starting with a digit | Broad catch for a trunk (use with care) |
| _555X | Four-digit numbers 5550 to 5559 | Short extension-style DIDs |
Why is the catch-all route dangerous, and what should it do?
A route with a blank DID and a blank CallerID Number is the catch-all. Anything that does not match a more specific route lands there. If it points at an IVR or ring group, scanners, misdialed numbers and fraud attempts reach a live destination, and a poorly built IVR with dial-by-extension can open the door to toll fraud.
Pick the treatment by what you want unknown calls to do.
| Catch-all destination | Use when | Risk |
|---|---|---|
| Terminate Call > Hangup | You own every number on the trunk | Callers with a real but unassigned number hear nothing useful |
| Announcement 'number not in service' | The carrier may deliver numbers you have not built yet | Low, but keep it short |
| Receptionist extension | A person can triage unknowns | Rings a human with every wrong number |
| IVR with dial-by-extension | Almost never | Toll fraud exposure and noise |
How do I test a route and fix one that is not matching?
Check the generated dialplan first. Each DID produces an entry in ext-did, and the call enters the one that matches. Then simulate an arrival from the carrier with originate so you do not need to place a real call each time.
DID routing happens after the trunk is matched. If the log says 'No matching endpoint found', the trunk identify or Match (Permit) setting is wrong and the call never reaches ext-did.
If the trunk matched but the format is wrong, there is no single error string. Asterisk does not log 'Unknown DID'. Instead, with core set verbose 5 you see the call enter from-trunk with the dialed string, and then no Goto into a matching ext-did line. On a system with no catch-all route, FreePBX falls through to its built-in catch-all context. There you typically see a NoOp along the lines of 'Catch-All DID match - Found 12125550101 - You probably want a DID for this', followed by the call ending or an announcement. With a catch-all route defined, you see the Goto into your catch-all destination instead. Exact wording varies by FreePBX version, so test a deliberately unassigned number on your own system and note the lines you get.
| Symptom | Likely cause | Fix |
|---|---|---|
| Every number goes to one place | Only a blank DID route exists, or the first route is a catch-all | Add exact routes per DID and move the catch-all to a safe destination |
| Call ends or hits the catch-all, and the log shows a NoOp 'Catch-All DID match - Found ...' | Format mismatch: missing 1, missing +, extra digits or spaces. The number after 'Found' is what the carrier sent. | Match the INVITE user part exactly, or use a pattern |
| No matching endpoint found | Trunk identify, IP or Match (Permit) is wrong | Fix the trunk match, not the route |
| Call hangs up after a few seconds | Catch-all is Hangup, or the route was not applied | Click Apply Config and confirm with dialplan show |
| Silence after answer | NAT or RTP issue, not routing | Check external media address, local_net, and rtp set debug on |
| Route ignored for some callers | CallerID Number restricts the route, or Language is set | Clear CallerID Number and Language unless intended |
- Run core set verbose 5 and pjsip set logger on in the Asterisk console.
- Run dialplan show ext-did and look for your DID as an exten line.
- Run dialplan show 2125550101@ext-did to see the exact steps for one number.
- Place a test call to a number you have not assigned. Read the Executing lines for the dialed string and the NoOp or Goto that shows the fall-through to the catch-all.
- Place a call to an assigned number and confirm the Executing lines show the Goto into the ext-did entry for that DID.
- Confirm the trunk matched with pjsip show endpoints and pjsip show identifies.
- Call each DID from an outside phone and confirm the correct destination answers, then check Reports > CDR Reports for the expected DID.
- Turn off pjsip set logger and return verbose to a normal level.
asterisk -rvvvvv
core set verbose 5
pjsip set logger on
dialplan show ext-did
dialplan show 2125550101@ext-did
pjsip show endpoints
pjsip show identifies
# simulate the carrier arriving in from-trunk
originate Local/2125550101@from-trunk application Playback demo-congrats
pjsip set logger off
tail -f /var/log/asterisk/fullCommon questions
Can I route multiple DIDs to different extensions on one trunk?
Yes. Create one inbound route per DID and set each destination to the extension you want. All routes share the same trunk, because FreePBX decides the route from the dialed number after the trunk is matched.
What DID number format should I use in FreePBX?
Use exactly what the carrier puts in the request-URI user part. That is 10 digits, 11 digits with a leading 1, or +E.164, depending on the carrier. If it can vary, use a pattern such as _1NXXNXXXXXX or fix the format in the carrier portal.
Does a blank DID route catch everything?
A blank DID with a blank CallerID Number matches anything not matched by a more specific route. Exact and pattern routes still win, so it only handles leftovers. Point it at a safe destination.
Why do calls hit my catch-all when a route for that number exists?
The string the carrier sent does not equal the DID Number field. Check for a missing plus, a missing leading 1, spaces or extra digits, and confirm the route was applied. With core set verbose 5, the Executing [number@from-trunk:1] line, or the 'Catch-All DID match - Found ...' NoOp, shows the exact string FreePBX searched for.
Do I need to restart Asterisk after adding an inbound route?
No. Click Submit, then Apply Config, which reloads the dialplan. A full restart would drop active calls and is not needed for routes.