開發者的 Terminal Proxy 工作流程
FreeGuard CLI 透過將流量導向加密的 VPN 隧道,將你的終端機轉變為安全的開發環境。無論你是在受限網路中複製儲存庫、跨區域除錯 API,還是透過安全通道部署容器,CLI 都能整合到你已經在使用的工具中 — git、ssh、curl、docker 等等。

開發者的 Terminal Proxy 工作流程

FreeGuard CLI 透過將流量導向加密的 VPN 隧道,將你的終端機轉變為安全的開發環境。無論你是在受限網路中複製儲存庫、跨區域除錯 API,還是透過安全通道部署容器,CLI 都能整合到你已經在使用的工具中 — git、ssh、curl、docker 等等。

為什麼開發者需要 Terminal 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 進行測試

將你的 API 請求透過 VPN 路由,以便從不同地區進行測試:

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 需要從被封鎖或速度緩慢的 registry 下載套件時:

freeguard connect --server us-west
docker build --network host -t my-app:latest .
freeguard disconnect

CI/CD 整合

GitHub Actions

在你的 CI pipeline 中使用 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'

Exit Codes

CLI 使用標準 Exit Codes,腳本可以檢查:

Exit Code 意義
0 成功
1 一般錯誤
2 需要驗證
3 連線失敗
4 找不到伺服器
freeguard connect --server us-east
if [ $? -eq 0 ]; then
  echo "VPN connected, starting deployment..."
  ./deploy.sh
fi

日常使用技巧

  1. Shell alias — 將 alias vpn="freeguard connect"alias vpnoff="freeguard disconnect" 加入你的 shell profile。
  2. 自動連線 — 如果你總是希望 VPN 保持開啟,請將 freeguard connect 加入你的 .zshrc.bashrc
  3. 伺服器書籤 — 使用 freeguard config set default-server us-east 來略過 --server 參數。
  4. 提示字元中的狀態 — 解析 freeguard status --json,在你的 shell 提示字元中顯示 VPN 狀態。

下一步

最後更新:2026 年 3 月