Loading... <div class="tip share">请注意,本文编写于 756 天前,最后修改于 729 天前,其中某些信息可能已经过时。</div> ## 前言 有些地方的解锁机器十分难找到,要不只能用DNS解锁,但是最近我在网上看到有种方法可以使用cloudflare的服务解锁全区流媒体,理论上你的IP归属地在哪里就可以解锁哪里的流媒体服务,但是warp账户的申请对IP有点限制,找个好点的机器就行,本文仅用于交流学术分享,请勿用于违法用途,大厂的服务还是请大家不要滥用,且用且珍惜。 ## 正文 首先申请Warp账户以及生成配置文件,这里我们用到了一个开源项目[WGCF](https://github.com/ViRb3/wgcf) 首先下载解压运行二进制文件。 ### 注册Wrap并且申请配置文件 ``` #弄个文件夹方便管理相关文件 mkdir wgcf cd wgcf #下载对应程序 wget -O wgcf https://github.com/ViRb3/wgcf/releases/download/v2.2.3/wgcf_2.2.3_linux_amd64 #添加执行权限 chmod +x wgcf ``` ``` #注册WARP账户 ./wgcf register #生成WireGuard配置文件 ./wgcf generate ``` 然后目录下会有个wgcf-profile.conf的配置文件,**其中xxx是你自己配置文件里的内容,记得修改** ``` [Interface] PrivateKey = xxx Address = 172.16.0.2/32 Address = fd01:5ca1:ab1e:8630:3282:88f8:eeb8:1b1c/128DNS = 1.1.1.1,2606:4700:4700::1111 MTU = 1280 [Peer] PublicKey = xxx AllowedIPs = ::/0 Endpoint = engage.cloudflareclient.com:2408 ``` ### 修改配置文件 我们需要自定义Wireguard的配置文件,如果把生成的直接使用的话会接管全局流量,会导致连不上服务器,所以我们要选择是接管ipv4或者是ipv6,如果接管ipv6的话,配置应该是这样的 #### IPV6 ``` [Interface] PrivateKey = xxx Address = 172.16.0.2/32 Address = fd01:5ca1:ab1e:8630:3282:88f8:eeb8:1b1c/128 DNS = 2001:4860:4860::8844 DNS = 1.1.1.1 MTU = 1280 [Peer] PublicKey = xxx #AllowedIPs = 0.0.0.0/0 AllowedIPs = ::/0 #Endpoint = [2606:4700:d0::a29f:c001]:2408 Endpoint = 162.159.192.1:2408 ``` #### IPV4 ``` [Interface] PrivateKey = xxx Address = 172.16.0.2/32 Address = fd01:5ca1:ab1e:8630:3282:88f8:eeb8:1b1c/128 DNS = 2001:4860:4860::8844 DNS = 1.1.1.1 MTU = 1280 [Peer] PublicKey = xxx AllowedIPs = 0.0.0.0/0 #AllowedIPs = ::/0 Endpoint = [2606:4700:d0::a29f:c001]:2408 #Endpoint = 162.159.192.1:2408 ``` 也就是说,如果我们想要接管ipv4那就放行`AllowedIPs = 0.0.0.0/0`,那么ipv6就是`AllowedIPs = ::/0`,当然我们也要相应的更改endpoint,如果是使用ipv6那endpint应该是ipv4格式的,v6同理。 ### 安装前准备工作 这里用DigitalOcean的debian 10系统进行演示,这个系统比较奇怪,要自己升级下内核才能安装linux-header,**如果你的系统可以安装linux-header那直接跳过这一步** #### 修改更新源 ``` sudo sh -c 'echo -e "deb http://http.debian.net/debian stretch-backports main\ndeb-src http://http.debian.net/debian stretch-backports main" > /etc/apt/sources.list.d/sources.list.bak' ``` #### 更新package ``` sudo apt-get update sudo apt-get dist-upgrade ``` #### 安装新版内核镜像 ``` sudo apt-cache search linux-image sudo apt-get install -t stretch-backports linux-image-amd64 ``` #### 重启系统 ``` sudo update-grub sudo apt-get clean sudo reboot ``` ## 开始安装WireGuard #### 先安装linux-headers ``` apt update apt install linux-headers-$(uname -r) -y ``` 然后安装wireguard ``` echo "deb http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/unstable.list printf 'Package: *\nPin: release a=unstable\nPin-Priority: 150\n' > /etc/apt/preferences.d/limit-unstable apt update apt install wireguard-dkms wireguard-tools resolvconf -y ``` 应该没有报错了,然后就进行一系列的设置 ``` #开启ipv4流量转发 echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf sysctl -p #创建并进入WireGuard文件夹 mkdir -p /etc/wireguard && chmod 0777 /etc/wireguard cd /etc/wireguard umask 077 #生成服务器和客户端密钥对 wg genkey | tee server_privatekey | wg pubkey > server_publickey wg genkey | tee client_privatekey | wg pubkey > client_publickey ``` 到这里wireguard就安装的差不多了,然后就编辑配置文件了,把之前设置好的配置新建到wgcf.cong配置文件,输入`vi /etc/wireguard/wgcf.conf`,把配置粘贴进去再按`:wq`就可以保存了 然后我们要检查内核模块是不是加载上了,如果报错那就是linux-herader没装好 ``` #加载内核模块 modprobe wireguard #检查WG模块加载是否正常 lsmod | grep wireguard ``` 如果你是选择出口优先走ipv6需要进行配置,编辑 /etc/gai.conf 文件(没有的话就新建),修改为以下内容: ``` label ::1/128 0 label ::/0 1 label fd01::/16 1 label 2002::/16 2 label ::/96 3 label ::ffff:0:0/96 4 label fec0::/10 5 label fc00::/7 6 label 2001:0::/32 7 precedence ::1/128 50 precedence ::/0 40 precedence fd01::/16 40 precedence 2002::/16 30 precedence ::/96 20 precedence ::ffff:0:0/96 10 ``` 然后再把系统dns设置为ipv6地址的dns应该就可以了 ### 启动Wireguard 建议不要一开始就设置开机自启,配置错了有可能连不上ssh,但是重启就好,设置了自启就没办法了,只能重装 #### 设置开机自启 ``` systemctl enable wg-quick@wgcf ``` #### 启动 ``` #启动WireGuard wg-quick up wgcf #停止WireGuard wg-quick down wgcf #查看WireGuard运行状态 wg ``` ## 注意 本文参考了其他博主写的内容,然后进行了整合,看看他们的文章也许对你有帮助 https://luotianyi.vc/5252.html https://luotianyi.vc/4500.html https://qiaodahai.com/update-debian-kernel.html https://loukky.com/archives/1440 https://ivanzz1001.github.io/records/post/linuxops/2018/11/14/linux-route Last modification:March 23, 2021 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 0 If you think my article is useful to you, please feel free to appreciate
2 comments
十年之约-虫洞穿梭而来,学习到了!
感谢分享 赞一个