Howwise RSS
VoIP & Phone Systems9 min read

FreePBX Inbound Routes for Multiple DIDs: Setup and Fixes

Short answer

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.

Key takeaways
  • 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:

  1. Open the Asterisk console with asterisk -rvvvvv, then run core set verbose 5 and pjsip set logger on.
  2. Call the number from a mobile phone. In a second shell, you can run sngrep -d any port 5060 for a readable call flow.
  3. Read the first INVITE in the console and note the user part of the request-URI.
  4. 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.
  5. 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=unconditional
Tip: Only the request-URI user part (2125550101 above) is used for DID matching. The To header, P-Called-Party-ID and Diversion are informational unless you write custom dialplan to read them. Carriers that forward calls often put the original number in Diversion, while the request-URI holds your trunk number.

How 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.

  1. Description: the number plus its purpose.
  2. DID Number: exactly what the INVITE carried, with no spaces, no leading or trailing digits and no stray punctuation.
  3. CallerID Number: leave blank unless you deliberately want to match only one caller.
  4. Set Destination: extension, ring group, IVR, queue, time condition, voicemail or Terminate Call.
  5. 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.
  6. 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.

DIDPurposeDestinationDID Number fieldExtras
2125550101Main lineIVR (Main Menu)2125550101Time condition in front for after-hours
2125550102SalesRing group 6002125550102CID prefix SALES:
2125550103FaxFax extension or Fax Detect to an extension2125550103No CID prefix
2125550104Direct number, one userExtension 1052125550104Voicemail fallback set on the extension
2125550105Support, mixed formatsQueue 7002125550105 and a second route 12125550105Use the second route only if the carrier mixes formats
Tip: For open and closed routing, point the DID at a time condition, then send each branch to the IVR or voicemail. Time conditions have their own dedicated article, so build them there rather than duplicating logic in each route.

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.

PatternMatchesTypical use
_NXXNXXXXXXAny 10-digit NANP numberCarrier sends 10 digits
_1NXXNXXXXXXAny 11-digit number starting with 1Carrier sends 11 digits
_+1NXXNXXXXXXAny E.164 US numberCarrier sends +1
_X.Anything of two or more characters starting with a digitBroad catch for a trunk (use with care)
_555XFour-digit numbers 5550 to 5559Short 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 destinationUse whenRisk
Terminate Call > HangupYou own every number on the trunkCallers with a real but unassigned number hear nothing useful
Announcement 'number not in service'The carrier may deliver numbers you have not built yetLow, but keep it short
Receptionist extensionA person can triage unknownsRings a human with every wrong number
IVR with dial-by-extensionAlmost neverToll fraud exposure and noise
Warning: FreePBX also has an Invalid Destination option in Settings > General Settings that decides where calls to invalid destinations go. Separately, 'Allow Anonymous Inbound SIP Calls' controls whether unidentified SIP sources can reach your system at all. They are different settings, and turning the second on widens your exposure. Leave it off unless you need it.

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.

SymptomLikely causeFix
Every number goes to one placeOnly a blank DID route exists, or the first route is a catch-allAdd 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 foundTrunk identify, IP or Match (Permit) is wrongFix the trunk match, not the route
Call hangs up after a few secondsCatch-all is Hangup, or the route was not appliedClick Apply Config and confirm with dialplan show
Silence after answerNAT or RTP issue, not routingCheck external media address, local_net, and rtp set debug on
Route ignored for some callersCallerID Number restricts the route, or Language is setClear CallerID Number and Language unless intended
  1. Run core set verbose 5 and pjsip set logger on in the Asterisk console.
  2. Run dialplan show ext-did and look for your DID as an exten line.
  3. Run dialplan show 2125550101@ext-did to see the exact steps for one number.
  4. 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.
  5. Place a call to an assigned number and confirm the Executing lines show the Goto into the ext-did entry for that DID.
  6. Confirm the trunk matched with pjsip show endpoints and pjsip show identifies.
  7. Call each DID from an outside phone and confirm the correct destination answers, then check Reports > CDR Reports for the expected DID.
  8. 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/full
Warning: Do not build duplicate routes for every possible format without checking what arrives. One pattern route or a carrier-side format change is easier to maintain, and extra routes hide the real mismatch. Also, originate places a live call into your system, so use a harmless application like Playback and avoid pointing it at a trunk you pay per minute on.

Common 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.

Related topics:freepbxinbound routesdidasterisksip trunk