frp 实战
frp 实战
Ubuntu 22.04 部署 FRP 服务端 + 飞牛OS 客户端配置指南
一、公网服务器(Ubuntu 22.04 x86_64)安装 FRP 服务端
目标:在公网服务器搭建 frps,接收内网飞牛OS客户端的连接。
1. 下载并解压 FRP
# 下载最新版 FRP(适配 x86_64)
wget https://github.com/fatedier/frp/releases/download/v0.61.1/frp_0.61.1_linux_amd64.tar.gz
tar -zxvf frp_0.61.1_linux_amd64.tar.gz
cd frp_0.61.1_linux_amd64
2. 配置服务端 frps.toml
bindPort = 7000 # 客户端连接端口
auth.token = "your_secure_token_123" # 必须与客户端一致
# 可选:监控面板(默认关闭)
webServer.port = 7500 # 管理面板端口
webServer.user = "admin" # 账号
webServer.password = "your_password" # 密码
3. 启动服务端
# 测试运行(前台)
./frps -c ./frps.toml
# 创建frpc.service + 开机自启
vim /etc/systemd/system/frpc.service
[Unit]
Description=FRP Server (frps)
After=network.target
[Service]
Type=simple
User=root
ExecStart=/path/to/frpc -c /path/to/frpc.toml
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
=====
参数说明:
/path/to/frpc:替换为 frpc 可执行文件的绝对路径(如 /home/user/frp_0.61.1_linux_amd64/frpc)。
/path/to/frpc.toml:替换为 frpc.toml 配置文件的绝对路径(如 /home/user/frp_0.61.1_linux_amd64/frpc.toml)。
Restart=on-failure:进程崩溃时自动重启。
User=root:以 root 用户运行(可按需改为普通用户)。
# 启用并启动FRP 服务端服务
# 重载 Systemd 配置
sudo systemctl daemon-reload
# 设置开机自启
sudo systemctl enable frpc
# 立即启动服务
sudo systemctl start frpc
# 检查服务状态
sudo systemctl status frpc
4. 防火墙放行
sudo ufw allow 7000/tcp
sudo ufw allow 7500/tcp
sudo ufw reload
5. 验证服务端
-
检查端口监听:
ss -tulnp | grep frps # 应看到 7000 和 7500 端口 -
访问 Dashboard(可选):
http://公网IP:7500,输入账号密码登录。
二、飞牛OS(内网)安装 FRP 客户端
目标:将内网 192.168.0.111:6806 映射到公网端口。
1. 下载并解压 FRP 或 下载现成的软件 配置启动
wget https://github.com/fatedier/frp/releases/download/v0.61.1/frp_0.61.1_linux_amd64.tar.gz
tar -zxvf frp_0.61.1_linux_amd64.tar.gz
cd frp_0.61.1_linux_amd64
2. 配置客户端 frpc.toml
serverAddr = "公网服务器IP" # 替换为公网IP
serverPort = 7000 # 与服务端一致
auth.token = "your_secure_token_123"
[[proxies]]
name = "nas_6806" # 自定义名称
type = "tcp" # 协议类型
localIP = "192.168.0.111" # 内网目标IP
localPort = 6806 # 内网端口
remotePort = 6806 # 公网暴露端口(可改为其他端口)
3. 启动客户端
# 测试运行
./frpc -c ./frpc.toml
4. 验证连接
-
服务端 Dashboard:检查
TCP 连接 中nas_6806 是否在线。 -
客户端日志:
journalctl -u frpc -f # 查看实时日志
三、外网访问测试
-
通过公网IP访问:
telnet 公网IP 6806 # 测试TCP端口 curl http://公网IP:6806 # 如果是HTTP服务 -
通过域名访问(可选):
在域名解析中添加A记录 指向公网IP,并配置type = "http"。
四、安全优化
-
修改默认端口:将
7000 改为高位端口(如37000)。 -
限制访问IP:在
frps.toml 中添加:allowPorts = ["6806"] # 仅允许映射6806端口 -
启用 TLS 加密(可选):
tls.enable = true
五、常见问题
-
连接失败:
- 检查
token、防火墙、安全组设置。 - 确保内网
192.168.0.111:6806 服务已启动。
- 检查
-
端口占用:更换
remotePort(如16806)。
最终效果
通过 公网IP:6806 稳定访问内网 192.168.0.111:6806 的服务(如 NAS、数据库等)。

浙公网安备 33010602011771号