mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6696] [Question]: portMap does not work as expected with tunnel inbound #4470
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#4470
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 @mohsenrahmani145 on GitHub (Sep 30, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6696
What are you trying to do?
Hi,
I’m experiencing an issue with the portMap feature when using the tunnel protocol.
I have a tunnel inbound listening on port 5522. When I use rewriteAddress and rewritePort, the connection works correctly and traffic is successfully forwarded to the destination.
However, when I try to use portMap to forward a different incoming port (5523) to the same destination, the connection does not work.
Configuration
{
"listen": "",
"port": 5522,
"protocol": "tunnel",
"tag": "in-5522-tcpudp",
"settings": {
"rewriteAddress": "185.14.160.21",
"rewritePort": 22,
"portMap": {
"5523": "185.14.160.21:22"
},
"allowedNetwork": "tcp,udp",
"followRedirect": false
},
"sniffing": {
"enabled": false
},
"streamSettings": {
"security": "none"
}
}
Expected behavior
My understanding is that the following configuration:
"portMap": {
"5523": "185.14.160.21:22"
}
should map incoming connections on port 5523 to:
185.14.160.21:22
In other words:
Client → :5523 → 185.14.160.21:22
Actual behavior
The rewriteAddress / rewritePort configuration works when connecting through the configured inbound port:
Client → :5522 → 185.14.160.21:22
However, the portMap configuration does not appear to work for port 5523:
Client → :5523 → [connection fails]
Question
Is portMap supported for the tunnel inbound?
If it is supported, could you please clarify the correct configuration or whether an additional setting is required?
Also, does portMap map additional listening ports to destinations, or is it intended for a different purpose within the tunnel protocol?
Thanks!
What have you already tried?
No response
3x-ui version
3.8.5
How did you install 3x-ui?
install.sh script
Operating system
No response
Screenshots or config snippets
No response
Before submitting
@github-actions[bot] commented on GitHub (Sep 30, 2026):
portMapdoesn't open extra listening ports. It only chooses the destination for connections that reach the inbound on a port the inbound already listens on. A 3x-ui inbound listens on exactly one port, so Xray never listens on5523, and nothing ever looks up the"5523"key in yourportMap.Why 5523 fails
The panel stores an inbound's port as a single integer and passes it to Xray unchanged:
internal/database/model/model.go:66hasPort int \json:"port" ... validate:"gte=0,lte=65535"``internal/database/model/model.go:386(GenXrayInboundConfig) hasPort: i.Port,So your inbound becomes an Xray listener on
5522only. A client connecting to:5523finds nothing listening there, and the connection fails beforeportMapis ever used. TheportMapeditor in the Tunnel form (frontend/src/pages/inbounds/form/protocols/tunnel.tsx:32) just saves aRecord<string, string>(frontend/src/schemas/protocols/inbound/tunnel.ts:22). It doesn't add listeners.In Xray,
portMapis meant for a tunnel inbound that receives traffic on several ports: a port list or range, or traffic sent to it by TPROXY/REDIRECT withfollowRedirect. It picks a destination based on the port each connection arrived on. #3866 made the same point: Xray PR XTLS/Xray-core#4968 needs a multi-portportvalue "then we can use portMap, otherwise it's useless". The panel'sportfield is still a single number.What works today
5523→185.14.160.21:22, add a second Tunnel inbound on port5523withrewriteAddress: 185.14.160.21andrewritePort: 22. It works the same way as your5522inbound.portMapempty on a normal single-port inbound. With one listening port,rewriteAddress/rewritePortalready cover what you need.Verdict: Not a bug (expected behaviour)
Notes for the maintainer: I couldn't read the Xray-core
proxy/dokodemosource from this environment. The claim that Xray matchesportMapagainst the port a connection arrived on comes from Xray'sportMapdesign and from #3866, not from a file I read here. The panel side, a single integerPort, is confirmed at the lines above. Related: #3866 (multi-port inbounds, whichportMapneeds to be useful).This reply was generated automatically; a maintainer may follow up.