Linux科学上网

创建目录

在命令行中输入以下命令

1
mkdir clash-linux && cd clash-linux

下载clash

github链接
根据你所使用的Linux的版本选择对应的下载,x86的Linux下载amd64版本即可.
右键复制链接地址,输入以下命令

1
wget -O clash.gz <你所复制的链接地址>

解压到当前文件夹

1
gzip -f clash.gz -d

给解压出来的文件赋予可执行权限

1
chmod +x clash

执行clash

1
./clash

然后退出程序,在~/.config/mihomo/生成两个文件:cache.db config.yaml

下载Country.mmdb GeoSite.dat

~/.config/mihomo/目录下执行

1
2
wget https://github.com/Dreamacro/maxmindgeoip/releases/latest/download/Country.mmdb
wget -O GeoSite.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/download/202406152210/geosite.dat

下载clash配置文件

在你购买机场的网站获取订阅链接.
推荐一个便宜好用的机场链接
~/.config/mihomo/目录下执行

1
wget -O ~/.config/mihomo/config.yaml  <你的订阅链接>

添加启动脚本

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash

# 检查是否传递了参数
if [ -z "$1" ]; then
echo "请传递一个参数:start, stop 或 restart"
exit 1
fi

# 定义 Clash 的路径
CLASH_PATH="/opt/clash/clash-linux"

# 检查 Clash 是否存在
if [ ! -f "$CLASH_PATH" ]; then
echo "找不到 Clash 可执行文件:$CLASH_PATH"
exit 1
fi

# 启动 Clash
start_clash() {
echo "正在启动 Clash..."
"$CLASH_PATH" &
if [ $? -eq 0 ]; then
echo "Clash 已启动"
else
echo "启动 Clash 失败"
fi
}

# 停止 Clash
stop_clash() {
echo "正在停止 Clash..."
pkill -f "$CLASH_PATH"
if [ $? -eq 0 ]; then
echo "Clash 已停止"
else
echo "停止 Clash 失败"
fi
}

# 重启 Clash
restart_clash() {
stop_clash
start_clash
}

# 根据传递的参数执行相应的操作
case "$1" in
start)
start_clash
;;
stop)
stop_clash
;;
restart)
restart_clash
;;
*)
echo "无效的参数:$1"
echo "请使用 start, stop 或 restart"
exit 1
;;
esac

exit 0

保存为control.sh,并且使用chmod +x control.sh赋予可执行权限,执行./control.sh start即可开启clash服务.


Linux科学上网
https://blog.hasong.top/2024/06/16/Linux科学上网/
Author
hasong
Posted on
June 16, 2024
Licensed under