frp 内网穿透一站式 skill,覆盖从零到日常运维全流程。首次使用会引导用户:从 gitee.com/DYXZYT/frp-cli 安装 frp-cli 二进制(带源码构建兜底)、可选购阿里云轻量应用服务器和域名(含套餐选型、地域选择、ICP 备案说明)、配置阿里云控制台和系统双层防火墙、在云端部署 frps 服务端、本机连接客户端、按场景(SSH / Web / RDP / MySQL / Minecraft / NAS / Webhook)添加第一条端口映射;已初始化的用户会自动跳
frp-cli技能(统一设置+操作). frp-cli是一款围绕 frp(frpc + frps)的 git 风格包装器,配置配置配置,结构化的 JSON 输出是一项面向实际任务的技能。它将相关步骤、工具调用和结果整理方式集中到统一流程中,帮助使用者更快完成目标并减少重复操作。
实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。
执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
frp-cli is a git-style wrapper around frp (frpc + frps) with profiles, structured JSON output, daemon management, and an admin/dashboard API passthrough. Always prefer it over hand-editing TOML or invoking frpc / frps directly.
This skill covers the whole journey: from a blank machine to a working tunnel, then ongoing operations. It is stateful — a marker at $FRP_HOME/.setup-done (default ~/.frp-cli/.setup-done) tells future invocations to skip Section A.
Check three things. If all three pass → skip Section A entirely, go to Section B (Operations).
# Linux / macOS
FRP_HOME="${FRP_HOME:-$HOME/.frp-cli}"
command -v frp-cli >/dev/null 2>&1
&& test -f "$FRP_HOME/config.toml"
&& test -f "$FRP_HOME/.setup-done"
&& echo "ALREADY_INITIALIZED"
# Windows PowerShell
$frpHome = if ($env:FRP_HOME) { $env:FRP_HOME } else { "$HOME.frp-cli" }
if ((Get-Command frp-cli -ErrorAction SilentlyContinue) `
-and (Test-Path "$frpHomeconfig.toml") `
-and (Test-Path "$frpHome.setup-done")) {
"ALREADY_INITIALIZED"
}
If ALREADY_INITIALIZED:
frp-cli profile list --json and frp-cli status --all --json.If any check fails, resume Section A from the corresponding step:
frp-cli not found → A.1 (install)frp-cli init)内网穿透有三个角色:
- frpc(client):跑在你家里 / 实验室 / 公司这台想被外网访问的机器上。
- frps(server):跑在一台有公网 IP 的机器上(云服务器 / VPS),充当中转。
frp-cli:一个二进制,可同时扮演 client 或 server,靠 profile 区分。完整链路:
公网用户 → 服务器公网 IP:remotePort → frps → frpc → 本机:localPort
然后必须问用户:
"你目前有没有一台带公网 IP 的服务器(云主机 / VPS)?"
- 有,且 frps 已经在跑 → 跳到 A.6(只装客户端)
- 有,但 frps 没装 → A.1 → A.5 → A.6 → A.7
- 没有,想自建 → A.1 → A.3(阿里云购买)→ A.4(防火墙)→ A.5 → A.6 → A.7
- 不想买服务器 → 建议改用 cpolar / ngrok(本 skill 不覆盖),或退出
frp-cli(本机 + 云端都要装)三级 fallback,第一条成功就停。装完用 frp-cli version 验证。
set -e
case "$(uname -s)" in Linux) os=linux ;; Darwin) os=darwin ;; *) echo "Unsupported OS"; exit 1 ;; esac
case "$(uname -m)" in x86_64|amd64) arch=amd64 ;; aarch64|arm64) arch=arm64 ;; *) echo "Unsupported arch"; exit 1 ;; esac
BINDIR="$HOME/.local/bin"
mkdir -p "$BINDIR"
# Source 1: gitee release latest (国内首选)
VER=$(curl -fsSL https://gitee.com/api/v5/repos/DYXZYT/frp-cli/releases/latest
| grep -oE '"tag_name":"[^"]+"' | head -n1 | cut -d'"' -f4 || true)
if [ -n "$VER" ]; then
URL="https://gitee.com/DYXZYT/frp-cli/releases/download/${VER}/frp-cli-${os}-${arch}.tar.gz"
if curl -fsSL "$URL" | tar xz -C /tmp 2>/dev/null && [ -f /tmp/frp-cli ]; then
mv /tmp/frp-cli "$BINDIR/frp-cli" && chmod +x "$BINDIR/frp-cli"
fi
fi
# Source 2: source build from gitee clone (兜底,要 Go 1.25+)
if ! "$BINDIR/frp-cli" version >/dev/null 2>&1; then
if ! command -v go >/dev/null; then
echo "Go 未安装。装 Go 1.25+: https://golang.google.cn/dl/ 然后重跑本节"; exit 1
fi
SRC="$HOME/.cache/frp-cli-src"
[ -d "$SRC/.git" ] || git clone --depth 1 https://gitee.com/DYXZYT/frp-cli.git "$SRC"
(cd "$SRC" && GOPROXY=https://goproxy.cn,direct go build -trimpath -ldflags="-s -w" -o "$BINDIR/frp-cli" ./cmd/frp-cli/)
fi
# PATH 持久化
case ":$PATH:" in *":$BINDIR:"*) ;; *)
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "${ZDOTDIR:-$HOME}/.zshrc" 2>/dev/null || true
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$HOME/.bashrc" 2>/dev/null || true
export PATH="$BINDIR:$PATH"
;;
esac
frp-cli version
$ErrorActionPreference = "Stop"
$arch = if ([Environment]::Is64BitOperatingSystem) { "amd64" } else { throw "Need 64-bit Windows" }
$bin = "$HOMEbin"
New-Item -ItemType Directory -Force $bin | Out-Null
# Source 1: gitee release latest
$ok = $false
try {
$ver = (Invoke-RestMethod "https://gitee.com/api/v5/repos/DYXZYT/frp-cli/releases/latest").tag_name
$url = "https://gitee.com/DYXZYT/frp-cli/releases/download/$ver/frp-cli-windows-$arch.zip"
$zip = "$env:TEMPfrp-cli.zip"
Invoke-WebRequest $url -OutFile $zip -UseBasicParsing
Expand-Archive $zip -DestinationPath $bin -Force
$ok = $true
} catch { $ok = $false }
# Source 2: source build
if (-not $ok) {
if (-not (Get-Command go -ErrorAction SilentlyContinue)) {
throw "Go 未安装。装 Go 1.25+: https://golang.google.cn/dl/"
}
$src = "$HOME.cachefrp-cli-src"
if (-not (Test-Path "$src.git")) {
git clone --depth 1 https://gitee.com/DYXZYT/frp-cli.git $src
}
Push-Location $src
$env:GOPROXY = "https://goproxy.cn,direct"
go build -trimpath -ldflags="-s -w" -o "$binfrp-cli.exe" ./cmd/frp-cli/
Pop-Location
}
# 持久化用户级 PATH
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -notlike "*$bin*") {
[Environment]::SetEnvironmentVariable("Path", "$userPath;$bin", "User")
$env:Path = "$env:Path;$bin"
}
frp-cli version
若失败:明确告诉用户错误信息,让其选择 (a) 装 Go 重试源码构建 (b) 换网络 (c) 提供预下载好的二进制。
server-addr / server-port / token → A.6入口:https://www.aliyun.com/product/swas(轻量应用服务器,非"云服务器 ECS";轻量便宜且足够穿透)。
| 场景 | 配置 | 带宽 | 估价(/月) |
|---|---|---|---|
| 个人 SSH / Web 穿透 / 远程办公 | 2c2g | 3 Mbps | ¥30 起 |
| 中等并发 Web、3-5 人 Minecraft | 2c2g | 5 Mbps | ¥50 起 |
| 大文件传输、RDP 远程桌面、20+ 人 MC | 2c4g | 6-10 Mbps | ¥100 起 |
| 多人 / 团队 / 直播推流 | 4c8g | 10+ Mbps | ¥200+ |
带宽是关键——frps 转发吃满你买的带宽上限。穿透只看带宽,CPU/内存够用就行。
Ubuntu 22.04 LTS 或 Debian 12。Centos 7 已 EOL,不推荐。
新用户 3 个月 / 1 年套餐通常大幅折扣,按年比按月便宜 30-50%。
| 选项 | 适用 | 代价 |
|---|---|---|
| 不买域名 | 只做 SSH / RDP / TCP / 数据库 / MC 等纯端口透传,IP:端口 访问 |
¥0 |
| 买域名 + 国内服务器 | 想用 https://app.example.com 访问 Web |
域名 ~¥55/年 + ICP 备案(7-20 天、绑定服务器 ≥3 个月) |
| 买域名 + 香港/海外服务器 | 域名 + HTTPS 又不想备案 | 域名 ~¥55/年(带宽贵) |
| 买域名 + Cloudflare 反代 | 隐藏源 IP、CDN 加速 | 域名钱 + Cloudflare 免费 |
新手建议:第一次穿透先不买域名,跑通 SSH / TCP 隧道。后续真要 HTTPS / 多服务再加。
域名购买:https://wanwang.aliyun.com/。备案:阿里云控制台 → ICP 备案。
阿里云轻量付款后 1-3 分钟开通。控制台 → 实例 → 拿到公网 IP 和初始 root 密码(或重置密码)。
ufw allow 。| 端口 | 协议 | 用途 | 必须 |
|---|---|---|---|
| 22 | TCP | SSH 登服务器 | ✅ |
| 7000 | TCP | frps 主端口(客户端连接) | ✅ |
| 7500 | TCP | frps dashboard | 推荐 |
| 7022 | TCP | 暴露的 SSH 端口(recipe S) | 看 recipe |
| 7080 | TCP | 暴露的 Web 端口(recipe W1) | 看 recipe |
| 80 / 443 | TCP | 用域名 vhost 时 | 看 recipe |
每加一条隧道前先放行 remotePort,否则公网访问会超时。
SSH 进服务器后:
# 装 frp-cli(重复 A.1.a)
frp-cli init
frp-cli profile add prod --role server
--bind-port 7000
--dashboard-port 7500 --dashboard-user admin
# token + dashboard 密码自动生成
# 拿凭证(客户端必须用 token;dashboard 密码登 Web 界面)
frp-cli profile show prod --json
# 关心 .meta.token 和 .meta.dashboardPassword
frp-cli server start
frp-cli server status --json
frp-cli doctor --json
记下 <服务器公网 IP>:7000 和 TOKEN。dashboard:http://<服务器公网 IP>:7500,账号 admin,密码 = dashboardPassword。
# A.1 装好 frp-cli,A.5 拿到 token
frp-cli init
frp-cli profile add home --role client
--server-addr <服务器公网 IP>
--server-port 7000
--token
frp-cli profile use home
先不要 start,A.7 加完至少一条隧道再启。
全部假设
profile use home已生效。 添加后用frp-cli client start(首次)或frp-cli client reload(已运行)生效。 每个 recipe 的remotePort都要在 A.4 阿里云防火墙放行。
frp-cli template apply ssh --var remotePort=7022 frp-cli client start
公网访问:ssh -p 7022 user@<服务器公网 IP>
frp-cli tunnel add web --type tcp --local-port 8080 --remote-port 7080 frp-cli client reload # 首次:client start
公网访问:http://<服务器公网 IP>:7080
前置:A.3.5 域名 + ICP 备案完成;80 端口已放行。
服务端一次性:
frp-cli config edit # 在 [webServer] 之后加: # vhostHTTPPort = 80 frp-cli server restart
客户端:
frp-cli tunnel add web --type http
--local-port 8080
--custom-domain app.example.com
frp-cli client reload
DNS:在阿里云域名控制台为 app.example.com 加 A 记录指向服务器公网 IP,等 DNS 生效后访问 http://app.example.com。
frp-cli tunnel add rdp --type tcp --local-port 3389 --remote-port 7389 frp-cli client reload
公网访问:mstsc /v:<服务器公网 IP>:7389
frp-cli tunnel add mysql --type tcp --local-port 3306 --remote-port 7306 frp-cli client reload
⚠️ 公网暴露数据库高危——强密码 + bind-address 限制 + 防火墙白名单 IP。
frp-cli tunnel add mc --type tcp --local-port 25565 --remote-port 25565 frp-cli client reload
玩家加服务器:<服务器公网 IP>(端口默认)。
frp-cli tunnel add nas --type tcp --local-port 5000 --remote-port 7150 frp-cli client reload
更安全方案(P2P 直连,不占公网带宽):B.4 xtcp/stcp。
frp-cli tunnel add webhook --type http
--local-port 3000 --custom-domain hooks.example.com
frp-cli client reload
用完即删:frp-cli tunnel remove webhook && frp-cli client reload。
# Linux/macOS
touch "${FRP_HOME:-$HOME/.frp-cli}/.setup-done"
echo "Setup complete at $(date -Iseconds)" >> "${FRP_HOME:-$HOME/.frp-cli}/.setup-done"
frp-cli status --all --json
frp-cli doctor --json
# Windows
$frpHome = if ($env:FRP_HOME) { $env:FRP_HOME } else { "$HOME.frp-cli" }
"Setup complete at $(Get-Date -Format o)" | Out-File "$frpHome.setup-done" -Encoding utf8
frp-cli status --all --json
frp-cli doctor --json
向用户输出小结:服务器 IP / token / dashboard URL / 已配隧道列表 / 每条公网访问地址。建议存密码管理器。
frp-cli status --all --json + frp-cli server clients/proxies加:参考 A.7 任一 recipe。每加一条 TCP/UDP 隧道前先在 A.4 阿里云防火墙放行 remotePort。
改(不重启,热更新):
frp-cli tunnel update web --remote-port 9080 frp-cli client reload # 其它隧道连接不受影响
删:
frp-cli tunnel remove web frp-cli client reload
暂停 / 恢复(保留配置):
frp-cli tunnel disable web && frp-cli client reload frp-cli tunnel enable web && frp-cli client reload
frp-cli profile list # 看有哪些 frp-cli profile use prod # 切到 prod,后续命令默认 prod frp-cli --profile dev tunnel list # 单条命令临时覆盖
适合家庭 NAS / 大文件传输——provider 端(NAS)和 visitor 端(要访问的设备)都得跑 frpc,但实际流量不过 frps。
NAS 侧(provider):
frp-cli tunnel add nas --type xtcp
--local-ip 127.0.0.1 --local-port 5000
--secret-key
笔记本侧(visitor,单独 client profile):
frp-cli visitor add nas --type xtcp --server-name nas
--secret-key --bind-port 6000
连接:本地 127.0.0.1:6000。
stcp 同结构,但走 frps 中转(更稳,但耗带宽)。
frp-cli doctor --json # 5 项体检:config/parse/process/server-reach/admin-api,先看这个 frp-cli client logs --tail 100 # 客户端日志 frp-cli server logs --tail 100 # 服务端(如你在服务端) frp-cli config validate # 重跑 frp loader frp-cli api get /api/proxy/tcp # 服务端:看 dashboard 真实在转什么 frp-cli status --all --json # 全 profile 聚合
| doctor 输出 | 含义 | 修法 |
|---|---|---|
server-reachable: fail |
客户端连不上服务端 | (1) 服务器公网 IP 对不对(2)7000 在阿里云防火墙放行(3)token 是否与服务端 profile show prod 里的 token 一致 |
admin-api: warn (client not running) |
进程没启动 | frp-cli client start |
dashboard: fail |
端口没开 / 密码错 | 检查防火墙 7500、profile show 拿正确密码 |
公网访问超时但 client status OK |
remotePort 没在阿里云防火墙放行 |
控制台加规则;规则生效有 1-2 分钟延迟 |
| 端口已被占用 | 服务端 7000/7500 撞车 | 改 bind-port/dashboard-port,或 lsof -i:7000 杀冲突进程 |
# 重跑 A.1 的安装脚本即可覆盖二进制;配置不动 frp-cli version frp-cli client restart # 或 server restart frp-cli doctor --json
frp-cli client stop && frp-cli server stop 2>/dev/null || true
rm -rf "${FRP_HOME:-$HOME/.frp-cli}"
rm -f ~/.local/bin/frp-cli # 或 $HOMEbinfrp-cli.exe
所有读类命令支持 --json,需要解析时必须显式带(非 TTY 自动结构化,但显式更安全)。
稳定 JSON 形状:
frp-cli profile list --json → [{name, role, active, configPath}, ...]frp-cli tunnel list --json → {tunnels: [{name, type, localPort, remotePort, ...}]}frp-cli status --json / --all --json → [{profile, role, state:{running,pid,...}, admin:{reachable,endpoint}, counts:{...}}]frp-cli doctor --json → [{name, status:"ok"|"warn"|"fail", detail}]frp-cli api get → 原样透传 dashboard / admin JSONfrp-cli profile show --json → 含 meta.token、meta.dashboardPassword 等全局 flags:--profile --json --frp-home -v -vv。
下列操作影响运行中的服务或持久状态。除非用户在当前对话明确要求,先 ask before doing:
frp-cli client stop / server stop / restart 针对疑似生产 profilefrp-cli profile remove (需 --yes;连同 tunnel/visitor TOML 一起删)frp-cli tunnel remove + client reload(断该代理在线连接)非生产 smoke test → 用 --frp-home 起一次性 profile,不污染主目录。
frp-cli api get/post —— 透传 dashboard/admin APIfrp-cli config show --json / frp-cli config edit —— 直接看/改底层 TOMLfrp-cli profile export / profile import —— 备份/迁移整个 profilefrpc / frps 原生二进制 → 仅作为最后手段,并告诉用户 CLI 在哪缺位tunnel add → 阿里云防火墙放行 remotePort → client reload。--json 方便解析。.setup-done 是单一事实来源。相关专题
热门下载
相关下载
精品课程
共6课时 | 54.7万人学习
共89课时 | 134.3万人学习
共49课时 | 82.7万人学习
最新文章