天涯随风
天涯随风
发布于 2026-03-13 / 4 阅读
0
0

无桌面无Root搭建Linux环境下科学上网

一、安装 Clash

现在基本都用 clash.meta

1.1 下载

mkdir -p /opt/clash
cd /opt/clash

wget https://github.com/MetaCubeX/mihomo/releases/latest/download/mihomo-linux-amd64
mv mihomo-linux-amd64 clash
chmod +x clash

1.2 创建配置

mkdir -p /opt/clash/config
# 将你在其他平台使用的配置文件导出另存为
/opt/clash/config/config.yaml

对config.yaml开头做如下修改:

mixed-port: 7890
socks-port: 7891
allow-lan: true
mode: rule
log-level: warning
external-controller: '0.0.0.0:9090'
external-ui: ./ui

二、安装Yacd面板

2.1 下载

cd /opt/clash
wget https://github.com/haishanh/yacd/archive/gh-pages.zip
unzip gh-pages.zip
mv yacd-gh-pages ui

目录结构如下:

/opt/clash
 ├─ clash
 ├─ config
 │   └─ config.yaml
 └─ ui

三、启动测试

./clash -d ./config

如果成功,会看到:

External controller listening at: 0.0.0.0:9090

四、访问 Yacd

浏览器打开:

http://服务器IP:9090/ui

输入对应secret即可。

五、启动Clash

5.1 配置 systemd 开机启动(有root权限)

sudo touch /etc/systemd/system/clash.service

内容:

[Unit]
Description=Clash Proxy
After=network.target

[Service]
Type=simple
ExecStart=/opt/clash/clash -d /opt/clash/config
Restart=always

[Install]
WantedBy=multi-user.target

启动:

sudo systemctl daemon-reload
sudo systemctl enable clash
sudo systemctl start clash
# 查看状态
sudo systemctl status clash

5.2 无Root权限

nohup ./clash -d ./config > clash.log 2>&1 &

六、代理使用

export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

取消代理:

unset http_proxy
unset https_proxy
unset HTTP_PROXY
unset HTTPS_PROXY

验证:

env | grep -i proxy

七、验证代理成功

curl -x http://127.0.0.1:7890 https://ipinfo.io

如果返回国外IP,则证明Clash运行正常,代理成功


评论