1. FRP 简介

FRP(Fast Reverse Proxy)是一款高性能内网穿透工具,可将内网服务(SSH、HTTP、RDP 等)映射到公网,实现远程访问。官方文档提供了安装、概念和示例说明。

案例:FRP 最简隧道部署文档(香港服务器 ↔ IDC)

1. 场景说明
  • 香港服务器(阿里云 ECS):拥有公网 IP,作为 frps(服务端)

  • IDC 服务器:无公网或不方便暴露公网,作为 frpc(客户端)

  • 目标:

    • 香港服务器可以通过 FRP 隧道 SSH 登录服务器

    • 香港服务器可以通过 FRP 隧道 FTP 访问服务器

    • 适用场景:

      • 香港服务器(阿里云)作为 frps

      • IDC 服务器作为 frpc

      • 香港服务器可通过 SSH / FTP 访问服务器

      • 使用 TLS 加密通道

      • 使用 systemd 自动启动

  • 要求:

    • 尽量简单,不使用 STCP/visitor

    • 保证安全性:只允许 IDC 的出口 IP 访问 frps

2. 架构拓扑
 IDC(frpc)  --主动连接-->  香港阿里云(frps)

 香港服务器通过 frps 暴露的端口访问IDC服务器

特点:

  • 服务器无需公网

  • 所有访问都从香港服务器发起

  • 安全组限制来源 IP,避免被外网扫描

3.香港服务器(frps)配置
3.1 frps.toml(含 TLS)

路径:/opt/frp/frps.toml

toml

bindAddr = "0.0.0.0"
bindPort = 7000

auth.method = "token"
auth.token = "123456"

# 启用 TLS 加密通道(强烈推荐)
transport.tls.enable = true

# 可选:Dashboard
webServer.addr = "0.0.0.0"
webServer.port = 7500
webServer.user = "admin"
webServer.password = "AdminPassword"

TLS 启用后,frpc 与 frps 之间的所有流量都会被加密。

3.2 systemd:/etc/systemd/system/frps.service

ini

[Unit]
Description=FRP Server (TLS)
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/opt/frp/frps -c /opt/frp/frps.toml
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

启用:

systemctl daemon-reload
systemctl enable frps
systemctl start frps
4. IDC(frpc)配置
4.1 frpc.toml(SSH + FTP + TLS)

路径:/opt/frp/frpc.toml

toml

serverAddr = "香港服务器公网IP"
serverPort = 7000

auth.method = "token"
auth.token = "123456"

# 启用 TLS 加密通道(必须与 frps 一致)
transport.tls.enable = true

# SSH 映射
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000

# FTP 映射
[[proxies]]
name = "ftp"
type = "tcp"
localIP = "127.0.0.1"
localPort = 21
remotePort = 6021
4.2 systemd:/etc/systemd/system/frpc.service

ini

[Unit]
Description=FRP Client (TLS)
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/opt/frp/frpc -c /opt/frp/frpc.toml
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

启用:

systemctl daemon-reload
systemctl enable frpc
systemctl start frpc
5.阿里云安全组(强安全)

为了避免 frps 暴露给全网,只允许 IDC 的出口 IP 访问:

入方向规则
协议 端口 授权对象 说明
TCP 7000 IDC 出口 IP/32 允许 frpc 连接 frps
TCP 6000 自己访问即可 SSH 隧道端口
TCP 6021 自己访问即可 FTP 隧道端口

删除:

代码

0.0.0.0/0 → TCP:7000
6.香港服务器访问服务器
SSH
ssh -p 6000 user@127.0.0.1
FTP

FTP 客户端:

  • 主机:香港服务器公网 IP

  • 端口:6021

  • 协议:FTP

7.最终安全性总结
安全措施 作用
TLS 加密 防止中间人攻击、流量嗅探
token 认证 防止未授权 frpc 连接
安全组白名单 只允许 IDC 访问 frps
frpc 主动连接 服务器不暴露公网
Copyright © https://yan-jian.com 2023 - 2026 All Right Reserved all right reserved,powered by Gitbook更新时间: 2026-04-27 19:51:20

results matching ""

    No results matching ""

    results matching ""

      No results matching ""