在linux上使用clash的完美解决方案
jerem1ah Lv4

在linux上使用clash的完美解决方案

0x01前言

参考链接:

https://blog.zzsqwq.cn/posts/how-to-use-clash-on-linux/

https://parrotsec-cn.org/t/linux-clash-dashboard/5169

https://cn.v2ex.com/t/645149 //docker

0x02具体步骤

基于docker实现的步骤

1.目录结构 && 文件

1
2
3
4
/ui/
config.yaml
Country.mmdb
docker-compose.yml

image-20230305103445195

1
2
#ui
git clone -b gh-pages https://github.com/haishanh/yacd ui
1
2
#config.yaml
wget -O config.yaml [订阅链接]
1
2
#Country.mmdb
wget -O https://github.com/Dreamacro/maxmind-geoip/releases/download/20220412/Country.mmdb
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
#docker-compose.yml
version: '3'
services:
clash:
# ghcr.io/dreamacro/clash
# ghcr.io/dreamacro/clash-premium
# dreamacro/clash
# dreamacro/clash-premium
image: dreamacro/clash
container_name: clash
volumes:
- ./config.yaml:/root/.config/clash/config.yaml
- ./Country.mmdb:/root/.config/clash/Country.mmdb
- ./ui:/ui # dashboard volume
ports:
- "7890:7890"
- "7891:7891"
- "9090:9090" # external controller (Restful API)
# # TUN
# cap_add:
# - NET_ADMIN
# devices:
# - /dev/net/tun
restart: unless-stopped
network_mode: "bridge" # or "host" on Linux

2.配置端口

1
需要配置config.yaml的端口和docker-compose.yml的端口保持一致
1
2
3
4
5
port: 7890
socks-port: 7891
external-controller: :9090
external-ui: /ui
allow lan :true

然后,

1
docker-compose up -d

3.代理配置

法一:

1
export https_proxy=http://127.0.0.1:7781 http_proxy=http://127.0.0.1:7781 all_proxy=socks5://127.0.0.1:7782

法二:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Proxy auto start
#export https_proxy=http://127.0.0.1:7890
#export http_proxy=http://127.0.0.1:7890
#export all_proxy=socks5://127.0.0.1:7890
# Open proxy
on() {
# export https_proxy=http://127.0.0.1:1087
# export http_proxy=http://127.0.0.1:1087
# export all_proxy=socks5://127.0.0.1:1086
export https_proxy=http://127.0.0.1:7781
export http_proxy=http://127.0.0.1:7781
export all_proxy=socks5://127.0.0.1:7781
echo "HTTP/HTTPS Proxy on"
}

# Close proxy
off() {
unset http_proxy
unset https_proxy
unset all_proxy
echo "HTTP/HTTPS Proxy off"
}
1
source ~/.bashrc
1
on

法三:

1
2
3
/etc/proxychains.conf
http 127.0.0.1 7781
socks5 127.0.0.1 7782
1
proxychains4 curl https://www.google.com/
 Comments