Ubuntu18安装使用 clash-for-linux,并注册为系统服务,设置开机自启动。


一、安装配置 clash-for-linux

1.1 下载安装

克隆项目到本地,添加ghproxy.com/是为了更顺利的下载github文件。

git clone https://ghproxy.com/github.com/wanhebin/clash-for-linux.git


进入项目目录,编辑 .env 文件

cd clash-for-linux
vim .envSHELL


CLASH_URL项写入自己的订阅地址。

export CLASH_URL='xxx'


1.2 启动测试

执行命令 sudo bash start.sh ,出现如下输出即为成功。


1.3 开启系统代理

依次执行如下命令

source /etc/profile.d/clash.sh
proxy_on
proxy_off




二、将 clash 注册为系统服务,并设置开机自启动

2.1 clash 系统服务配置

创建 clash 服务配置文件

vim /etc/systemd/system/clash.service


写入以下内容。主要修改的地方就是 [service] 节点下的脚本路径(路径因人而异),其他的不用动。

[Unit]
Description=
Documentation=
After=network-online.target
Wants=
Requires=

[Service]
ExecStart=/bin/bash /root/clash-for-linux/start.sh
ExecStop=/bin/bash /root/clash-for-linux/shutdown.sh
ExecReload=/bin/bash /root/clash-for-linux/restart.sh
Type=forking

[Install]
WantedBy=multi-user.targetSHELL


2.2 启动服务测试

service clash start      # 启动服务
service clash stop # 停止服务
service clash restart # 重启服务
service clash status # 查看服务状态


2.3 设置开机自启动

执行命令:sudo systemctl enable clash




https://www.sunnyc.icu/articles/e343c2eb