[GH-ISSUE #4993] [Bug]: Port hopping #3512

Closed
opened 2026-10-31 20:32:57 +07:00 by bsakaguchi · 1 comment
Owner

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

Describe the bug

Port hopping only works if I manually apply the NAT routing rule via SSH:
iptables -t nat -A PREROUTING -p udp --dport 20000:50000 -j REDIRECT --to-port 443
It's not viable to manually run this command every time the node restarts or updates. This is definitely a bug where the panel fails to auto-configure the iptables rules.

How to reproduce the problem

Set up a new Hysteria2 node with port hopping enabled.

Expected behavior

No response

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

v3.2.8

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

debian12

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 @lxhifu on GitHub (Jun 6, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4993 ### Describe the bug Port hopping only works if I manually apply the NAT routing rule via SSH: iptables -t nat -A PREROUTING -p udp --dport 20000:50000 -j REDIRECT --to-port 443 It's not viable to manually run this command every time the node restarts or updates. This is definitely a bug where the panel fails to auto-configure the iptables rules. ### How to reproduce the problem Set up a new Hysteria2 node with port hopping enabled. ### Expected behavior _No response_ ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version v3.2.8 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system debian12 ### 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:32:57 +07:00
Author
Owner

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

Thanks for the follow-up, @lxhifu, and for confirming the manual command works. This ties directly to the prior investigations in #4974 and #4992, so let me summarise the full picture and give you a persistence solution.

What the panel does (and does not) do for port hopping

When you enable UDP Hop in Inbound → Stream → FinalMask → QUIC Params, 3x-ui:

  1. Stores the range (e.g. 20000-50000) in streamSettings.finalmask.quicParams.udpHop.ports in the database.
  2. Emits it as mport=20000-50000 in subscription links — this tells the client which port range to hop across.
  3. Passes the full streamSettings (including finalmask) to Xray-core.

What it does not do: create any iptables/ip6tables NAT rules on the server. There is no such code anywhere in the backend, the Xray process manager, or the install/update scripts. Xray-core itself also only binds to the single configured UDP port; it does not open the hop range.

So the server-side DNAT rule is always required for port hopping to work, and right now it must be set up manually.

Making the rule persistent across reboots

The simplest approach on Debian 12 is iptables-persistent:

# Apply the rules (replace 20000:50000 and 443 with your actual hop range and inbound port)
iptables -t nat -A PREROUTING -p udp --dport 20000:50000 -j REDIRECT --to-port 443
ip6tables -t nat -A PREROUTING -p udp --dport 20000:50000 -j REDIRECT --to-port 443

# Persist them across reboots
apt-get install -y iptables-persistent
netfilter-persistent save

After this, iptables-persistent restores the saved rules during boot automatically — before the network comes up — so the hop range is always redirected even after a VPS restart or a systemctl restart x-ui.

Why this is an enhancement, not a regression

Checked the code between v3.2.7 and v3.2.8: there are no changes to inbound config generation for Hysteria2, and the Xray-core version is identical in both releases. The iptables auto-configuration was never implemented. What changed in v3.2.7 was that the panel started emitting mport in subscription links (PR #4789), which means clients started actually using the hop range — and failing to connect, because the server-side NAT rules were not in place.

Feature request

Auto-configuring the DNAT rules when UDP hop is enabled is a valid request — labelled enhancement accordingly. A proper implementation would need to detect hop-enabled inbounds on startup and apply (and clean up) the matching iptables/ip6tables rules, similar to how fail2ban rules are managed today.

For now the iptables-persistent workaround above should keep you running without manual intervention on every restart.

<!-- gh-comment-id:4636895574 --> @github-actions[bot] commented on GitHub (Jun 6, 2026): Thanks for the follow-up, @lxhifu, and for confirming the manual command works. This ties directly to the prior investigations in #4974 and #4992, so let me summarise the full picture and give you a persistence solution. ## What the panel does (and does not) do for port hopping When you enable **UDP Hop** in Inbound → Stream → FinalMask → QUIC Params, 3x-ui: 1. Stores the range (e.g. `20000-50000`) in `streamSettings.finalmask.quicParams.udpHop.ports` in the database. 2. Emits it as `mport=20000-50000` in subscription links — this tells the **client** which port range to hop across. 3. Passes the full `streamSettings` (including `finalmask`) to Xray-core. **What it does not do:** create any `iptables`/`ip6tables` NAT rules on the server. There is no such code anywhere in the backend, the Xray process manager, or the install/update scripts. Xray-core itself also only binds to the single configured UDP port; it does not open the hop range. So the server-side DNAT rule is always required for port hopping to work, and right now it must be set up manually. ## Making the rule persistent across reboots The simplest approach on Debian 12 is `iptables-persistent`: ```bash # Apply the rules (replace 20000:50000 and 443 with your actual hop range and inbound port) iptables -t nat -A PREROUTING -p udp --dport 20000:50000 -j REDIRECT --to-port 443 ip6tables -t nat -A PREROUTING -p udp --dport 20000:50000 -j REDIRECT --to-port 443 # Persist them across reboots apt-get install -y iptables-persistent netfilter-persistent save ``` After this, `iptables-persistent` restores the saved rules during boot automatically — before the network comes up — so the hop range is always redirected even after a VPS restart or a `systemctl restart x-ui`. ## Why this is an enhancement, not a regression Checked the code between v3.2.7 and v3.2.8: there are no changes to inbound config generation for Hysteria2, and the Xray-core version is identical in both releases. The iptables auto-configuration was never implemented. What changed in v3.2.7 was that the panel started emitting `mport` in subscription links (PR #4789), which means clients started actually using the hop range — and failing to connect, because the server-side NAT rules were not in place. ## Feature request Auto-configuring the DNAT rules when UDP hop is enabled is a valid request — labelled `enhancement` accordingly. A proper implementation would need to detect hop-enabled inbounds on startup and apply (and clean up) the matching `iptables`/`ip6tables` rules, similar to how fail2ban rules are managed today. For now the `iptables-persistent` workaround above should keep you running without manual intervention on every restart.
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#3512
No description provided.