最近,某第三方公司说我们封了frp, 为了证明我们没有,而是他们配置有问题。所以我利用自己的服务器部署来证明。
frp部署
frp Github
frp分成 frps和frpc, frps与frps.ini配置文件是Server使用的,同理,frpc与frpc.ini配置文件是需要被内网穿透的机器(客户端)使用的。
以Ubuntu部署frps为例:
wget https://github.com/fatedier/frp/releases/download/v0.41.0/frp_0.41.0_linux_amd64.tar.gz
# 下载后解压
AI 代码解读
配置frps.ini
在更新的版本,不再使用.ini,而是使用.toml
[common]
bind_port = 60000
vhost_http_port = 18080
token = 22N2UMYA4AL772BE1
AI 代码解读
bind_port是服务器端与客户端统一绑定的端口
vhost_http_port或者vhost_https_port 是映射到公网端口
token是密码,用于验证。
配置frpc.ini
[common]
server_addr = 156.146.88.125
server_port = 60000
token = 22N2UMYA4AL772BE1
tls_enable = true
[web]
type = http
local_ip = 192.168.1.101
local_port = 80
custom_domains = ppp.example.com
AI 代码解读
server_addr是服务端地址
[web]的内容是穿透到本地机器的web服务
custom_domains是绑定自定义域名
其中tls_enable并非必须,但是有时候如果没有添加这一行,会导致本机服务无法链接。
错误提示是:login to server failed: EOF
服务端启动服务
直接cd到解压后文件夹,然后在终端输入:
./frps -c ./frps.ini
AI 代码解读
服务端停止服务
netstat -tulpn
#找到端口对应的服务PID
#sudo kill -9 <PID>
sudo kill -9 12512
AI 代码解读
Windows客户端启动服务
D:\frp>frpc.exe -c frpc.ini
AI 代码解读
暴露本地RDP 3389远程桌面链接
我们可以通过公网的服务器暴露机器B的RDP,在机器C也安装frp client的情况下实现p2p链接。
公网IP服务器A配置
我使用docker部署了frps, 以下是配置内容:(将文件映射到裸机文件夹)
参考:https://gofrp.org/zh-cn/docs/features/xtcp/
XTCP 的配置方式和 STCP 很类似。但是会采用 P2P 的方式进行打洞穿透,如果成功,后续的流量将不会经过 frps,而是直接通信,不再受到 frps 所在服务器的带宽限制。
[common]
bind_port = 7000
AI 代码解读
需要暴露的RDP机器B
sk是preshared key,也可以没有的。
[common]
server_addr = x.x.x.x
server_port = 7000
[secret_ssh]
type = xtcp
sk = abcdefg
local_ip = 127.0.0.1
local_port = 3389
AI 代码解读
然后在frp文件夹运行
D:\frp>frpc.exe -c frpc.ini
AI 代码解读
另一台需要连接到RDP的C机器
[common]
server_addr = x.x.x.x
server_port = 7000
[secret_ssh_visitor]
type = xtcp
role = visitor
server_name = secret_ssh
sk = abcdefg
bind_addr = 127.0.0.1
bind_port = 6000
AI 代码解读
然后在frp文件夹运行
D:\frp>frpc.exe -c frpc.ini
AI 代码解读
只有1台公网和1台客户端情况下直接访问
公网:
[common]
bind_port = 7000
sk = abcdefg
AI 代码解读
客户端:
[common]
server_addr = x.x.x.x
server_port = 7000
[rdp]
type = stcp
sk = abcdefg
local_ip = 127.0.0.1
local_port = 3389
remote_port = 6000
AI 代码解读