WSL2 ubuntu 配置clash代理科学上网 您所在的位置:网站首页 ubuntu上网设置 WSL2 ubuntu 配置clash代理科学上网

WSL2 ubuntu 配置clash代理科学上网

2024-06-04 16:29| 来源: 网络整理| 查看: 265

在WSL2中配置ubuntu系统的科学上网 1.准备环境 WSL2 (Windows Subsystem for Linux) 怎么安装直接在Bing或者Google搜索 科学上网的工具(梯子,机场),可以支持clash的,其它的应该也行,但是作者没试过 在WSL2中安装ubuntu22.04的发行版,其它版本号也行(20.04,18.04),不过没有特殊需求在看见这篇博客之后可以放心使用22.04版本了, 2.下载clash的二进制文件

访问clash的Github仓库 image.png 选择适合自己的系统最新版的就行,老版本曾经有漏洞,我们是要在ubuntu上面安装所以选择linux-amd64版本

image.png

3.准备好clash的订阅文件

这一步其实方法有很多,大致是以下几种

直接把机场给的订阅地址下载下来,大概率就是clash的订阅链接,不建议使用网络上面各种野鸡订阅链接转换的方式 如果使用过Windows系统上面的clash for Windows,可以直接去配置文件的位置把配置复制过来 地址一般就在下面的路径下 ${USER}\.config\clash\profiles

image.png 如果有很多分不清,直接更新一下,哪个日期新就是哪个,找到后记得传到我们的Ubuntu里面

4.开始配置

现在你的ubuntu里面应该有以下2个类似的文件

# clash的二进制文件压缩包 clash-linux-amd64-v1.17.0.gz # 订阅链接文件 xxxxxx.yml

解压clash二进制压缩包,改名成clash,配置文件改成config.yaml

tar -xvf clash-linux-amd64-v1.17.0.gz # 解压完应该是一个去掉后面的.gz的一个文件例如"clash-linux-amd64-v1.17.0" mv clash-linux-amd64-v1.17.0 clash mv xxxxx.yml config.yaml

将可执行文件和配置文件分别拷贝到对应的位置

# 赋与可执行权限 chmod 755 clash # 添加到用户可执行文件目录 cp clash /usr/local/bin/clash # 创建配置文件夹 mkdir /usr/local/etc/clash # 复制配置文件到配置文件夹 cp config.yaml /usr/local/etc/clash/config.yaml

配置systemctl服务,使clash成为系统的守护进程,同时开机自启

sudo vim /etc/systemd/system/clash.service 将下面的内容粘贴进去(不要星号的两行) **************************************** [Unit] Description=Clash Service After=network.target [Service] ExecStart=/usr/local/bin/clash -d /usr/local/etc/clash [Install] WantedBy=default.target ************************************** # 重新加载systemd服务文件 sudo systemctl daemon-reload # 使Clash服务在系统启动时自动启动 sudo systemctl enable clash.service # 启动Clash服务 sudo systemctl start clash.service # 检查启动状态(可以不做,一般没啥问题) sudo systemctl status clash.service

在bashrc,zshrc等配置文件中配置代理网址

vim ~/.bashrc 或者 vim ~/.zshrc 输入下面两行 export http_proxy="127.0.0.1:7890" export https_proxy="127.0.0.1:7890" 退出编辑 source ~/.bashrc 或者 source ~/.zshrc 5.验证是否可以成功启动代理 # 安装curl工具 sudo apt install curl curl www.google.com 如果输出一大段代码,证明成功了 6.不想使用代理了,怎么还原系统设置 # 停止Clash服务 sudo systemctl stop clash.service # 禁用Clash服务,以防止其在系统启动时自动启动 sudo systemctl disable clash.service # 删除Clash的systemd服务单元文件 sudo rm /etc/systemd/system/clash.service # clash的二进制文件和配置文件不删除也行。下次想用直接重新配置systemctl就行


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有