mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #4993] [Bug]: Port hopping #3512
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#3512
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 @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
@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:
20000-50000) instreamSettings.finalmask.quicParams.udpHop.portsin the database.mport=20000-50000in subscription links — this tells the client which port range to hop across.streamSettings(includingfinalmask) to Xray-core.What it does not do: create any
iptables/ip6tablesNAT 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:After this,
iptables-persistentrestores the saved rules during boot automatically — before the network comes up — so the hop range is always redirected even after a VPS restart or asystemctl 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
mportin 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
enhancementaccordingly. A proper implementation would need to detect hop-enabled inbounds on startup and apply (and clean up) the matchingiptables/ip6tablesrules, similar to how fail2ban rules are managed today.For now the
iptables-persistentworkaround above should keep you running without manual intervention on every restart.