mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #5601] [Feature]: Support port ranges for inbound #3911
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#3911
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @NoanCliffe on GitHub (Jun 27, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5601
Is your feature request related to a problem?
Xray-core supports specifying a single port, a port range, or a comma-separated list in the top-level inbound
portfield:This is a common
InboundObjectfeature and is not limited to the Tunnel protocol. It can be used by applicable inbound protocols such as VLESS, VMess, Trojan, Shadowsocks, HTTP, SOCKS, WireGuard, Hysteria, and Tunnel. TUN does not use a listening port, andportis ignored when listening on a Unix domain socket.3x-ui currently treats an inbound port as a single integer. As a result, the UI, API, database model, or validation logic cannot store and generate valid Xray port-range configurations.
Tunnel is an especially useful case. When the destination port in
settings.portis omitted or set to0, Xray forwards traffic to the same destination port on which it was received:This maps local ports
10000-10100to the corresponding ports10000-10100onexample.comwithout creating 101 separate inbounds.Other protocols can also use the same inbound configuration and credentials on multiple listening ports. This provides multiple available connection ports, but it is not automatic port hopping; the client still connects to one selected port.
Describe the solution you'd like
Please support Xray's native inbound port syntax for all applicable inbound protocols:
1000010000-1010053,443,10000-10100Suggested implementation requirements:
1-65535.If changing the shared inbound data model is currently too invasive, supporting port ranges for Tunnel inbounds first would still solve the primary use case because Tunnel does not need a client share link.
Alternatives you've considered
No response
Concrete use case
No response
Mockups, screenshots, or examples
No response
Which parts of the panel would this affect?
Frontend (UI / panel pages), Backend (API endpoints, login, settings), Xray config generation
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Jun 27, 2026):
The feature request is valid and the diagnosis is accurate. Xray-core's
InboundObject.portfield accepts an integer, a range string ("10000-10100"), or a comma-separated combination ("53,443,10000-10100"), but 3x-ui currently models the inbound port as a plain Gointthroughout the stack. The following locations would all need to change to support this.Backend
internal/database/model/model.go:62— theInboundstruct declaresPort intwith the struct tagvalidate:"gte=0,lte=65535". This is the persisted DB column. It must become a type that can hold either an integer or a string such as"10000-10100".internal/xray/inbound.go:13—InboundConfig.Port intis the in-memory representation passed to Xray. Because Xray acceptsint | stringin JSON for this field, this would need to become ajson.RawMessageor a custom marshalling type so it serialises correctly (integer form for single ports, quoted string for ranges).internal/database/model/model.go:272-307—GenXrayInboundConfig()copiesi.Portdirectly intoxray.InboundConfig.Port. Once the types change, this copy/serialisation must produce the correct JSON shape.internal/web/service/port_conflict.go:161-211—checkPortConflictqueries the DB withWHERE port = ?and compares integers. For range-valued ports, exact-match lookup is not sufficient; the check must parse and compare ranges for overlap.internal/web/service/port_conflict.go:223-251—baseInboundTag,composeInboundTag, andgenerateInboundTagall callfmt.Sprintf("in-%v", port)with the port as an integer. Tag generation must handle string-form port values.internal/xray/hot_diff.go:239andinbound.go:26—Equalscomparesc.Port == other.Portas integers; would need updating for the new type.internal/xray/process.go:470— stores the API inbound port asint; not directly affected for user inbounds but worth auditing.Subscription / share-link generation (
internal/sub/)Every share-link builder (
service.go,json_service.go,clash_service.go,endpoint.go) readsinbound.Portas an integer and embeds it directly into URLs and proxy objects. For range-valued ports a decision is needed: use the first port in the range, require a separately stored "advertised port," or emit one link per port. This is the most user-visible design choice. The issue proposes defaulting to the first port, which is the least disruptive option.Frontend
frontend/src/schemas/primitives/port.ts:6—InboundPortSchema = z.number().int().min(0).max(65535). This must be extended to also accept a validated string form.frontend/src/pages/inbounds/form/InboundFormModal.tsx:609-611— the port form field is wired toInboundFormBaseSchema.shape.portandForm.useWatch('port', form)expects a number. The input element would need to switch fromInputNumbertoInput(or a custom component) to accept range strings.frontend/src/schemas/api/inbound.ts— the API response schema also referencesInboundPortSchemaand would need the same extension.Note on Hysteria2 port hopping — the existing issues about Hysteria2 UDP hop (#4166, #4789, #4960, etc.) concern a separate Hysteria2-specific mechanism (
hopInterval,hopPortsin the Hysteria stream settings). That is distinct from Xray's genericportfield feature described here.Scope summary. This is a moderate-to-large cross-cutting change. The Tunnel-first scoping suggested in the request is a reasonable staged approach to reduce risk: Tunnel inbounds do not appear in subscription links, so the share-link design decision can be deferred.
This reply was generated automatically; a maintainer may follow up.
@tengzl33t commented on GitHub (Jul 15, 2026):
@MHSanaei any ETA for this? This does seem to cause issue with Hysteria's port hopping feature.
@HamedSanaei commented on GitHub (Oct 26, 2026):
@MHSanaei I recommend closing this issue as not planned.
Although Xray supports inbound port ranges, I don't think exposing them as a general 3x-ui feature offers enough practical value to justify the complexity and maintenance cost. The panel currently uses a single numeric port across its database model, API, validation, conflict detection, hot updates, UI, and subscription generation. Supporting ranges would require substantial cross-cutting changes and introduce more edge cases, especially around overlapping listeners and selecting the port advertised to clients.
More importantly, listening on a range does not provide automatic port hopping: clients still connect to a selected port. Hysteria2's own UDP port-hopping mechanism is a separate feature and should not be confused with this request.
I recognize that a Tunnel inbound forwarding the same range of ports is a legitimate niche use case. However, for the general-purpose panel, I believe the implementation and regression risk outweigh the benefit to most operators. I'd prefer keeping the inbound model simple and stable rather than expanding this behavior across the whole stack.
My suggestion is to close #5601 as not planned, unless there is a compelling, broadly applicable use case that justifies the required architectural changes.