[GH-ISSUE #1108] frpc在连接服务器的时候指定某个端口作为socket的通信端口? #865

Closed
opened 2026-05-05 12:33:03 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @tun100 on GitHub (Mar 3, 2019).
Original GitHub issue: https://github.com/fatedier/frp/issues/1108

Issue is only used for submiting bug report and documents typo. If there are same issues or answers can be found in documents, we will close it directly.
(为了节约时间,提高处理问题的效率,不按照格式填写的 issue 将会直接关闭。)

Use the commands below to provide key information from your environment:
You do NOT have to include this information if this is a FEATURE REQUEST

What version of frp are you using (./frpc -v or ./frps -v)?
服务器端和客户端都是 0.20.0

What operating system and processor architecture are you using (go env)?
没有开发,只是在使用

Configures you used:
你好!感谢开发了如此好用便捷的程序!
我的客户端是Ubuntu 16.04,frp版本都是0.20.0
因为网络设备之间环境复杂,服务器端和客户端都能互相ping通和访问端口,我需要使用iptables防火墙来禁止frp服务器端访问我笔记本的端口,只开放一些端口供frp程序使用。
我禁止的命令如下:
1, iptables -I INPUT -s ${IP} -j DROP
2, iptables -I INPUT -s ${IP} -p tcp ${FRPC_PORT} -j ACCEPT
最终防火墙将会禁止服务端IP访问我本机的所有端口,并且只允许通过frpc通信的端口

然而在实际实践过程中,发现防火墙开启之后,frp不能和之前一样继续运行了,而是被防火墙拦截住。我调用netstat -anop命令查看,应该是frpc程序建立socket通信的端口被防火墙拦截了,导致程序无法访问。

找了一下配置文档,好像没能找到相关的端口配置。我感觉这个端口是随机的,可能为了避免端口被占用的情况,在frp源码里查找好像也是用随机的方法来调用。
请教一下,如何才能固定配置这个端口呢?谢谢!

Steps to reproduce the issue:
1.
2.
3.

Describe the results you received:

Describe the results you expected:

Additional information you deem important (e.g. issue happens only occasionally):

Can you point out what caused this issue (optional)

Originally created by @tun100 on GitHub (Mar 3, 2019). Original GitHub issue: https://github.com/fatedier/frp/issues/1108 Issue is only used for submiting bug report and documents typo. If there are same issues or answers can be found in documents, we will close it directly. (为了节约时间,提高处理问题的效率,不按照格式填写的 issue 将会直接关闭。) Use the commands below to provide key information from your environment: You do NOT have to include this information if this is a FEATURE REQUEST **What version of frp are you using (./frpc -v or ./frps -v)?** 服务器端和客户端都是 0.20.0 **What operating system and processor architecture are you using (`go env`)?** 没有开发,只是在使用 **Configures you used:** 你好!感谢开发了如此好用便捷的程序! 我的客户端是Ubuntu 16.04,frp版本都是0.20.0 因为网络设备之间环境复杂,服务器端和客户端都能互相ping通和访问端口,我需要使用iptables防火墙来禁止frp服务器端访问我笔记本的端口,只开放一些端口供frp程序使用。 我禁止的命令如下: 1, iptables -I INPUT -s ${IP} -j DROP 2, iptables -I INPUT -s ${IP} -p tcp ${FRPC_PORT} -j ACCEPT 最终防火墙将会禁止服务端IP访问我本机的所有端口,并且只允许通过frpc通信的端口 然而在实际实践过程中,发现防火墙开启之后,frp不能和之前一样继续运行了,而是被防火墙拦截住。我调用netstat -anop命令查看,应该是frpc程序建立socket通信的端口被防火墙拦截了,导致程序无法访问。 找了一下配置文档,好像没能找到相关的端口配置。我感觉这个端口是随机的,可能为了避免端口被占用的情况,在frp源码里查找好像也是用随机的方法来调用。 请教一下,如何才能固定配置这个端口呢?谢谢! **Steps to reproduce the issue:** 1. 2. 3. **Describe the results you received:** **Describe the results you expected:** **Additional information you deem important (e.g. issue happens only occasionally):** **Can you point out what caused this issue (optional)**
Author
Owner

@fatedier commented on GitHub (Mar 3, 2019):

你的客户端之所以要用 frp,肯定是一个内网环境,外网是访问不到的,所以你不需要设置这个防火墙,服务器之所以能和你客户端这个端口建立连接,是因为你的客户端主动对外建立的连接。服务端是不能随意访问到你客户端的端口的。只需要确保 frpc 的配置文件的安全性。

<!-- gh-comment-id:469025980 --> @fatedier commented on GitHub (Mar 3, 2019): 你的客户端之所以要用 frp,肯定是一个内网环境,外网是访问不到的,所以你不需要设置这个防火墙,服务器之所以能和你客户端这个端口建立连接,是因为你的客户端主动对外建立的连接。服务端是不能随意访问到你客户端的端口的。只需要确保 frpc 的配置文件的安全性。
Author
Owner

@tun100 commented on GitHub (Mar 3, 2019):

@fatedier 谢谢回复!可能我没有描述完整,我是用TeamViewer的VPN把client和server连接在一起,VPN给它们分配了一个ip,通过TeamViewer的网卡接口可以实现远程虚拟网络,同时它们通过这个虚拟网卡可以互联互通。
server端是一个跳板机,为了访问跳板机的内网设备,我是用这么操作的:

  • server 开启一个frps作为服务器
  • server 开启一个frpc,stcp协议并加了token
  • client 开启一个frpc,stcp协议并写对应token来访问server的frpc

因为server这台机器太多人用了,而且也有各种网络在里面,我怕别有用心的人来攻击我的本机,所以加了防火墙。

经过刚才的iptables调试,我找到了解决方案!
iptables -I INPUT -s ${IP} -j DROP
iptables -I INPUT -s ${IP} -p tcp --sport ${FRP_PORT} -j ACCEPT

把dport改为sport即可!问题应该解决了!

<!-- gh-comment-id:469032486 --> @tun100 commented on GitHub (Mar 3, 2019): @fatedier 谢谢回复!可能我没有描述完整,我是用TeamViewer的VPN把client和server连接在一起,VPN给它们分配了一个ip,通过TeamViewer的网卡接口可以实现远程虚拟网络,同时它们通过这个虚拟网卡可以互联互通。 server端是一个跳板机,为了访问跳板机的内网设备,我是用这么操作的: - server 开启一个frps作为服务器 - server 开启一个frpc,stcp协议并加了token - client 开启一个frpc,stcp协议并写对应token来访问server的frpc 因为server这台机器太多人用了,而且也有各种网络在里面,我怕别有用心的人来攻击我的本机,所以加了防火墙。 经过刚才的iptables调试,我找到了解决方案! iptables -I INPUT -s ${IP} -j DROP iptables -I INPUT -s ${IP} -p tcp --sport ${FRP_PORT} -j ACCEPT 把dport改为sport即可!问题应该解决了!
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#865
No description provided.