[GH-ISSUE #4602] [Feature Request] Add configurable port range for P2P mode #3635

Closed
opened 2026-05-05 14:20:02 -06:00 by gitea-mirror · 6 comments
Owner

Originally created by @stleon on GitHub (Dec 20, 2024).
Original GitHub issue: https://github.com/fatedier/frp/issues/4602

Describe the feature request

I would like to request a feature that allows explicitly defining a range of ports for P2P mode.

Currently, ports are selected using:

port := rand.IntN(65535-1024) + 1024

source

This approach may result in conflicts if some ports in this range are already in use. Being able to specify a custom port range would provide more control and prevent such issues.

Why this feature should be added

  1. Avoid port conflicts: users can prevent runtime issues by limiting the range to known available ports.
  2. Flexibility: allows adaptation to specific environments or network policies.

Proposed Solution

Introduce a configuration option, such as p2pPortRange, where users can specify the allowed range of ports:

p2pPortRange = "29160-29200"

If not set, the default behavior remains unchanged (random selection from 1024–65535), ensuring backward compatibility.

Describe alternatives you've considered

No response

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @stleon on GitHub (Dec 20, 2024). Original GitHub issue: https://github.com/fatedier/frp/issues/4602 ### Describe the feature request I would like to request a feature that allows explicitly defining a range of ports for P2P mode. Currently, ports are selected using: ``` port := rand.IntN(65535-1024) + 1024 ``` [source](https://github.com/fatedier/frp/blob/dev/pkg/nathole/nathole.go#L401) This approach may result in conflicts if some ports in this range are already in use. Being able to specify a custom port range would provide more control and prevent such issues. **Why this feature should be added** 1. Avoid port conflicts: users can prevent runtime issues by limiting the range to known available ports. 2. Flexibility: allows adaptation to specific environments or network policies. **Proposed Solution** Introduce a configuration option, such as p2pPortRange, where users can specify the allowed range of ports: ``` p2pPortRange = "29160-29200" ``` If not set, the default behavior remains unchanged (random selection from 1024–65535), ensuring backward compatibility. ### Describe alternatives you've considered _No response_ ### Affected area - [X] Docs - [ ] Installation - [ ] Performance and Scalability - [ ] Security - [X] User Experience - [ ] Test and Release - [X] Developer Infrastructure - [ ] Client Plugin - [ ] Server Plugin - [ ] Extensions - [ ] Others
gitea-mirror 2026-05-05 14:20:02 -06:00
Author
Owner

@xqzr commented on GitHub (Dec 21, 2024):

这么做也许不再需要 UPnP #4112。
frpc 指定范围后,在路由器“端口映射”指定的范围,来获得“全锥 NAT(1)”。

<!-- gh-comment-id:2558220249 --> @xqzr commented on GitHub (Dec 21, 2024): 这么做**也许**不再需要 UPnP #4112。 frpc 指定范围后,在路由器“端口映射”指定的范围,来获得“全锥 NAT(1)”。
Author
Owner

@fatedier commented on GitHub (Dec 23, 2024):

I'm not quite sure what specific issue you're encountering. The code you posted is probing the port number on the peer's side. The exit port of the peer's NAT could be any arbitrary port.

<!-- gh-comment-id:2558848692 --> @fatedier commented on GitHub (Dec 23, 2024): I'm not quite sure what specific issue you're encountering. The code you posted is probing the port number on the peer's side. The exit port of the peer's NAT could be any arbitrary port.
Author
Owner

@xqzr commented on GitHub (Dec 23, 2024):

例如 XTCP 类型,在 frpc 增加一个 bindSrcPort 字段,并设置值为 3478
之后,所有的发包(STUN、数据传输...)都使用 3478 作为端口发送。

<!-- gh-comment-id:2559224282 --> @xqzr commented on GitHub (Dec 23, 2024): 例如 XTCP 类型,在 frpc **增加**一个 `bindSrcPort` 字段,并**设置**值为 `3478`。 之后,**所有**的发包(STUN、数据传输...)都使用 `3478` 作为**源**端口发送。
Author
Owner

@stleon commented on GitHub (Dec 29, 2024):

I was specifically referring to the ability to define a port range on the client side (frpc). Allowing this configuration would simplify operations in environments with restricted port access, such as when using Docker

<!-- gh-comment-id:2564839606 --> @stleon commented on GitHub (Dec 29, 2024): I was specifically referring to the ability to define a port range on the client side (frpc). Allowing this configuration would simplify operations in environments with restricted port access, such as when using Docker
Author
Owner

@Mohamezezo commented on GitHub (Jan 4, 2025):

p2pPortRange = "29160-29200"

<!-- gh-comment-id:2571341929 --> @Mohamezezo commented on GitHub (Jan 4, 2025): p2pPortRange = "29160-29200"
Author
Owner

@github-actions[bot] commented on GitHub (Jan 26, 2025):

Issues go stale after 14d of inactivity. Stale issues rot after an additional 3d of inactivity and eventually close.

<!-- gh-comment-id:2614151754 --> @github-actions[bot] commented on GitHub (Jan 26, 2025): Issues go stale after 14d of inactivity. Stale issues rot after an additional 3d of inactivity and eventually close.
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: github-starred/frp#3635
No description provided.