Ubuntu Server 配置 Clash

本文最后更新于:2025年9月13日 下午

安装 clash

下载链接

  • 启动

    1
    2
    3
    cd /clash
    wget -O config.yaml https://your subscribe url
    ./clash -d ./

  • 设置系统代理

    1
    2
    3
    4
    5
    sudo vim ~/.zshrc
    // 加入并保存
    export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 no_proxy="localhost,127.0.0.1"
    //更新
    source ~/.zshrc

  • 启用和禁用命令

    1
    2
    3
    4
    5
    6
    #禁用全局代理
    unset http_proxy
    unset https_proxy
    #启用全局代理
    set http_proxy
    set https_proxy

设置clash开机启动

  • 创建服务文件:

    1
    sudo vim /etc/systemd/system/clash.service

  • 填入以下内容(修改路径为你的 Clash 可执行文件和配置文件路径):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    [Unit]
    Description=Clash Service
    After=network.target

    [Service]
    Type=simple
    ExecStart=/home/zzmes/workspace/tools/clash/clash -d /home/zzmes/workspace/tools/clash
    Restart=on-failure
    User=zzmes
    WorkingDirectory=/home/zzmes/workspace/tools/clash

    [Install]
    WantedBy=multi-user.target

  • 保存后执行:

    1
    2
    3
    4
    sudo systemctl daemon-reload
    sudo systemctl enable clash # 开机启动
    sudo systemctl start clash # 立即启动
    sudo systemctl status clash # 查看状态

Clash相关的管理命令

1
2
3
4
5
6
7
8
9
10
11
12
#启动Clash
sudo systemctl start clash.service
#重启Clash
sudo systemctl restart clash.service
#查看Clash运行状态
sudo systemctl status clash.service
#禁用全局代理
unset http_proxy
unset https_proxy
#启用全局代理
set http_proxy
set https_proxy

Ubuntu Server 配置 Clash
https://zzmes.github.io/2025/09/10/ubuntu-clash-md/
作者
Zzmes
发布于
2025年9月10日
许可协议