面向开发者的终端 Proxy 工作流
FreeGuard CLI 通过将流量路由到加密的 VPN 隧道中,把你的终端变成安全的开发环境。无论你是在受限网络中克隆仓库、跨区域调试 API,还是通过安全通道部署容器,CLI 都能无缝集成到你已经在使用的工具中——git、ssh、curl、docker 等等。
为什么开发者需要终端 Proxy
许多开发任务都涉及需要 VPN 保护的网络访问:
- 在咖啡馆或机场访问内部 API
- 在开发过程中测试地理限制服务
- 通过会限速或检查 git 流量的网络推送代码
- 通过受限防火墙连接远程服务器
- 在传输过程中加密 CI/CD 凭据
FreeGuard CLI 能处理以上所有场景,而且无需离开你的终端。
通过 VPN 使用 Git
问题
企业网络、公共 Wi-Fi 和某些 ISP 会限速或阻止 git 操作。基于 SSH 的 git 连接可能会被深度包检测标记。HTTPS 克隆可能会被透明 Proxy 拦截。
解决方案
在执行 git 操作之前先连接到 FreeGuard:
freeguard connect --server us-east
git clone [email protected]:your-org/private-repo.git
git fetch --all
git push origin feature-branch
freeguard disconnect
若想更自动化一些,可以把它封装到脚本中:
#!/bin/bash
freeguard connect --server us-east --json | jq -r '.status'
trap "freeguard disconnect" EXIT
git pull origin main
npm run build
git push origin main
trap 可确保即使脚本中途失败,VPN 也会断开。
支持 Proxy 的 Git
FreeGuard CLI 还可以暴露本地 SOCKS5 或 HTTP Proxy。将 git 配置为使用它:
# Set proxy for git globally
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080
# Or per-repository
git config http.proxy socks5://127.0.0.1:1080
完成后移除 Proxy 配置:
git config --global --unset http.proxy
git config --global --unset https.proxy
使用 VPN 进行 SSH 隧道连接
远程服务器访问
当你需要从不受信任的网络通过 SSH 连接服务器时,VPN 会在你的 SSH 流量离开设备之前先增加一层加密:
freeguard connect --server us-west
ssh [email protected]
通过 VPN 使用 ProxyJump
将 FreeGuard 与 SSH ProxyJump 结合起来,实现多跳访问:
# Connect to VPN first
freeguard connect
# Then jump through a bastion host
ssh -J [email protected] [email protected]
端口转发
通过 VPN 隧道转发远程端口:
freeguard connect --server eu-west
ssh -L 5432:db.internal:5432 [email protected]
# Now connect to localhost:5432 to reach the remote database
API 开发
使用 curl 进行测试
通过 VPN 路由你的 API 请求,以便从不同区域进行测试:
freeguard connect --server jp-tokyo
# Test geo-specific API responses
curl -s https://api.example.com/v1/content | jq '.region'
# Output: "ap-northeast-1"
freeguard connect --server de-frankfurt
curl -s https://api.example.com/v1/content | jq '.region'
# Output: "eu-central-1"
使用 httpie
httpie 的工作方式相同。FreeGuard CLI 在系统层面运行,因此所有 HTTP 客户端都能受益:
freeguard connect --server uk-london
http GET https://api.example.com/v1/pricing Accept:application/json
用于选择性路由的 Proxy 模式
如果你只想让某些请求通过 VPN,请使用本地 Proxy:
# Start FreeGuard with local proxy
freeguard connect
# Route specific requests through the proxy
curl --proxy socks5://127.0.0.1:1080 https://api.example.com/endpoint
# Direct requests bypass VPN
curl https://internal.company.com/api
Docker 容器 + VPN
通过 VPN 传输容器网络
将 Docker 容器流量路由通过 FreeGuard:
# Connect host to VPN
freeguard connect --server us-east
# Containers using host network will route through VPN
docker run --network host my-app:latest
Docker Compose 集成
将 VPN 连接能力加入你的开发栈:
#!/bin/bash
# dev-start.sh
freeguard connect --server us-east --json | jq -r '.status'
docker compose up -d
echo "Development stack is running through VPN"
在受限网络后构建镜像
当 docker build 需要从被阻止或很慢的镜像仓库下载包时:
freeguard connect --server us-west
docker build --network host -t my-app:latest .
freeguard disconnect
CI/CD 集成
GitHub Actions
在 CI 流水线中使用 FreeGuard CLI,在构建期间访问地理限制资源:
- name: Connect VPN
run: |
curl -fsSL https://cli.freeguard.com/install.sh | bash
freeguard login --method token --token ${{ secrets.FREEGUARD_TOKEN }}
freeguard connect --server us-east --json
适合脚本的输出
每个 FreeGuard CLI 命令都支持用于机器可读输出的 --json,以及用于生成干净日志文件的 --no-color:
# Get connection status as JSON
freeguard status --json
# {"connected": true, "server": "us-east-1", "protocol": "hysteria2", "uptime": 3600}
# List servers as JSON for programmatic selection
freeguard servers --json --region us | jq '.[0].id'
退出码
CLI 使用标准退出码,脚本可以据此进行检查:
| Exit Code | 含义 |
|---|---|
| 0 | 成功 |
| 1 | 一般错误 |
| 2 | 需要身份验证 |
| 3 | 连接失败 |
| 4 | 未找到服务器 |
freeguard connect --server us-east
if [ $? -eq 0 ]; then
echo "VPN connected, starting deployment..."
./deploy.sh
fi
日常使用技巧
- Shell alias — 将
alias vpn="freeguard connect"和alias vpnoff="freeguard disconnect"添加到你的 shell 配置文件中。 - 自动连接 — 如果你始终希望开启 VPN,可将
freeguard connect添加到你的.zshrc或.bashrc中。 - 服务器书签 — 使用
freeguard config set default-server us-east来跳过--server标志。 - 提示符中的状态 — 解析
freeguard status --json,在你的 shell 提示符中显示 VPN 状态。
下一步
- FreeGuard CLI — 安装和完整命令参考
- CLI command documentation — 每个命令和标志的详细参考
- Deploy on headless servers — 将 FreeGuard CLI 作为系统服务运行
- Pricing — 面向开发者的方案
最后更新:2026 年 3 月