ArchLinux 上使用 Clash

Clash 是 Go 语言实现的,跨平台代理工具,支持规则分流等等。

官方 Github:https://github.com/Dreamacro/clash/releases

安装 Clash

Linux 下载对应的 linux-amd64 即可。
下载对应的二进制,比如默认放到~/software 目录,在终端进入该目录。

1
2
3
wget https://github.com/Dreamacro/clash/releases/download/v1.11.8/clash-linux-amd64-v1.11.8.gz

gzip -d clash-linux-amd64-v1.11.8.gz

移动到 /usr/local/bin 目录并给予可执行权限

1
2
sudo mv clash-linux-amd64-v1.11.8 /usr/local/bin/clash
sudo chmod +x /usr/local/bin/clash

启动 Clash

clash 启动后会在~/.config/clash 目录生成配置文件。

1
2
# 此时命令行会进入阻塞状态
clash

打开新的终端查看是否生成配置文件 (3 gewenjian)

1
cd ~/.config/clash

image

设置开机自启

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

添加以下内容

1
2
3
4
5
6
7
8
9
[Unit]
Description=Clash Daemon

[Service]
ExecStart=/usr/local/bin/clash -d /home/[用户名]/.config/clash
Restart=on-failure

[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
## 每只修改 xxx.service 文件都需要重启此服务
sudo systemctl daemon-reload
# 启动服务
sudo systemctl start clash.service
# 设置开机自启
sudo systemctl enable clash.service
# 查看服务状态
sudo systemctl status clash.service

远程管理端口

Clash 提供了默认的 9090 端口作为远端管理端口,在配置中可以看到:

1
vim ~/.config/clash/config.yaml
1
2
# 远端管理端口
external-controller: '127.0.0.1:9090'

可以使用 Clash 远程管理的页面进行管理: http://clash.razord.top/#/proxies

如果访问失败可以启动项目 dashboard:https://github.com/Dreamacro/clash-dashboard

image

这个页面要求提供,Host,Port,Secret 三个输入:

  • Host: 127.0.0.1
  • Port: 9090
  • Secret: 配置文件配置的 secret

其中 Secret 是在配置文件中通过:

1
2
# 可为空
secret: 'xxx'

添加 Proxy

我自己所用的 Proxy 是 PuCloud

1
2
3
4
5
cd ~/.config/clash
# 备份.config.yaml
mv config.yaml config.yaml.backup

wget [订阅地址] -O config.yaml

登录 https://clash.razord.top/#/proxies 代理一栏选择代理规则

系统代理

image-20230118150509345

命令行代理 proxychains

安装 proxychains

1
yay -S proxychains

修改配置文件

1
2
3
4
5
sudo vim /etc/proxychains.conf

# 修改文件最后一行为
# 端口是 Socks5 代理端口
socks5 127.0.0.1 7891

使用

1
proxychains4 curl www.google.com

使 yay 支持 proxychains

由于 go 语言问题,直接使用 proxychains yay 命令会报网络错误 1.
需要使用 gcc-go 重新编译 yay 和 proxychains, 命令如下:

1
2
3
4
5
6
7
8
# 安装 gcc-go 替代默认的 go 
yay -S gcc-go

# 克隆 PKGBUILD 并使用 makepkg 重新编译 yay:
git clone https://aur.archlinux.org/yay.git
cd yay
# 可以会下载不了就使用代理
proxychains4 makepkg -si

手动设置代理

1
2
3
4
5
vim proxy-terminal

#! /bin/bash
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
1
ln -s /home/likfees/Software/script/proxy-terminal /usr/local/bin

使用

1
source proxy-terminal

Github 代理

1. http 代理

1
2
3
4
5
6
vim ~/.gitconfig

[http]
proxy = socks5://127.0.0.1:7891
[https]
proxy = socks5://127.0.0.1:7891

2. ssh 代理

1
2
3
4
5
6
7
8
9
yay -S openbsd-netcat
vim .ssh/config

Host github.com
HostName ssh.github.com
User git
Port 443
# 走 socks5 代理(如 Shadowsocks)
ProxyCommand nc -v -x 127.0.0.1:7891 %h %p

chrome 代理

方式一

Archlinux 使用系统代理无法直接应用于 Chrome

这里我们打开 /usr/bin/google-chrome-stable 发现检测了一个 chrome 启动参数文件的,具体这样做:

1
echo "-proxy-server=127.0.0.1:7890" > ~/.config/chrome-flags.conf

重启浏览器即可

方式二

下载 Proxy-SwitchyOmega-Chromium 插件

1
2
3
4
cd ~/software
wget https://proxy-switchyomega.com/file/Proxy-SwitchyOmega-Chromium-2.5.15.crx

unzip Proxy-SwitchyOmega-Chromium-2.5.15.crx -d Proxy-SwitchyOmega-Chromium-2.5.15

Chrome 安装插件
浏览器访问 chrome://extensions/ 进入插件管理

  1. 开启开发模式
  2. 加载刚刚解压的 Proxy-SwitchyOmega
  3. 修改 Proxy-SwitchyOmega 代理规则
    1
    https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt
    image