[GH-ISSUE #6696] [Question]: portMap does not work as expected with tunnel inbound #4470

Open
opened 2026-10-31 20:39:52 +07:00 by bsakaguchi · 1 comment
Owner

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

  • I read the Wiki and searched existing issues.
  • This is a usage question, not a bug report.
  • This question is written in English.
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 - [x] I read the [Wiki](https://github.com/MHSanaei/3x-ui/wiki) and searched [existing issues](../issues?q=is%3Aissue). - [x] This is a usage question, not a bug report. - [x] This question is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Sep 30, 2026):

portMap doesn'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 on 5523, and nothing ever looks up the "5523" key in your portMap.

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:66 has Port int \json:"port" ... validate:"gte=0,lte=65535"``
  • internal/database/model/model.go:386 (GenXrayInboundConfig) has Port: i.Port,

So your inbound becomes an Xray listener on 5522 only. A client connecting to :5523 finds nothing listening there, and the connection fails before portMap is ever used. The portMap editor in the Tunnel form (frontend/src/pages/inbounds/form/protocols/tunnel.tsx:32) just saves a Record<string, string> (frontend/src/schemas/protocols/inbound/tunnel.ts:22). It doesn't add listeners.

In Xray, portMap is meant for a tunnel inbound that receives traffic on several ports: a port list or range, or traffic sent to it by TPROXY/REDIRECT with followRedirect. 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-port port value "then we can use portMap, otherwise it's useless". The panel's port field is still a single number.

What works today

  1. To forward 5523 → 185.14.160.21:22, add a second Tunnel inbound on port 5523 with rewriteAddress: 185.14.160.21 and rewritePort: 22. It works the same way as your 5522 inbound.
  2. You can leave portMap empty on a normal single-port inbound. With one listening port, rewriteAddress/rewritePort already cover what you need.

Verdict: Not a bug (expected behaviour)

Notes for the maintainer: I couldn't read the Xray-core proxy/dokodemo source from this environment. The claim that Xray matches portMap against the port a connection arrived on comes from Xray's portMap design and from #3866, not from a file I read here. The panel side, a single integer Port, is confirmed at the lines above. Related: #3866 (multi-port inbounds, which portMap needs to be useful).

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

<!-- gh-comment-id:5909154312 --> @github-actions[bot] commented on GitHub (Sep 30, 2026): `portMap` doesn'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 on `5523`, and nothing ever looks up the `"5523"` key in your `portMap`. **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:66` has `Port int \`json:"port" ... validate:"gte=0,lte=65535"\`` - `internal/database/model/model.go:386` (`GenXrayInboundConfig`) has `Port: i.Port,` So your inbound becomes an Xray listener on `5522` only. A client connecting to `:5523` finds nothing listening there, and the connection fails before `portMap` is ever used. The `portMap` editor in the Tunnel form (`frontend/src/pages/inbounds/form/protocols/tunnel.tsx:32`) just saves a `Record<string, string>` (`frontend/src/schemas/protocols/inbound/tunnel.ts:22`). It doesn't add listeners. In Xray, `portMap` is meant for a tunnel inbound that receives traffic on several ports: a port list or range, or traffic sent to it by TPROXY/REDIRECT with `followRedirect`. 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-port `port` value "then we can use portMap, otherwise it's useless". The panel's `port` field is still a single number. **What works today** 1. To forward `5523` → `185.14.160.21:22`, add a **second** Tunnel inbound on port `5523` with `rewriteAddress: 185.14.160.21` and `rewritePort: 22`. It works the same way as your `5522` inbound. 2. You can leave `portMap` empty on a normal single-port inbound. With one listening port, `rewriteAddress`/`rewritePort` already cover what you need. Verdict: Not a bug (expected behaviour) Notes for the maintainer: I couldn't read the Xray-core `proxy/dokodemo` source from this environment. The claim that Xray matches `portMap` against the port a connection arrived on comes from Xray's `portMap` design and from #3866, not from a file I read here. The panel side, a single integer `Port`, is confirmed at the lines above. Related: #3866 (multi-port inbounds, which `portMap` needs to be useful). _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#4470
No description provided.