FRP搭建流程

FRP搭建流程

FRP搭建SOP

FRP搭建流程

服务端部署

1. 下载FRP

1
2
3
4
5
# 下载最新版FRP(以v0.58.0为例,请查看GitHub获取最新版本) 
wget https://github.com/fatedier/frp/releases/download/v0.58.0/frp_0.58.0_linux_amd64.tar.gz
# 解压 
tar -xzf frp_0.58.0_linux_amd64.tar.gz 
cd frp_0.58.0_linux_amd64

2. 配置服务端

创建服务端配置文件 frps.toml

1
2
3
4
5
6
7
8
# FRP服务端配置 
bindPort = 7000 # FRP通信端口 
auth.token = "YourStrongPassword" # 认证密码,客户端需要一致 
# Web管理面板(可选但推荐) 
webServer.addr = "0.0.0.0" 
webServer.port = 7500 
webServer.user = "admin" # 面板用户名 
webServer.password = "dashboard123" # 面板密码

3. 启动FRP服务端

1
2
3
4
# 前台运行(测试用) 
./frps -c frps.toml 
# 后台运行(正式使用) 
nohup ./frps -c frps.toml > frps.log 2>&1 &

4. 配置防火墙

在控制台 → 防火墙 中放行以下端口:

端口 用途 必须
7000 FRP通信端口 ✅ 必须
7500 FRP管理面板 可选
5000-6000 穿透映射端口(按需) 按需

5. 设置开机自启(systemd)

一、安装systemd

1
2
# 使用 yum 安装 systemd(CentOS/RHEL)
yum install systemd

二、创建服务文件 /etc/systemd/system/frps.service

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[Unit] 
Description=FRP Server 
After=network.target 

[Service] 
Type=simple 
ExecStart=/root/frp_0.58.0_linux_amd64/frps -c /root/frp_0.58.0_linux_amd64/frps.toml 
Restart=always 
RestartSec=5 

[Install] 
WantedBy=multi-user.target

三、启用服务:

1
2
3
4
systemctl daemon-reload 
systemctl enable frps 
systemctl start frps 
systemctl status frps # 确认运行正常

客户端配置

下载FRP客户端

1. 下载FRP客户端

在你的内网设备上下载对应操作系统版本的FRP:

  • Linux/Mac → frp_0.58.0_linux_amd64.tar.gz
  • Windows → frp_0.58.0_windows_amd64.zip
  • 树莓派 → frp_0.58.0_linux_arm64.tar.gz

2. 配置客户端

创建客户端配置文件 frpc.toml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# FRP客户端配置
serverAddr = "你的公网IP"
serverPort = 7000
auth.token = "YourStrongPassword"  # 必须与服务端一致

# 穿透规则1:NAS Web管理页面
[[proxies]]
name = "nas-web"
type = "tcp"
localIP = "127.0.0.1"
localPort = 5000          # NAS管理页面端口(群晖默认5000)
remotePort = 5000         # 通过服务器的5000端口访问

# 穿透规则2:SSH远程连接
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000         # 通过服务器的6000端口SSH

# 穿透规则3:Windows远程桌面
[[proxies]]
name = "rdp"
type = "tcp"
localIP = "127.0.0.1"
localPort = 3389
remotePort = 3389

# 穿透规则4:本地Web开发项目
[[proxies]]
name = "dev-web"
type = "tcp"
localIP = "127.0.0.1"
localPort = 3000          # 本地开发服务器端口
remotePort = 3000

3. 启动客户端

1
2
3
4
5
# Linux/Mac
./frpc -c frpc.toml

# Windows(CMD)
frpc.exe -c frpc.toml

4. 验证穿透

现在你可以在任何有网络的地方,通过服务器的公网IP访问内网设备:

服务 访问地址
NAS管理页面 http://你的公网IP:5000
SSH远程连接 ssh -p 6000 user@你的公网IP
Windows远程桌面 远程桌面连接 你的公网IP:3389
本地Web项目 http://你的公网IP:3000
FRP管理面板 http://你的公网IP:7500

进阶配置

1. 自定义域名访问(HTTP穿透)

如果想通过域名而不是IP+端口访问,可以使用HTTP类型的穿透:

服务端增加配置

1
vhostHTTPPort = 80

客户端配置:

1
2
3
4
5
[[proxies]]
name = "nas-domain"
type = "http"
localPort = 5000
customDomains = ["nas.yourdomain.com"]

然后将 nas.yourdomain.com 的DNS解析到服务器的公网IP即可。

2. HTTPS加密(推荐)

为了安全,建议给穿透的Web服务加上HTTPS。可以在服务器上使用Nginx反向代理+Let’s Encrypt免费证书:

1
2
3
4
5
# 安装certbot
apt install certbot python3-certbot-nginx -y

# 申请证书
certbot --nginx -d nas.yourdomain.com

3. Windows客户端开机自启

Windows上设置FRP开机自启的最简方法:

  1. 创建 start-frpc.vbs 文件:Set ws = CreateObject(“Wscript.Shell”) ws.Run “cmd /c D:\frp\frpc.exe -c D:\frp\frpc.toml”, 0
  2. start-frpc.vbs 放入 C:\Users\你的用户名\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\
本文由作者按照 CC BY 4.0 进行授权