[ PROMPT_NODE_24376 ]
networking
[ SKILL_DOCUMENTATION ]
# Tunnel 网络连接
## 连接要求
### 出站端口
Cloudflared 需要以下出站访问权限:
| 端口 | 协议 | 用途 | 必须 |
|------|----------|---------|----------|
| 7844 | TCP/UDP | 主要 Tunnel 协议 (QUIC) | 是 |
| 443 | TCP | 回退协议 (HTTP/2) | 是 |
**网络路径:**
cloudflared → edge.argotunnel.com:7844 (首选)
cloudflared → region.argotunnel.com:443 (回退)
### 防火墙规则
#### 最小化 (生产环境)
bash
# 仅出站
ALLOW tcp/udp 7844 to *.argotunnel.com
ALLOW tcp 443 to *.argotunnel.com
#### 完全 (推荐)
bash
# Tunnel 连接
ALLOW tcp/udp 7844 to *.argotunnel.com
ALLOW tcp 443 to *.argotunnel.com
# API 访问 (用于基于令牌的 Tunnel)
ALLOW tcp 443 to api.cloudflare.com
# 更新 (可选)
ALLOW tcp 443 to github.com
ALLOW tcp 443 to objects.githubusercontent.com
### IP 地址段
Cloudflare Anycast IP (Tunnel 端点):
# IPv4
198.41.192.0/24
198.41.200.0/24
# IPv6
2606:4700::/32
**注意:** 请使用 `*.argotunnel.com` 的 DNS 解析,而不是硬编码 IP。Cloudflare 可能会增加边缘节点。
## 预检检查
部署前测试连接:
bash
# 测试 DNS 解析
dig edge.argotunnel.com +short
# 测试端口 7844 (QUIC/UDP)
nc -zvu edge.argotunnel.com 7844
# 测试端口 443 (HTTP/2 回退)
nc -zv edge.argotunnel.com 443
# 使用 cloudflared 测试
cloudflared tunnel --loglevel debug run my-tunnel
# 查找 "Registered tunnel connection"
### 常见连接错误
| 错误 | 原因 | 解决方案 |
|-------|-------|----------|
| "no such host" | DNS 被拦截 | 允许端口 53 UDP/TCP |
| "context deadline exceeded" | 端口 7844 被拦截 | 允许 UDP/TCP 7844 |
| "TLS handshake timeout" | 端口 443 被拦截 | 允许 TCP 443,禁用 SSL 检测 |
## 协议选择
Cloudflared 会自动选择协议:
| 协议 | 端口 | 优先级 | 使用场景 |
|----------|------|----------|----------|
| QUIC | 7844 UDP | 第1 (首选) | 低延迟,最佳性能 |
| HTTP/2 | 443 TCP | 第2 (回退) | 防火墙拦截了 QUIC |
**强制 HTTP/2 回退:**
bash
cloudflared tunnel --protocol http2 run my-tunnel
**验证活动协议:**
bash
cloudflared tunnel info my-tunnel
# 显示带有协议类型的 "connections"
## 私有网络路由
### WARP 客户端要求
通过 WARP 访问私有 IP 的用户需要:
bash
# 出站 (WARP 客户端)
ALLOW udp 500,4500 to 162.159.*.* (IPsec)
ALLOW udp 2408 to 162.159.*.* (