ipv6通过cloudflare建立tunnels搭建v2ray

最近尝试了一下cloudflare的zero零信任服务,里面的tunnels真的是太棒了。

最近也顺利撸了2台scaleway家的星尘服务器小鸡,虽然是only ipv6,但是便宜无流量上限啊,量大管饱。非常的值得入手。

现在开始搭建,至于如何获得星尘小鸡不再另说,网上有很多教程。

这里提的是如何通过tunnels访问自己搭建的v2端口,可以通过隧道传输流量,达到出国效果。

环境:debian11

配置:1c1g

修改dns并一键DD Debian

修改dns

echo -e "nameserver 2001:67c:2b0::4\nameserver 2001:67c:2b0::6" > /etc/resolv.conf

一键dd

bash <(wget --no-check-certificate -qO- 'https://raw.githubusercontent.com/MoeClub/Note/master/InstallNET.sh') -d 11 -v 64 -p "password须修改" -port "22" --ip-addr 你的ipv6地址/64 --ip-gate 网关地址 --ip-mask 255.255.255.254 --ip-dns 2001:67c:2b0::4

估计要等待10分钟到1小时,看机器网络和性能,一般都很快,我的1c1g都能在15分钟dd完。

Warp配置IPv4

wget -N https://raw.githubusercontent.com/fscarmen/warp/main/menu.sh && bash menu.sh 4

上面的命令最后的参数4,是指只做WARP IPv4,让机器可以访问ipv4的网站,可以参考下面的参数。或者访问脚本项目地址获取帮助:https://github.com/fscarmen/warp

h帮助
4原无论任何状态 -> WARP IPv4
4 lisence name把 WARP+ Lisence 和设备名添加进去,如 bash menu.sh 4 N5670ljg-sS9jD334-6o6g4M9F Goodluck
6原无论任何状态 -> WARP IPv6
d原无论任何状态 -> WARP 双栈
oWARP 开关,脚本主动判断当前状态,自动开或关
u卸载 WARP
n断网时,用于刷WARP网络 (WARP bug)
b升级内核、开启BBR及DD

按脚本一步一步来就能完成warp配置了,其中步骤我选了ipv6优先,毕竟这是only ipv6的小鸡

#启动和开机启动命令备用

systemctl start wg-quick@wgcf

systemctl enable wg-quick@wgcf

安装v2ray

安装之前先停掉warp,不然会识别为ipv4为代理地址

systemctl stop wg-quick@wgcf
或者一键脚本自带的命令
wget -N https://raw.githubusercontent.com/fscarmen/warp/main/menu.sh && bash menu.sh o

这里也是用到一个github大神的一键脚本

bash <(curl -s -L https://git.io/v2ray.sh)

我选择安装的是ws+tls模式,有需要其他的自己选,需要记住配置过程的端口,在后面的tunnels要用到。

安装好之后,再把warp开回来

systemctl start wg-quick@wgcf
或者一键脚本自带的命令
wget -N https://raw.githubusercontent.com/fscarmen/warp/main/menu.sh && bash menu.sh o

到这里完成之后,现在就可以试一下,去电脑的特别软件里配置一下能不能用了。

如果够用或者速度可以,就不用往下折腾了啦。



配置tunnels

1、安装cloudflare

curl -L --output cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb && 

sudo dpkg -i cloudflared.deb

2、登录校验

cloudflared tunnel login

前提是在cloudflare已经绑定了域名,然后在给到的链接去到浏览器访问授权

3、创建隧道

cloudflared tunnel create mytn

隧道命名一般以用途为命名,我这里填mytn

4、查看创建的隧道id

cloudflared tunnel list

把ID那串类似a16ggc3a-0eea-4bbb-9a85-407caf9105b6的记住

5、新建一个dns域名指向

下面的命令最后需要填一个你绑定在cloudflare的二级域名,我这里随意填了一个v2-tn.666666.com与mytn隧道绑定,执行之后到cloudflare里的域名dns去看会多了一个cname的指向。

cloudflared tunnel route dns mytn v2-tn.666666.com

6、修改配置

vim ~/.cloudflared/config.yml

填入下面,修改tunnel、credentials-file用到的是上面查到的隧道ID;修改hostname为上一步配置的域名;修改service: tcp://localhost:端口,端口为v2ray配置的侦听端口(不是443)

tunnel: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
credentials-file: /home/yunyuyuan/.cloudflared/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.json
ingress:
  - hostname: v2ray-sw-cf.yunyuyuan.net
    service: tcp://localhost:18686
  - service: http_status:404

7、测试一下

cloudflared tunnel --edge-ip-version=6 run mytn

没有报错信息就ok,ctrl+c结束掉这个

8、把程序安装成服务

cloudflared service install

9、此时在/etc/systemd/system会生成cloudflared.service文件,需要小修改一下

vi /etc/systemd/system/cloudflared.service

把ExecStart改为
ExecStart=/usr/bin/cloudflared --no-autoupdate --config /etc/cloudflared/config.yml tunnel --edge-ip-version 6 run

主要改动是因为用到ipv6,参考https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/local/local-management/arguments/#edge-ip-version/issues/664,当然也可以配置为

--edge-ip-version auto

10、重载配置,重启服务,开机启动

systemctl daemon-reload
systemctl restart cloudflared
systemctl enable cloudflared

配置客户端

按一键安装的配置填写就行。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注