
背景在日常开发和运维工作中我们经常会遇到这样的场景在家需要访问公司内网的开发服务器需要将本地开发的小程序或 Web 应用暴露给外部测试远程访问部署在家庭网络的 NAS 或树莓派将内网的 Windows 远程桌面服务暴露给外部访问这些场景的共同特点是你的服务在内网中没有公网 IP无法直接从互联网访问。传统的解决方案包括花生壳、Ngrok 等第三方服务但它们往往有诸多限制方案限制花生壳免费版带宽有限需要付费才能获得更多功能Ngrok免费版只能访问随机生成的 URL不支持自定义域名花生壳服务不稳定安全性无法保证商业 VPN配置复杂成本高昂今天要介绍的frp (Fast Reverse Proxy)完美解决了这些问题让你拥有完全可控、稳定、高效的内网穿透系统。什么是 frpfrp是一个开源的高性能反向代理工具通过客户端-服务器架构将内网服务安全地暴露到公网。核心特性特性说明多协议支持支持 TCP、UDP、HTTP、HTTPS、SOCKS5 等协议简单配置仅需一个配置文件即可完成穿透设置高性能支持 TCP 流复用、KCP、QUIC 等加速协议安全可靠支持 TLS 加密、Token 认证、OIDC 认证热更新支持在不重启服务的情况下更新配置Web 仪表盘提供可视化的服务监控和管理界面P2P 模式支持点对点直连大幅降低服务器带宽消耗插件扩展提供丰富的插件支持静态文件、HTTP 代理等GitHub 数据Star: 97.4K语言: Go协议: Apache-2.0维护: 活跃维护中工作原理┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ 用户端 │ --- │ frps │ --- │ frpc │ │ (公网) │ │ (服务器) │ │ (内网) │ └─────────────┘ └─────────────┘ └─────────────┘ │ v ┌─────────────┐ │ 内网服务 │ │ (SSH/Web) │ └─────────────┘frps (Server): 部署在有公网 IP 的服务器上作为中转桥梁frpc (Client): 部署在需要暴露的内网机器上建立到 frps 的连接用户通过访问 frps 的公网地址间接访问到内网服务快速开始安装从 GitHub Release 页面下载对应平台的二进制文件# 下载 (Linux AMD64 为例)wgethttps://github.com/fatedier/frp/releases/download/v0.61.1/frp_0.61.1_linux_amd64.tar.gztar-xzffrp_0.61.1_linux_amd64.tar.gzcdfrp_0.61.1_linux_amd64# 服务器端文件lsfrps*# 客户端文件lsfrpc*服务器端配置编辑frps.toml# frps.toml - 服务器配置 bindPort 7000 # frpc 连接的端口 # Web 仪表盘 (可选) webServer.addr 0.0.0.0 webServer.port 7500 webServer.user admin webServer.password admin # 允许使用的端口范围 (可选) allowPorts [ { start 2000, end 3000 }, { single 3001 }, { start 4000, end 50000 } ]启动服务器./frps-c./frps.toml客户端配置编辑frpc.toml# frpc.toml - 客户端配置 serverAddr 你的服务器IP serverPort 7000 # 认证配置 (与服务器一致) auth.method token auth.token your_token_here [[proxies]] name ssh type tcp localIP 127.0.0.1 localPort 22 remotePort 6000启动客户端./frpc-c./frpc.tomlSSH 远程访问配置完成后即可通过服务器 IP 访问内网 SSHssh-oPort6000用户名服务器IP核心功能详解1. HTTP/HTTPS 服务暴露将内网 Web 服务通过自定义域名暴露到公网服务器端配置# frps.toml bindPort 7000 vhostHTTPPort 8080 vhostHTTPSPort 8443 subDomainHost example.com客户端配置# frpc.toml serverAddr x.x.x.x serverPort 7000 [[proxies]] name web type http localPort 80 customDomains [www.example.com] [[proxies]] name api type http localPort 8080 customDomains [api.example.com] locations [/api]DNS 配置将www.example.com和api.example.com的 A 记录解析到服务器 IP。2. 保护敏感服务 (STCP)对于敏感服务可以使用 Secret TCP 模式需要预共享密钥才能访问服务端 (机器 B)# frpc.toml [[proxies]] name secret_ssh type stcp secretKey abcdefg localIP 127.0.0.1 localPort 22访问端 (机器 C)# frpc.toml [[visitors]] name secret_ssh_visitor type stcp serverName secret_ssh secretKey abcdefg bindAddr 127.0.0.1 bindPort 6000访问时执行ssh-oPort6000user127.0.0.13. P2P 直连模式 (XTCP)用于传输大量数据的场景数据直接在各户端之间传输服务器只负责建立连接# frpc.toml (被访问端) [[proxies]] name p2p_ssh type xtcp secretKey abcdefg localIP 127.0.0.1 localPort 22# frpc.toml (访问端) [[visitors]] name p2p_ssh_visitor type xtcp serverName p2p_ssh secretKey abcdefg bindAddr 127.0.0.1 bindPort 60004. TCP 端口复用多个 SSH 服务共享同一端口通过域名区分服务器端# frps.toml bindPort 7000 tcpmuxHTTPConnectPort 5002机器 A# frpc.toml [[proxies]] name ssh1 type tcpmux multiplexer httpconnect customDomains [machine-a.example.com] localIP 127.0.0.1 localPort 22机器 B# frpc.toml [[proxies]] name ssh2 type tcpmux multiplexer httpconnect customDomains [machine-b.example.com] localIP 127.0.0.1 localPort 225. 插件功能frp 提供丰富的插件扩展插件用途unix_domain_socket暴露 Unix 域套接字http_proxyHTTP 代理socks5SOCKS5 代理static_file静态文件服务器https2httpHTTPS 转 HTTPhttps2httpsHTTPS 转 HTTPS静态文件服务器示例[[proxies]] name file_server type tcp remotePort 6000 [proxies.plugin] type static_file localPath /tmp/files stripPrefix static httpUser admin httpPassword admin6. 负载均衡支持多个后端服务负载均衡[[proxies]] name web1 type tcp localPort 8080 remotePort 80 loadBalancer.group web loadBalancer.groupKey secret [[proxies]] name web2 type tcp localPort 8081 remotePort 80 loadBalancer.group web loadBalancer.groupKey secret7. 健康检查支持服务健康检查实现高可用[[proxies]] name web type http localIP 127.0.0.1 localPort 80 customDomains [web.example.com] healthCheck.type http healthCheck.path /status healthCheck.timeoutSeconds 3 healthCheck.maxFailed 3 healthCheck.intervalSeconds 10高级配置TLS 加密frp 默认启用 TLS强制服务器端仅接受 TLS 连接# frps.toml transport.tls.force true transport.tls.certFile server.crt transport.tls.keyFile server.keyKCP 协议加速使用 KCP 协议可以减少延迟 30-40%# frps.toml bindPort 7000 kcpBindPort 7000# frpc.toml serverAddr x.x.x.x serverPort 7000 transport.protocol kcpQUIC 协议支持QUIC 是基于 UDP 的新一代多路复用传输协议# frps.toml bindPort 7000 quicBindPort 7000# frpc.toml transport.protocol quic连接池预建立连接池减少连接建立时间# frps.toml transport.maxPoolCount 5# frpc.toml transport.poolCount 2热更新配置修改配置后无需重启客户端./frpc reload-c./frpc.toml端口范围映射批量创建端口映射{{- range $_, $v : parseNumberRangePair 6000-6007 6000-6007 }} [[proxies]] name tcp-{{ $v.First }} type tcp localPort {{ $v.First }} remotePort {{ $v.Second }} {{- end }}实战场景场景一远程访问家中 NAS假设你有一台群晖 NAS 部署在家庭网络想要从外部访问# NAS 上的 frpc.toml serverAddr 你的服务器IP serverPort 7000 [[proxies]] name nasDSM type tcp localIP 192.168.1.100 localPort 5000 remotePort 5000 [[proxies]] name nasSSH type tcp localIP 192.168.1.100 localPort 22 remotePort 2222场景二暴露本地开发环境开发微信小程序或需要回调的 Web 应用时使用# frpc.toml serverAddr 你的服务器IP serverPort 7000 [[proxies]] name web type https customDomains [dev.yourdomain.com] [proxies.plugin] type https2http localAddr 127.0.0.1:8080 crtPath ./server.crt keyPath ./server.key hostHeaderRewrite 127.0.0.1场景三Windows 远程桌面# frpc.toml serverAddr 你的服务器IP serverPort 7000 [[proxies]] name rdp type tcp localIP 127.0.0.1 localPort 3389 remotePort 3389 transport.useEncryption true transport.useCompression true场景四搭建 SOCKS5 代理通过服务器转发网络流量[[proxies]] name socks5 type tcp remotePort 1080 [proxies.plugin] type socks5 httpUser user httpPassword password常见问题Q1: frpc 被杀毒软件误删怎么办frp 是网络穿透工具部分杀毒软件会将其误判为潜在有害程序。请在杀毒软件中将 frpc 添加到白名单。Q2: 如何选择 TCP/KCP/QUIC 协议协议适用场景TCP稳定可靠兼容性最好KCP网络延迟高时可提升 30-40% 速度QUIC需要低延迟和高吞吐量的场景Q3: frp 和 VPN 有什么区别VPN: 建立虚拟网络所有流量都走 VPN适合长期办公场景frp: 按需暴露特定端口和服务资源消耗更小配置更灵活Q4: 如何保证传输安全启用 TLS 加密 (transport.tls.enable true)使用 Token 或 OIDC 认证对敏感服务使用 STCP 模式 预共享密钥使用 HTTP Basic Auth 保护 Web 服务Q5: 连接不稳定怎么办检查服务器防火墙是否放行端口尝试更换传输协议 (TCP → KCP/QUIC)启用连接池和 TCP 流复用检查网络 NAT 类型是否限制穿透总结frp 是一款功能强大、配置灵活的内网穿透工具具有以下核心优势优势说明✅ 完全可控自建服务数据完全自主掌控✅ 高性能支持 KCP/QUIC 加速TCP 流复用✅ 多协议TCP、UDP、HTTP、HTTPS、SOCKS5✅ 安全可靠TLS 加密、Token/OIDC 认证✅ 功能丰富负载均衡、健康检查、热更新✅ 易于使用配置文件简洁学习成本低✅ 活跃社区97K Star持续迭代更新无论是远程访问家庭设备、暴露开发环境还是搭建私有 VPNfrp 都能提供稳定、高效的解决方案。建议有相关需求的读者部署自己的 frp 服务享受完全自主的内网穿透体验。相关资源GitHub: https://github.com/fatedier/frp官方文档: https://frp.readthedocs.io/插件仓库: https://github.com/gofrp/plugin如果你觉得这个工具对你有帮助欢迎关注我们的更多技术分享。