FreePBX Trunk Maximum Channels: What It Limits and Doesn't
The FreePBX trunk maximum channels setting caps outbound calls on that trunk using a GROUP_COUNT check, and a full trunk fails over to the next one in the route. It does not reliably limit inbound calls, so a hard inbound cap needs custom dialplan.
- The Maximum Channels field (Connectivity > Trunks > trunk > General) is enforced in the outbound trunk-dial code, and a blank value means unlimited.
- The stock outbound check counts a group named OUT_<trunkid>. Inbound calls are not in that group, so the field alone does not cap inbound calls.
- A real inbound cap needs Set(GROUP(in)=name) plus a GROUP_COUNT(name@in) test in custom dialplan, and Busy() or Congestion() to reject the surplus.
- Use separate GROUP categories (all, in, out) to build a total cap and a reserved-channel split, and keep every cap at or below the provider's contracted channels.
- A channel cap limits how much fraud can run at once but does not prevent it. Pair it with international blocking, a firewall allow-list, fail2ban and provider spend caps.
What does the FreePBX trunk maximum channels setting actually do?
The field lives at Connectivity > Trunks > (your trunk) > General tab > Maximum Channels. Blank means unlimited. A number is the most simultaneous calls FreePBX will place through that trunk.
The help text suggests it covers inbound plus outbound, but the generated dialplan only counts what the outbound code adds to the group. The macro (macro-dialout-trunk in older releases, a subroutine in newer ones) sets GROUP()=OUT_<trunkid> just before dialing and compares GROUP_COUNT(OUT_<trunkid>) with the configured number. Inbound calls arrive through from-trunk or from-pstn and never join that group.
The practical result is that the number is an outbound cap. Behavior and file layout differ between FreePBX 13, 14, 15, 16 and 17, so confirm on your own box:
# Does your version use the OUT_ group, and where is it set?
asterisk -rx "dialplan show macro-dialout-trunk" | grep -Ei "GROUP|MAXCHANS"
asterisk -rx "dialplan show sub-dialout-trunk" | grep -Ei "GROUP|MAXCHANS"
# Which macro hooks exist?
grep -rn "predial-hook" /etc/asterisk/extensions*.confWhat happens when the cap is hit, and what does the caller hear?
Outbound, a full trunk is skipped and FreePBX tries the next trunk in the outbound route. If no trunk is left, the Dial ends with CONGESTION or CHANUNAVAIL and the extension user hears reorder (fast busy). The CDR typically shows FAILED or NO ANSWER for that attempt.
Inbound, the stock behavior is nothing. The carrier's INVITE is accepted and routed normally even when you are over the limit. If you add custom code, the carrier sees whichever response you choose.
| Direction | Stock Maximum Channels | What the caller hears | Dial status or SIP code |
|---|---|---|---|
| Outbound, another trunk in route | Skips to the next trunk | Normal ringing on the next trunk | Hidden from the user |
| Outbound, no trunk left | Call fails | Fast busy (reorder) | CONGESTION or CHANUNAVAIL |
| Inbound, GUI field only | Not limited | Call is delivered | None |
| Inbound, custom Busy() | Rejected | Busy tone | 486 Busy Here |
| Inbound, custom Congestion() | Rejected | Fast busy or carrier recording | 503 Service Unavailable |
Why does the cap not stop extra calls from the carrier?
The count only covers channels that pass through FreePBX's dialplan and join the group. The carrier can send an INVITE at any time, and PJSIP will create a channel before any of your dialplan runs. The cap therefore decides what you do with the call and does not prevent the INVITE.
For a hard inbound limit you have two options. Reject in dialplan as early as possible, which is what the next section does. Or limit at the edge with the provider's channel setting or a firewall rate limit, which stops floods before Asterisk sees them.
How do I enforce a real inbound limit with GROUP_COUNT?
GROUP() tags a channel with a name, and an optional category lets one channel sit in several groups at once. GROUP(in)=prov1 puts the channel in group prov1 under category in. GROUP_COUNT(prov1@in) counts the members. The group is released automatically on hangup, so no cleanup code is needed.
Put the code in extensions_custom.conf, never in the GUI-generated files, which are overwritten on reload. Use the same group string for inbound and outbound, because the stock OUT_<trunkid> name will not match a trunk name. The example below sends the trunk's inbound calls to a wrapper context and then hands them to the normal inbound route, assuming trunk id 1 is named prov1.
- Add the wrapper context to /etc/asterisk/extensions_custom.conf (code below).
- Point the trunk's inbound context at it. For a PJSIP trunk, add context=limit-inbound under a [prov1](+) section in pjsip.endpoint_custom_post.conf. Check the endpoint's real name first with pjsip show endpoints.
- Run fwconsole reload, then place calls and watch group show channels.
; extensions_custom.conf
[limit-inbound]
exten => _X.,1,NoOp(Inbound limit check on prov1)
same => n,Set(GROUP(all)=prov1)
same => n,Set(GROUP(in)=prov1)
same => n,GotoIf($[${GROUP_COUNT(prov1@all)} > 10]?full)
same => n,Goto(from-pstn,${EXTEN},1)
same => n(full),NoOp(Trunk prov1 full: ${GROUP_COUNT(prov1@all)} channels)
same => n,Hangup(17) ; 17 = busy, sends 486
; Congestion variant: replace Hangup(17) with Hangup(34) for 503
[macro-dialout-trunk-predial-hook]
exten => s,1,GotoIf($["${DIAL_TRUNK}" = "1"]?tag:done)
same => n(tag),Set(GROUP(all)=prov1)
same => n(done),MacroExit()How do I split channels between inbound and outbound?
Use a separate category per direction plus an all category for the total. Take a provider selling 10 channels. Set Maximum Channels on the trunk to 6, which caps outbound at 6 through the OUT_ group. Total calls are capped at 10 by the all check above.
The behavior is as follows. Outbound stops at 6 and the user hears fast busy once failover is exhausted. Inbound can use the remaining 4 at any time, and can use more when outbound is quiet, up to 10 total. Call 11 inbound gets 486. An outbound attempt while 6 outbound calls are active is refused even if inbound has free channels, so the 4-channel reserve for inbound holds.
Remember that one bridged call between a trunk and an extension is one trunk channel. Counting an extension-to-extension call or a queue leg that never touches the trunk would inflate the numbers, so only tag channels that belong to the trunk.
# Group membership and counts, per category
asterisk -rx "group show channels"
asterisk -rx "group show channels in"
# Total channels, all types
asterisk -rx "core show channels count"
# Evaluate the function directly
asterisk -rx "dialplan eval function GROUP_COUNT(prov1@all)" What about PJSIP and chan_sip alternatives?
The PJSIP endpoint option device_state_busy_at sets the number of in-use channels at which the endpoint's device state turns busy. It affects state reporting, hints and queue member availability, and is not a guaranteed rejection of INVITEs, so do not rely on it as a cap.
The chan_sip call-limit option behaved similarly for peers, but chan_sip is deprecated and removed in recent Asterisk releases, and FreePBX 17 is PJSIP only. For rate rather than count, CPS (calls per second) limits belong at the provider or a firewall, since neither Asterisk nor the GUI field limits call setup rate.
The provider's own channel limit is the one that ultimately bills or blocks you, so set your cap at or below it.
| Control | Counts | Rejects extra INVITE? | Best use |
|---|---|---|---|
| Maximum Channels (GUI) | Outbound OUT_ group | Fails over outbound only | Outbound cap and failover |
| GROUP_COUNT custom dialplan | Anything you tag | Yes, with 486 or 503 | Inbound and split caps |
| device_state_busy_at | Endpoint channels | No, state only | Hints and queues |
| Provider channel limit | Provider side | Yes | Hard backstop |
| Firewall rate limit | Packets or connections | Yes, before Asterisk | Floods and scans |
How should I size the number and use it against fraud?
Start from peak simultaneous users, then add headroom for queue callers and paging, and stay at or below the contracted channels. Bandwidth is about 87 kbps per call each way for G.711 with overhead and about 31 kbps for G.729, so 10 G.711 calls need roughly 870 kbps each way.
A cap bounds how many fraudulent calls run at once but does not stop them, and a low cap can also lock out your own users while an attacker holds the channels. Layer it with these controls:
International routes blocked or behind a PIN, and per-extension outbound permissions. A firewall allow-list limiting SIP to the provider's IPs. fail2ban on registration failures. A spend cap or alert at the provider.
How do I test the cap and avoid common mistakes?
Place test calls until the cap is reached, with the CLI open, then confirm the extra call is rejected and logged. Check the FreePBX CDR (Reports > CDR Reports) for the disposition of the rejected attempt.
- Run asterisk -rvvv and place calls up to the cap, checking group show channels after each.
- Place one more call and confirm the expected result: fast busy outbound, or 486 or 503 inbound (use pjsip set logger on or sngrep to see it).
- Hang up one call and confirm the count drops and a new call succeeds.
- Check the CDR for the rejected attempt.
Common questions
Does a blank Maximum Channels field mean unlimited?
Yes. With no value, the stock check is skipped and FreePBX imposes no limit on that trunk. The provider's channel limit still applies, and exceeding it usually causes 480, 486 or 503 responses from the carrier.
Why is freepbx maximum channels not working?
The usual causes are testing with inbound calls, which the stock check never counts, or a second trunk in the route absorbing the overflow. Also confirm you are testing the right trunk id and that you ran fwconsole reload after saving.
Do stuck channels count against the limit?
Yes. A group member is released only when its channel hangs up, so a hung channel keeps the count raised. List them with core show channels verbose and clear them with channel request hangup <channel>.
Should I reject with Busy() or Congestion()?
Busy() (486) tells the carrier the call failed for that destination, and carriers usually do not retry it. Congestion() (503) may make some carriers retry an alternate route, which suits a multi-trunk carrier setup.
Can I read the count from the CLI?
Yes. Run group show channels for all members, or dialplan eval function GROUP_COUNT(prov1@all) for a single count. You can also write the count to the log with NoOp in your custom context.