利用Cloudflare WARP为服务器实现双栈IPv4/IPv6支持

场景需求
购买的VPS仅分配有IPv4/IPv6地址,但需访问仅支持IPv4/IPv6的服务。我们可以利用Cloudflare WARP的代理隧道,为这台VPS添加双栈网络访问支持。

安装 cloudflare-warp 软件包

参考:https://pkg.cloudflareclient.com/

配置连接

注:我组网使用的是Tailscale,所以下面只考虑使用普通的WARP Client而不使用Cloudflare Zero Trust,如有需要请查看https://developers.cloudflare.com/cloudflare-one/connections/connect-devices/warp/

1
2
3
4
5
6
7
8
9
10
11
# 使用前必须先注册这个client
root@zgocloud:~# warp-cli registration new
Success
root@zgocloud:~# warp-cli registration show
Account type: Free
ID: 264065dc-95fc-400b-a8de-b89a5795275d
Device ID: 264065dc-95fc-400b-a8de-b89a5795275d
Public key: 3059301306072a8648ce3d020106082a8648ce3d03010703420004d13537da59da4a1587e0c730bc213d651d8327ef6e01da64302518fe7ac2ba826f7d712c9ed5ff8ea6e6570491b5989c4cd684a9fddf4d4ec3bcb0c6d0b6eaac
Account ID: 8856c87c48e94d92acf64f02216d26d1
License: 170D3IGe-x8NR01Z6-HtL0751B
root@zgocloud:~#
  • 管理隧道IP范围(需要添加你需要保留的IP段,比如为服务器添加IPv6访问能力就需要添加绕过IPv4全段)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 排除所有IPv4流量
warp-cli tunnel ip add-range 0.0.0.0/0

# 排除所有IPv6流量
warp-cli tunnel ip add-range ::/0

# 查看已配置的IP范围
root@zgocloud:~# warp-cli tunnel ip list
Excluded routes:
10.0.0.0/8
100.64.0.0/10
169.254.0.0/16
172.16.0.0/12
192.0.0.0/24
192.168.0.0/16
224.0.0.0/24
240.0.0.0/4
239.255.255.250/32
255.255.255.255/32
fe80::/10
fd00::/8
ff01::/16
ff02::/16
ff03::/16
ff04::/16
ff05::/16
fc00::/7
17.249.0.0/16
17.252.0.0/16
17.57.144.0/22
17.188.128.0/18
17.188.20.0/23
2620:149:a44::/48
2403:300:a42::/48
2403:300:a51::/48
2a01:b740:a42::/48
0.0.0.0/0 (CLI exclude)

检查

1
2
root@zgocloud:~# curl -6 ip.sb
2a09:bac5:636a:1173::2bd:d4