Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Akityo/clashindocker

Repository files navigation

前言

软路由,openwrt,是老生常谈的内容了。但是我更加喜欢all in one,而且不喜欢用虚拟机。每次装openwrt的主要目的也只是使用其中的clash。所以我就干脆直接用docker+clash来充当软路由的功能了。其中使用到的主要工具是docker,macvlan,clash(mihomo),iptables.

创建macvlan网络

为了能够让docker启动的容器作为家庭网络中的旁路由,因此需要创建macvlan网络。 其中192.168.3.1为你局域网的网关,em1为你机器的网卡名称,这两个请根据实际情况修改。

  1. (可选)让docker监听ipv6。 编辑etc/docker/daemon.json文件
{ 
  "ipv6": true, 
  "fixed-cidr-v6": "2409:DA8:8001:7B22:200::/80" 
}

重启docker

sudo systemctl restart docker
  1. 创建macvlan 没有ipv6的版本
 docker network create -d macvlan \  
  --subnet=192.168.3.0/24 \  
  --gateway=192.168.3.1 \  
   -o parent=em1 \  
   -o macvlan_mode=bridge macnet
 

有ipv6的版本

 docker network create -d macvlan --ipv6 \  
  --subnet=192.168.3.0/24 \  
  --gateway=192.168.3.1 \  
  --subnet=2409:DA8:8001:7B22:200::/80 
  --gateway=2409:DA8:8001:7B22:200::1 \  
   -o parent=em1 \  
   -o macvlan_mode=bridge macnet

注意看含义,有的值需要变

制作docker镜像并创建容器

  1. 获取代码
git clone https://github.com/akityo/clashindocker
cd clashindocker
cp example.yml config.yml
  1. 更改地址docker-compose.yml中的ipv4_address为你的ip地址.

  2. 更改config.yml中的proxy-providerurl为你的机场订阅地址.

  3. 启动容器

docker compose up -d 
  1. 假设你的docker容器ip地址为192.168.3.23. 通过http://192.168.3.23:9090/ui/可以管理clash,进行切换节点等.后端地址为http://192.168.3.23:9090/,密码为yourpassword.

  2. 在同一个局域网下,将其他机器的网关设置为192.168.3.23就可以实现该机器的所有流量都经过clash,并且根据clash的规则进行分流.

  3. 可以不看的说明. example.yml中使用proxy-providerrule-providers来实现远端配置. 示例中是两个机场的情况.如果只有一个机场,删除其中一个和下面proxy-groups对应的部分即可.这个配置文件中需要注意以下几点.

  • 配置redir-port来让clash能够处理请求.
redir-port: 7892 
  • 配置web管理配合metacubexd来进行网页管理.
external-controller: '0.0.0.0:9090'
external-ui: ui
# RESTful API 的口令
secret: 'yourpassword'

如果有无法使用的欢迎在issue中讨论.

About

armbian

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /