[GH-ISSUE #5785] [Bug]: Duplication of WireGuard client IP address when using multiple inbounds #4023

Closed
opened 2026-10-31 20:36:36 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @AndreyOkh on GitHub (Jul 4, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5785

Describe the bug

If a client is added to multiple WireGuard inbound configurations, or if one WireGuard configuration is swapped for another, different clients might end up with the same IP address. This can lead to traffic routing issues.

How to reproduce the problem

  1. Create inbound WireGuard configurations "a" and "b".
  2. Create "user1" and link it to inbound "a".
  3. Create "user2" and link it to inbound "b".
  4. Change the inbound setting for "user1" from "a" to "b".
  5. Both clients will have the same IP address and will not be able to operate simultaneously.

Expected behavior

A unique IP address must be assigned to each individual WireGuard inbound connection.

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.4.2

Xray-core version

26.6.27

How did you install 3x-ui?

install.sh script

Operating system

Debian 12

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @AndreyOkh on GitHub (Jul 4, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5785 ### Describe the bug If a client is added to multiple WireGuard inbound configurations, or if one WireGuard configuration is swapped for another, different clients might end up with the same IP address. This can lead to traffic routing issues. ### How to reproduce the problem 1. Create inbound WireGuard configurations "a" and "b". 2. Create "user1" and link it to inbound "a". 3. Create "user2" and link it to inbound "b". 4. Change the inbound setting for "user1" from "a" to "b". 5. Both clients will have the same IP address and will not be able to operate simultaneously. ### Expected behavior A unique IP address must be assigned to each individual WireGuard inbound connection. ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.4.2 ### Xray-core version 26.6.27 ### How did you install 3x-ui? install.sh script ### Operating system Debian 12 ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:36:36 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jul 4, 2026):

Confirmed in the code. There are two separate issues at play, both in internal/web/service/client_wireguard.go.

Root cause

WireGuard address allocation is scoped per-inbound only. defaultWireguardClients builds its "used" address set from inboundSvc.GetClients(oldInbound) — the peers already on the one inbound being written to (internal/web/service/client_inbound_apply.go, the AddInboundClient WireGuard branch). It never looks at any other inbound. Since every new WireGuard inbound defaults to the same 10.0.0.0/24 subnet (defaultWireguardBase in client_wireguard.go) unless you pick a different one, the first client added to inbound "a" and the first client added to inbound "b" each independently get 10.0.0.2/32 — that alone is not harmful while the two clients stay on separate inbounds (separate tunnels), but it sets up the collision.

The actual duplicate-in-one-inbound bug happens at step 4. In the panel, changing a clients inbound assignment (the inbound multi-select in the client editor) is implemented as attach-to-new plus detach-from-old (ClientService.Attach then AddInboundClient, driven from frontend/src/pages/clients/ClientsPage.tsx), not a fresh allocation. A clients WireGuard keys and AllowedIPs live on the clients single shared record (ClientRecord.AllowedIPs / ToClient() in internal/database/model/model.go) and are carried forward unchanged on attach. In the 3.4.2 source, defaultWireguardClients only allocates a new address if len(c.AllowedIPs) == 0; when the client already has an address (as user1 does after being created on inbound "a"), that branch is a no-op — there is no check against the peers already present on the inbound being attached to. So user1s 10.0.0.2/32 is written straight into inbound "bs" peer list even though user2 already holds it there, with no error and no dedup.

Status

This has already been addressed in the repository, but after v3.4.2 was tagged (2026-06-29): commit 64c30603 ("feat(wireguard): make client allowedIPs editable with validation", 2026-07-02) adds an explicit collision check (wireguardAllowedIPsCollision) so attaching or moving a client whose stored AllowedIPs collides with another peer already on the target inbound is now rejected with an error instead of silently applied. It is not part of any tagged release yet.

Workaround on 3.4.2

  • Give each WireGuard inbound its own non-overlapping subnet in its settings, so a client carried over from one inbound can never coincide with a peer already on another.
  • For clients that already collide, open the affected inbounds Advanced -> Settings (raw JSON) editor and manually change one of the colliding settings.clients[].allowedIPs entries to a free /32 address in that inbounds subnet, then save.

This reply was generated automatically by an AI agent; a maintainer may follow up.

<!-- gh-comment-id:4881949643 --> @github-actions[bot] commented on GitHub (Jul 4, 2026): Confirmed in the code. There are two separate issues at play, both in `internal/web/service/client_wireguard.go`. **Root cause** WireGuard address allocation is scoped per-inbound only. `defaultWireguardClients` builds its "used" address set from `inboundSvc.GetClients(oldInbound)` — the peers already on the *one* inbound being written to (`internal/web/service/client_inbound_apply.go`, the `AddInboundClient` WireGuard branch). It never looks at any other inbound. Since every new WireGuard inbound defaults to the same `10.0.0.0/24` subnet (`defaultWireguardBase` in `client_wireguard.go`) unless you pick a different one, the *first* client added to inbound "a" and the *first* client added to inbound "b" each independently get `10.0.0.2/32` — that alone is not harmful while the two clients stay on separate inbounds (separate tunnels), but it sets up the collision. The actual duplicate-in-one-inbound bug happens at step 4. In the panel, changing a clients inbound assignment (the inbound multi-select in the client editor) is implemented as attach-to-new plus detach-from-old (`ClientService.Attach` then `AddInboundClient`, driven from `frontend/src/pages/clients/ClientsPage.tsx`), not a fresh allocation. A clients WireGuard keys and `AllowedIPs` live on the clients single shared record (`ClientRecord.AllowedIPs` / `ToClient()` in `internal/database/model/model.go`) and are carried forward unchanged on attach. In the 3.4.2 source, `defaultWireguardClients` only allocates a new address `if len(c.AllowedIPs) == 0`; when the client already has an address (as user1 does after being created on inbound "a"), that branch is a no-op — there is no check against the peers already present on the inbound being attached to. So user1s `10.0.0.2/32` is written straight into inbound "bs" peer list even though user2 already holds it there, with no error and no dedup. **Status** This has already been addressed in the repository, but after v3.4.2 was tagged (2026-06-29): commit `64c30603` ("feat(wireguard): make client allowedIPs editable with validation", 2026-07-02) adds an explicit collision check (`wireguardAllowedIPsCollision`) so attaching or moving a client whose stored `AllowedIPs` collides with another peer already on the target inbound is now rejected with an error instead of silently applied. It is not part of any tagged release yet. **Workaround on 3.4.2** - Give each WireGuard inbound its own non-overlapping subnet in its settings, so a client carried over from one inbound can never coincide with a peer already on another. - For clients that already collide, open the affected inbounds Advanced -> Settings (raw JSON) editor and manually change one of the colliding `settings.clients[].allowedIPs` entries to a free /32 address in that inbounds subnet, then save. *This reply was generated automatically by an AI agent; a maintainer may follow up.*
Author
Owner

@MHSanaei commented on GitHub (Jul 5, 2026):

This is fixed on main by 64c30603 (feat(wireguard): make client allowedIPs editable with validation), which landed after v3.4.2 was tagged — so it will ship in the next release.

What changed:

  • Attaching or moving a client to a WireGuard inbound where its stored address is already held by another peer is now rejected with an explicit error (wireguard: allowedIPs entry already used by another client: <addr>) instead of silently writing a duplicate peer address. The move aborts before the client is detached from the original inbound, so nothing is left half-moved.
  • The client's Allowed IPs field is now editable in the client editor (with the same validation), so you can assign a free address in the target inbound's subnet and then move the client.

Until the next release, on 3.4.2:

  • Give each WireGuard inbound its own non-overlapping subnet so carried-over addresses can't collide.
  • For clients that already collide, edit one of the duplicate allowedIPs entries to a free /32 via the inbound's raw settings JSON.

Note the address is deliberately not silently re-allocated on move: a client's WireGuard address is part of the config already deployed on the device, so changing it implicitly would break the existing tunnel without warning. The explicit error + editable field keeps that decision with you.

<!-- gh-comment-id:4887405106 --> @MHSanaei commented on GitHub (Jul 5, 2026): This is fixed on `main` by 64c30603 (`feat(wireguard): make client allowedIPs editable with validation`), which landed after v3.4.2 was tagged — so it will ship in the next release. What changed: - Attaching or moving a client to a WireGuard inbound where its stored address is already held by another peer is now **rejected with an explicit error** (`wireguard: allowedIPs entry already used by another client: <addr>`) instead of silently writing a duplicate peer address. The move aborts before the client is detached from the original inbound, so nothing is left half-moved. - The client's Allowed IPs field is now **editable in the client editor** (with the same validation), so you can assign a free address in the target inbound's subnet and then move the client. Until the next release, on 3.4.2: - Give each WireGuard inbound its own non-overlapping subnet so carried-over addresses can't collide. - For clients that already collide, edit one of the duplicate `allowedIPs` entries to a free /32 via the inbound's raw settings JSON. Note the address is deliberately *not* silently re-allocated on move: a client's WireGuard address is part of the config already deployed on the device, so changing it implicitly would break the existing tunnel without warning. The explicit error + editable field keeps that decision with you.
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#4023
No description provided.