[GH-ISSUE #7101] [Feature]: Master-controlled global IP limit across all nodes #6653

Open
opened 2026-11-08 06:59:28 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @xAlokyx on GitHub (Nov 7, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/7101

In my multi-node setup, the IP limit configured on the master does not effectively restrict concurrent use of the same subscription across different nodes.

For example, one subscriber has access to three node servers and an IP limit of 1 configured on the master. Three devices with three different public IP addresses can connect simultaneously, one device to each node, and all three connections remain active without the master enforcing the limit.

The required limit is one concurrent unique public IP across the entire subscription, regardless of which node is used. Adding nodes should not multiply the subscriber's effective IP allowance. This is an IP-address limit, not an exact device count: multiple devices behind the same public IP may share one IP slot.

Describe the solution you'd like

Please provide reliable master-controlled enforcement of a single global IP limit per client across the master and every assigned node.

  • Configure the client IP limit once on the master.
  • Collect current client IP observations from all assigned nodes and combine them by the same client identity. Count each unique public IP once, even if it connects to multiple nodes.
  • Let the master decide when the combined limit is exceeded and which IPs should be blocked according to the configured enforcement policy.
  • Have the master distribute those ban/unban decisions to the nodes, and ensure the nodes actually enforce them. A firewall ban only on the master cannot block traffic terminating on a remote node.
  • Disconnect or block excess IPs and prevent bypassing the decision by switching to another node.
  • Expire inactive observations appropriately, synchronize ban expiry/unbans, and reconcile decisions when a node reconnects.
  • Show the aggregated active IP count and enforcement status on the master, including node synchronization failures.

I understand that the current project already has cross-node IP synchronization and cluster-wide counting logic. This request focuses on making end-to-end master-controlled enforcement work for the scenario above. If this behavior is already supported, please clarify the required master/node settings and prerequisites so this can be diagnosed as a configuration problem or a bug.

Alternatives you've considered

Independent per-node limits do not meet this requirement: with three nodes and a limit of 1 on each, the same subscription could still be used from three different IPs at the same time. Manual monitoring and manually repeating bans on every node are difficult to maintain.

Concrete use case

  1. Create one client/subscription on the master and assign three node servers.
  2. Set the client IP limit to 1 on the master.
  3. Connect device A from public IP A to node 1.
  4. Connect device B from public IP B to node 2.
  5. Connect device C from public IP C to node 3, keeping the earlier connections active.

Observed in my setup: all three different IPs remain connected.

Expected: the master evaluates the combined three-IP usage against the single global limit of 1 and coordinates enforcement on the nodes. Only one unique public IP should remain permitted under the configured policy; moving the excess connections to another assigned node must not bypass the limit.

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

Multi-node (sub-nodes)

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 @xAlokyx on GitHub (Nov 7, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/7101 ### Is your feature request related to a problem? In my multi-node setup, the IP limit configured on the master does not effectively restrict concurrent use of the same subscription across different nodes. For example, one subscriber has access to three node servers and an IP limit of 1 configured on the master. Three devices with three different public IP addresses can connect simultaneously, one device to each node, and all three connections remain active without the master enforcing the limit. The required limit is one concurrent unique public IP across the entire subscription, regardless of which node is used. Adding nodes should not multiply the subscriber's effective IP allowance. This is an IP-address limit, not an exact device count: multiple devices behind the same public IP may share one IP slot. ### Describe the solution you'd like Please provide reliable master-controlled enforcement of a single global IP limit per client across the master and every assigned node. - Configure the client IP limit once on the master. - Collect current client IP observations from all assigned nodes and combine them by the same client identity. Count each unique public IP once, even if it connects to multiple nodes. - Let the master decide when the combined limit is exceeded and which IPs should be blocked according to the configured enforcement policy. - Have the master distribute those ban/unban decisions to the nodes, and ensure the nodes actually enforce them. A firewall ban only on the master cannot block traffic terminating on a remote node. - Disconnect or block excess IPs and prevent bypassing the decision by switching to another node. - Expire inactive observations appropriately, synchronize ban expiry/unbans, and reconcile decisions when a node reconnects. - Show the aggregated active IP count and enforcement status on the master, including node synchronization failures. I understand that the current project already has cross-node IP synchronization and cluster-wide counting logic. This request focuses on making end-to-end master-controlled enforcement work for the scenario above. If this behavior is already supported, please clarify the required master/node settings and prerequisites so this can be diagnosed as a configuration problem or a bug. ### Alternatives you've considered Independent per-node limits do not meet this requirement: with three nodes and a limit of 1 on each, the same subscription could still be used from three different IPs at the same time. Manual monitoring and manually repeating bans on every node are difficult to maintain. ### Concrete use case 1. Create one client/subscription on the master and assign three node servers. 2. Set the client IP limit to 1 on the master. 3. Connect device A from public IP A to node 1. 4. Connect device B from public IP B to node 2. 5. Connect device C from public IP C to node 3, keeping the earlier connections active. Observed in my setup: all three different IPs remain connected. Expected: the master evaluates the combined three-IP usage against the single global limit of 1 and coordinates enforcement on the nodes. Only one unique public IP should remain permitted under the configured policy; moving the excess connections to another assigned node must not bypass the limit. ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? Multi-node (sub-nodes) ### 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 (Nov 7, 2026):

Most of this already exists on the default branch, but it is not a central "master decides, nodes obey" design. Each node runs its own IP-limit job and counts the other nodes' recent IPs toward the client's limit. Every node has to be set up to enforce it, though, and there is one gap in the code that could explain your three surviving connections. I need a few details from your setup (listed at the end) to tell which of these you hit.

How the cluster-wide limit works today

  1. Collection, every 10 s on every panel. CheckClientIpJob (internal/web/job/check_client_ip_job.go, scheduled in internal/web/web.go:360) reads the live IPs for each client from Xray's online-stats API and writes them to that panel's inbound_client_ips row.
  2. Master ⇄ node exchange, every 10 s per node. node_traffic_sync_job.go:453-470 pulls each node's rows (FetchAllClientIps → MergeNodeClientIps), merges them into the master's row for the same email, then pushes the merged rows back to that node (GetNodeInboundClientIps → PushAllClientIps). On the node they land in MergeInboundClientIps (internal/web/controller/server.go:544-551). After this step every node holds the union of IPs for the clients it hosts.
  3. Enforcement, locally on each node. partitionLiveIps (check_client_ip_job.go) counts an IP as live if it is connected to this node or was seen anywhere in the last 120 s:
    // Recent remote observations count toward the cluster-wide limit.
    if observedThisScan[ip] || now-ts < 120 {
    
    selectIpsToBan then keeps the newest limitIp IPs and bans the older ones. The ban goes through that node's own fail2ban (publishBans → 3x-ipl log) plus a temporary Xray disconnect (disconnectClientTemporarily). Every node bans the same older IPs, including ones not connected to it, so moving a banned IP to another node doesn't get around the limit.

In your example (A, then B, then C, limit 1), each node should end up banning A and B, and only C stays connected.

Prerequisites on every node, not just the master

  • fail2ban installed and the IP-limit jail set up on each node (x-ui menu → 22. IP Limit Management). On Linux, resolveEnforce turns enforcement off when the binary is missing:
    if hasLimit && needsBinary && !f2bInstalled {
        return false
    }
    
    The job then only records IPs and bans nothing.
  • XUI_ENABLE_FAIL2BAN must not be false in the node's service environment. false turns off enforcement and leaves only tracking (#6722).
  • The node must be running a build that has the IP sync (GET/POST /panel/api/server/clientIps), and the master must reach it. Failures show in the master log as node traffic sync: fetch client ips from <node> failed or push client ips to <node> failed.
  • The client's limitIp has to reach the node. hasLimitIp reads the node's own clients.limit_ip.

A gap that could defeat it even when set up correctly (inference, not confirmed)

The timestamp stored in the shared row is Xray's lastSeen for the IP, not the time of the scan. The code says this value can be old for a connection that is still open (processObserved: "A live connection's lastSeen may be its old start time."), because the core refreshes it only on a new dispatch (selectAdvancedSinceLastBan). The local node always counts its own connection. The other nodes get that old timestamp through the master, and once it is older than 120 s, partitionLiveIps puts the IP in the historical bucket and leaves it out of the count.

So a device that keeps one long connection open (mux, a single gRPC/XHTTP stream) can stop counting on the other nodes. The fresh "seen now" stamp the job does write (recordLocalAttribution → node_client_ips) is only used to show which node an IP is on. Enforcement never reads it. Whether this is what happened in your case depends on how your clients connect, which I can't see from here.

What I could not confirm

The issue also asks for an aggregated count and enforcement/sync-failure status on the master's UI, and for ban/unban decisions made centrally. Today bans are decided per node by the logic above. I did not find a central ban list sent to nodes. That part is a real feature request.

Please reply with

  1. The 3x-ui version on the master and on each node (they can differ).
  2. On each node: the output of fail2ban-client status 3x-ipl, and whether XUI_ENABLE_FAIL2BAN is set in the service environment.
  3. Any [LIMIT_IP] / [LimitIP] lines from a node's log while A, B and C are connected, and any node traffic sync: ... client ips warnings from the master's log.
  4. Whether the test devices use mux or a single long transport such as gRPC or XHTTP. That tells us whether the 120 s window above is the cause.

Related: #6587 (an earlier lost-update bug in this same shared row, now closed).

Verdict: Insufficient information. Cross-node enforcement already exists, but whether your setup is a configuration problem or the lastSeen gap above depends on the details requested.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:6714399964 --> @github-actions[bot] commented on GitHub (Nov 7, 2026): Most of this already exists on the default branch, but it is not a central "master decides, nodes obey" design. Each node runs its own IP-limit job and counts the other nodes' recent IPs toward the client's limit. Every node has to be set up to enforce it, though, and there is one gap in the code that could explain your three surviving connections. I need a few details from your setup (listed at the end) to tell which of these you hit. ### How the cluster-wide limit works today 1. **Collection, every 10 s on every panel.** `CheckClientIpJob` (`internal/web/job/check_client_ip_job.go`, scheduled in `internal/web/web.go:360`) reads the live IPs for each client from Xray's online-stats API and writes them to that panel's `inbound_client_ips` row. 2. **Master ⇄ node exchange, every 10 s per node.** `node_traffic_sync_job.go:453-470` pulls each node's rows (`FetchAllClientIps` → `MergeNodeClientIps`), merges them into the master's row for the same email, then pushes the merged rows back to that node (`GetNodeInboundClientIps` → `PushAllClientIps`). On the node they land in `MergeInboundClientIps` (`internal/web/controller/server.go:544-551`). After this step every node holds the union of IPs for the clients it hosts. 3. **Enforcement, locally on each node.** `partitionLiveIps` (`check_client_ip_job.go`) counts an IP as live if it is connected to this node *or* was seen anywhere in the last 120 s: ```go // Recent remote observations count toward the cluster-wide limit. if observedThisScan[ip] || now-ts < 120 { ``` `selectIpsToBan` then keeps the newest `limitIp` IPs and bans the older ones. The ban goes through that node's own fail2ban (`publishBans` → `3x-ipl` log) plus a temporary Xray disconnect (`disconnectClientTemporarily`). Every node bans the same older IPs, including ones not connected to it, so moving a banned IP to another node doesn't get around the limit. In your example (A, then B, then C, limit 1), each node should end up banning A and B, and only C stays connected. ### Prerequisites on every node, not just the master - **fail2ban installed and the IP-limit jail set up on each node** (`x-ui` menu → `22. IP Limit Management`). On Linux, `resolveEnforce` turns enforcement off when the binary is missing: ```go if hasLimit && needsBinary && !f2bInstalled { return false } ``` The job then only records IPs and bans nothing. - **`XUI_ENABLE_FAIL2BAN` must not be `false`** in the node's service environment. `false` turns off enforcement and leaves only tracking (#6722). - **The node must be running a build that has the IP sync** (`GET/POST /panel/api/server/clientIps`), and the master must reach it. Failures show in the master log as `node traffic sync: fetch client ips from <node> failed` or `push client ips to <node> failed`. - The client's `limitIp` has to reach the node. `hasLimitIp` reads the node's own `clients.limit_ip`. ### A gap that could defeat it even when set up correctly (inference, not confirmed) The timestamp stored in the shared row is Xray's `lastSeen` for the IP, not the time of the scan. The code says this value can be old for a connection that is still open (`processObserved`: *"A live connection's lastSeen may be its old start time."*), because the core refreshes it only on a new dispatch (`selectAdvancedSinceLastBan`). The local node always counts its own connection. The *other* nodes get that old timestamp through the master, and once it is older than 120 s, `partitionLiveIps` puts the IP in the historical bucket and leaves it out of the count. So a device that keeps one long connection open (mux, a single gRPC/XHTTP stream) can stop counting on the other nodes. The fresh "seen now" stamp the job does write (`recordLocalAttribution` → `node_client_ips`) is only used to show which node an IP is on. Enforcement never reads it. Whether this is what happened in your case depends on how your clients connect, which I can't see from here. ### What I could not confirm The issue also asks for an aggregated count and enforcement/sync-failure status on the master's UI, and for ban/unban decisions made centrally. Today bans are decided per node by the logic above. I did not find a central ban list sent to nodes. That part is a real feature request. ### Please reply with 1. The 3x-ui version on the master **and** on each node (they can differ). 2. On each node: the output of `fail2ban-client status 3x-ipl`, and whether `XUI_ENABLE_FAIL2BAN` is set in the service environment. 3. Any `[LIMIT_IP]` / `[LimitIP]` lines from a node's log while A, B and C are connected, and any `node traffic sync: ... client ips` warnings from the master's log. 4. Whether the test devices use mux or a single long transport such as gRPC or XHTTP. That tells us whether the 120 s window above is the cause. Related: #6587 (an earlier lost-update bug in this same shared row, now closed). Verdict: Insufficient information. Cross-node enforcement already exists, but whether your setup is a configuration problem or the lastSeen gap above depends on the details requested. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
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#6653
No description provided.