[GH-ISSUE #5601] [Feature]: Support port ranges for inbound #3911

Open
opened 2026-10-31 20:35:50 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @NoanCliffe on GitHub (Jun 27, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5601

Xray-core supports specifying a single port, a port range, or a comma-separated list in the top-level inbound port field:

"port": 443
"port": "10000-10100"
"port": "53,443,10000-10100"

This is a common InboundObject feature 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, and port is 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.port is omitted or set to 0, Xray forwards traffic to the same destination port on which it was received:

{
  "tag": "tunnel-range",
  "listen": "0.0.0.0",
  "port": "10000-10100",
  "protocol": "tunnel",
  "settings": {
    "address": "example.com",
    "port": 0,
    "network": "tcp,udp"
  }
}

This maps local ports 10000-10100 to the corresponding ports 10000-10100 on example.com without 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:

  • Single port: 10000
  • Port range: 10000-10100
  • Combined ports and ranges: 53,443,10000-10100

Suggested implementation requirements:

  • Allow the inbound port value to be stored as either an integer or an Xray-compatible string.
  • Validate individual ports and closed ranges within 1-65535.
  • Update duplicate-port and port-conflict detection to detect overlapping ranges.
  • Preserve compatibility with existing inbounds that store a single integer port.
  • Generate the original integer form for single ports and the string form for ranges or lists.
  • For protocols that generate share or subscription links, allow a separate advertised/connection port to be selected from the configured range, or use the first configured port by default.

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?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
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 `port` field: ```json "port": 443 ``` ```json "port": "10000-10100" ``` ```json "port": "53,443,10000-10100" ``` This is a common `InboundObject` feature 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, and `port` is 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.port` is omitted or set to `0`, Xray forwards traffic to the same destination port on which it was received: ```json { "tag": "tunnel-range", "listen": "0.0.0.0", "port": "10000-10100", "protocol": "tunnel", "settings": { "address": "example.com", "port": 0, "network": "tcp,udp" } } ``` This maps local ports `10000-10100` to the corresponding ports `10000-10100` on `example.com` without 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: - Single port: `10000` - Port range: `10000-10100` - Combined ports and ranges: `53,443,10000-10100` Suggested implementation requirements: - Allow the inbound port value to be stored as either an integer or an Xray-compatible string. - Validate individual ports and closed ranges within `1-65535`. - Update duplicate-port and port-conflict detection to detect overlapping ranges. - Preserve compatibility with existing inbounds that store a single integer port. - Generate the original integer form for single ports and the string form for ranges or lists. - For protocols that generate share or subscription links, allow a separate advertised/connection port to be selected from the configured range, or use the first configured port by default. 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? - [ ] I'd like to implement this feature myself and open a PR. - [ ] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 27, 2026):

The feature request is valid and the diagnosis is accurate. Xray-core's InboundObject.port field 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 Go int throughout the stack. The following locations would all need to change to support this.

Backend

  • internal/database/model/model.go:62 — the Inbound struct declares Port int with the struct tag validate:"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 int is the in-memory representation passed to Xray. Because Xray accepts int | string in JSON for this field, this would need to become a json.RawMessage or 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() copies i.Port directly into xray.InboundConfig.Port. Once the types change, this copy/serialisation must produce the correct JSON shape.
  • internal/web/service/port_conflict.go:161-211 — checkPortConflict queries the DB with WHERE 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, and generateInboundTag all call fmt.Sprintf("in-%v", port) with the port as an integer. Tag generation must handle string-form port values.
  • internal/xray/hot_diff.go:239 and inbound.go:26 — Equals compares c.Port == other.Port as integers; would need updating for the new type.
  • internal/xray/process.go:470 — stores the API inbound port as int; 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) reads inbound.Port as 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 to InboundFormBaseSchema.shape.port and Form.useWatch('port', form) expects a number. The input element would need to switch from InputNumber to Input (or a custom component) to accept range strings.
  • frontend/src/schemas/api/inbound.ts — the API response schema also references InboundPortSchema and 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, hopPorts in the Hysteria stream settings). That is distinct from Xray's generic port field 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.

<!-- gh-comment-id:4815730864 --> @github-actions[bot] commented on GitHub (Jun 27, 2026): The feature request is valid and the diagnosis is accurate. Xray-core's `InboundObject.port` field 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 Go `int` throughout the stack. The following locations would all need to change to support this. **Backend** - `internal/database/model/model.go:62` — the `Inbound` struct declares `Port int` with the struct tag `validate:"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 int` is the in-memory representation passed to Xray. Because Xray accepts `int | string` in JSON for this field, this would need to become a `json.RawMessage` or 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()` copies `i.Port` directly into `xray.InboundConfig.Port`. Once the types change, this copy/serialisation must produce the correct JSON shape. - `internal/web/service/port_conflict.go:161-211` — `checkPortConflict` queries the DB with `WHERE 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`, and `generateInboundTag` all call `fmt.Sprintf("in-%v", port)` with the port as an integer. Tag generation must handle string-form port values. - `internal/xray/hot_diff.go:239` and `inbound.go:26` — `Equals` compares `c.Port == other.Port` as integers; would need updating for the new type. - `internal/xray/process.go:470` — stores the API inbound port as `int`; 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`) reads `inbound.Port` as 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 to `InboundFormBaseSchema.shape.port` and `Form.useWatch('port', form)` expects a number. The input element would need to switch from `InputNumber` to `Input` (or a custom component) to accept range strings. - `frontend/src/schemas/api/inbound.ts` — the API response schema also references `InboundPortSchema` and 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`, `hopPorts` in the Hysteria stream settings). That is distinct from Xray's generic `port` field 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.*
Author
Owner

@tengzl33t commented on GitHub (Jul 15, 2026):

@MHSanaei any ETA for this? This does seem to cause issue with Hysteria's port hopping feature.

<!-- gh-comment-id:4978156323 --> @tengzl33t commented on GitHub (Jul 15, 2026): @MHSanaei any ETA for this? This does seem to cause issue with Hysteria's port hopping feature.
Author
Owner

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

<!-- gh-comment-id:6412006360 --> @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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3911
No description provided.