转载 - IPv6 Only VPS 接入 warp

  • ipv6 only vps 接入 warp 实现双栈访问网络

  • 资料来源:

    https://p3terx.com/archives/use-cloudflare-warp-to-add-extra-ipv4-or-ipv6-network-support-to-vps-servers-for-free.html
    https://www.oplog.cn/archives/1112.html

  • 更新

    1
    2022.12.11 初始

导语

黑五贪便宜入了 ipv6 only 的服务器,其他都还好,奈何 GitHub 还不支持 ipv6 访问..

DNS64 其实可用解决大部分需求,但有时非常不稳定(原因未知) 就有了 访问 ipv4 的需要.

其实就是接入 warp ,让 vps 连接到 cloudflare 的内网,再访问 ipv4 网络.

这一篇是纯转载

正文

建议先配置好 dns64, /etc/resolv.conf 换成下面内容

1
2
nameserver 2001:67c:2b0::4
nameserver 2001:67c:2b0::6

安装 wireguard

  • 这里是 debian kvm 且初装机器,其他虚拟化参考 -> Debian Linux VPS 服务器 WireGuard 安装教程
  • 实在不行还可以 -> wireguard-go: curl -fsSL git.io/wireguard-go.sh | sudo bash
1
2
3
4
5
6
7
8
9
# 更新环境.安装依赖
apt update
apt install curl sudo lsb-release -y
# 安装wireguard
echo "deb http://deb.debian.org/debian $(lsb_release -sc)-backports main" sudo tee /etc/apt/sources.list.d/backports.list
sudo apt update
sudo apt install net-tools iproute2 openresolv dnsutils -y
sudo apt install wireguard-tools --no-install-recommends
sudo apt install wireguard

wgcf 非官方的 Cloudflare WARP 的 CLI 工具,模拟注册生成配置

1
2
# 安装WGCF
curl -fsSL git.io/wgcf.sh sudo bash
1
2
3
4
# 注册 WARP 生成 wgcf-account.toml
wgcf register
# 生成 WireGuard 配置文件 wgcf-profile.conf
wgcf generate
  • wgcf-account.tomlwgcf-profile.conf 注意备份

编辑 wgcf-profile.conf

1
2
3
4
5
6
7
8
9
10
11
[Interface]
PrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Address = 172.16.0.2/32
Address = fd01:5ca1:ab1e:8a15:6634:bea7:4f74:47d9/128
DNS = 1.1.1.1
MTU = 1280
[Peer]
PublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AllowedIPs = 0.0.0.0/0
AllowedIPs = ::/0
Endpoint = engage.cloudflareclient.com:2408
  • 删除 AllowedIPs = ::/0 ,这一条让 warp 不再接管 ipv6 流量
  • DNS 换成纯 ipv6 dns.因为这一条会覆盖系统 dns,防止 warp 网络故障导致基本 dns 都出问题.
  • Endpointengage.cloudflareclient.com 替换为 [2606:4700:d0::a29f:c001]

启用 warp

1
2
3
4
sudo cp wgcf-profile.conf /etc/wireguard/wgcf.conf
sudo systemctl start wg-quick@wgcf
sudo systemctl enable wg-quick@wgcf
echo 'precedence ::ffff:0:0/96 100' sudo tee -a /etc/gai.conf
  • 这里是开机启动
  • ipv4 优先

验证

1
ping ipv4.google.com

更详细配置 -> Cloudflare WARP 给 Linux VPS 云服务器添加原生 IPv4/IPv6 双栈网络

结语

本机访问 ipv4 自然是没有遇到任何故障.

但 docker 编译镜像时只能选择 network host 否则 ipv4 还是无法访问

  • 也正常,编译镜像也就是起了另外的容器,与 host 不是一个网络栈.