Coder Social home page Coder Social logo

clashindocker's Introduction

前言

软路由,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/UntaggedRui/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中讨论.

clashindocker's People

Contributors

untaggedrui avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.