问题背景
最近整了一台纯IPv6的HK服务器,性能不错,不过没有可用的公网 IPv4。主要还是访问Github受限,因为Github没有v6地址。
本文通过 Cloudflare WARP 给纯 IPv6 机器补一个 IPv4 出口。最终目标不是让所有流量都进入 WARP,而是让IPv4 流量 → Cloudflare WARP,IPv6 流量 → 服务器原生 IPv6 直连。
这样做的好处是,IPv6 不绕路,SSH 管理也更稳;只有机器原本无法访问的 IPv4 流量才交给 WARP 处理。
安装基础组件
安装 WireGuard、DNS 工具和常用依赖:
apt update
apt install -y wireguard-tools resolvconf curl dnsutils ca-certificates
确认 WireGuard 工具可用:
wg --version
wg-quick --version
安装 wgcf 并注册 WARP 账户
先确认机器架构:
uname -m
常见对应关系:
x86_64 → linux_amd64
aarch64 → linux_arm64
armv7l → linux_armv7
从 wgcf 的 Releases 页面下载对应架构的二进制文件,保存为 wgcf,然后安装到系统路径:
chmod +x wgcf
install -m 755 wgcf /usr/local/bin/wgcf
检查:
wgcf --help
注册 WARP 账户:
wgcf register
执行时会看到 Cloudflare Terms of Service 提示,确认后继续。成功后会在当前目录生成:
wgcf-account.toml
接着生成 WireGuard 配置:
wgcf generate
成功后会生成:
wgcf-profile.conf
把配置文件放到 WireGuard 配置目录:
install -m 600 wgcf-profile.conf /etc/wireguard/warp4.conf
只让 IPv4 走 WARP
编辑配置文件:
nano /etc/wireguard/warp4.conf
找到 [Peer] 段里的 AllowedIPs。
默认可能是:
AllowedIPs = 0.0.0.0/0, ::/0
这表示 IPv4 和 IPv6 都走 WARP。本文不需要这样做。
改成:
AllowedIPs = 0.0.0.0/0
九、启动 WARP IPv4-only 隧道
启动:
wg-quick up warp4
查看 WireGuard 状态:
wg show
查看 IPv4 路由:
ip -4 route
此时应该能看到 IPv4 默认路由已经指向 warp4。
再看 IPv6 路由:
ip -6 route
IPv6 默认路由应仍然是 VPS 原来的网关,而不是 WARP。
也可以用 route get 检查:
ip -4 route get 140.82.112.4
ip -6 route get 2606:4700:4700::1111
预期结果:
IPv4 route → dev warp4
IPv6 route → 原生网卡
验证 WARP 是否按预期工作
检查 IPv4 是否走 WARP:
curl -4 https://www.cloudflare.com/cdn-cgi/trace | grep warp
预期:
warp=on
检查 IPv6 是否保持直连:
curl -6 https://www.cloudflare.com/cdn-cgi/trace | grep warp
预期:
warp=off
如果 IPv4 是 warp=on,IPv6 是 warp=off,说明目标已经达成:
IPv4 → WARP
IPv6 → 直连
测试 GitHub:
curl -4I https://github.com
git ls-remote https://github.com/git/git.git HEAD
如果这些命令能正常返回,说明纯 IPv6 机器已经具备访问 IPv4 站点的能力。
设置开机自启
确认手动启动没有问题后,再设置开机自启:
systemctl enable wg-quick@warp4
查看服务状态:
systemctl status wg-quick@warp4 --no-pager
重启后验证:
reboot
重启完成后检查:
wg show
curl -4 https://www.cloudflare.com/cdn-cgi/trace | grep warp
curl -6 https://www.cloudflare.com/cdn-cgi/trace | grep warp
十二、回滚方法
如果配置后出现异常,可以立即关闭:
wg-quick down warp4
如果已经设置了开机自启,取消它:
systemctl disable wg-quick@warp4
删除配置:
rm -f /etc/wireguard/warp4.conf
恢复 DNS 备份:
cp /etc/resolv.conf.bak /etc/resolv.conf
如果 /etc/resolv.conf 是软链接,恢复前应先确认:
ls -l /etc/resolv.conf
十三、常见问题记录
lookup api.cloudflareclient.com on [::1]:53: connection refused
原因很明确:系统 DNS 指向 [::1]:53,但本机没有 DNS 服务。
处理方法:
cat > /etc/resolv.conf <<'EOF'
nameserver 2606:4700:4700::1111
nameserver 2606:4700:4700::1001
nameserver 2001:4860:4860::8888
options timeout:2 attempts:3
EOF
然后重新测试:
getent hosts api.cloudflareclient.com
wgcf register 无法连接
先检查 DNS,再检查 IPv6 连通性:
getent hosts api.cloudflareclient.com
curl -6I https://api.cloudflareclient.com
如果 DNS 和 IPv6 HTTPS 都不通,先不要排查 WARP。WARP 还没启动,问题一定在系统网络或 DNS。
启动后 IPv6 也走了 WARP
检查配置:
grep AllowedIPs /etc/wireguard/warp4.conf
必须是:
AllowedIPs = 0.0.0.0/0
不能包含:
::/0
只要 AllowedIPs 里有 ::/0,IPv6 默认流量就会被 WARP 接管。
GitHub 仍然访问异常
先拆开测试:
curl -4I https://github.com
curl -6I https://github.com
git ls-remote https://github.com/git/git.git HEAD
再看路由:
ip -4 route get 140.82.112.4
如果 IPv4 路由没有走 warp4,说明 WireGuard 路由没有生效。重新检查 AllowedIPs、wg show 和 wg-quick 日志。
查看日志:
journalctl -u wg-quick@warp4 --no-pager -n 100
系统查询 ::1
在实际操作中,第一步遇到了这个错误:
lookup api.cloudflareclient.com on [::1]:53: read udp [::1]:37390->[::1]:53: read: connection refused
它说明当前系统的 DNS 配置指向了本机 IPv6 loopback:
nameserver ::1
也就是说,系统把 DNS 查询交给本机的 53 端口处理。但机器上并没有 DNS 服务监听 [::1]:53,所以查询被拒绝。
先备份当前 DNS 配置:
cp /etc/resolv.conf /etc/resolv.conf.bak
临时写入可用的 IPv6 DNS:
cat > /etc/resolv.conf <<'EOF'
nameserver 2606:4700:4700::1111
nameserver 2606:4700:4700::1001
nameserver 2001:4860:4860::8888
options timeout:2 attempts:3
EOF
测试解析:
getent hosts api.cloudflareclient.com
测试 IPv6 HTTPS 连接:
curl -6I https://api.cloudflareclient.com
只要 DNS 能解析,HTTPS 能连通,就可以继续下一步。
十四、关于费用和限制
基础 WARP 通常可以免费使用。Cloudflare 在 WARP 发布说明中写到,基础 WARP 免费,并且没有带宽上限;WARP+ 是额外的付费加速版本。(The Cloudflare Blog)
但这并不代表它适合所有用途。Cloudflare 也明确说明,WARP 不是传统意义上用于选择地区、隐藏访问来源或解锁区域内容的 VPN。(The Cloudflare Blog)
实际使用中需要注意几点:
- 出口 IP 是 Cloudflare WARP 共享出口,部分网站可能会触发风控;
- 免费 WARP 不保证固定出口 IP;
- 速度取决于 VPS 到 Cloudflare 节点的 IPv6 质量;
wgcf是非官方工具,未来如果 Cloudflare 调整接口,注册或生成配置可能受到影响;- 不建议把它当作匿名代理或地区切换工具。
最终效果
配置完成后,这台机器的网络行为是:
访问 IPv6 网站:
服务器原生 IPv6 → 目标站点
访问 IPv4 网站:
服务器 IPv6 → Cloudflare WARP → 目标 IPv4 站点
验证结果应为:
curl -4 https://www.cloudflare.com/cdn-cgi/trace | grep warp
# warp=on
curl -6 https://www.cloudflare.com/cdn-cgi/trace | grep warp
# warp=off