Docker/linux/斐讯设备/系统运维

【N1和Armbian】十一、在 docker 中使用 mihomo

daimafengzi · 9月4日 · 2025年 · · · · · · · · 本文共6493个字 · 预计阅读22分钟 14次已读

须知

本文默认您已经安装好了 docker 并了解 docker 的一些基本概念
如果您是纯命令行环境,本文将默认你会命令行最基本的使用(如创建文件/文件夹、编辑文本等)
mihomo 是 clash 的一个分支,也是目前使用最广泛的分支,各平台许多客户端使用的核心均为 mihomo,或者它曾经还有个可能更多人听过的名字叫 mihomo meta。
需要说明的是 mihomo 与最原始的 clash 本身都是一个纯命令行程序,这意味着它本身没有图形界面,但本文会讲到如何配置 mihomo 的 webUI,以便日常使用。

编写 mihomo 配置文件

新建一个空文件夹命名为 mihomo,在其中新建文本文档 config.yaml
可参考下方模板来创建您自己的配置文件,模板参考自官方文档,如果你希望了解配置文件的具体规则,同样请参考官方文档。(本文最后有链接)
该模板中必须要修改的是第 19、20 行与 25 行,根据实际情况进行填写,修改模板后不含模板中的尖括号。其中节点提供者名称可自由填写,用于程序区分多个订阅;节点名称前缀会在显示节点信息时插入到原始节点名称前,便于自己区分不同订阅的节点。
第 1 行为代理端口设置,第 6 行为外部控制端口设置(如使用 webUI 控制 mihomo)如有需要可自行更改。

# =================== 基础设置 ===================
mixed-port: 7890
allow-lan: true
bind-address: '*'
mode: rule
log-level: info
external-controller: '0.0.0.0:9090'

# =================== Profile 与连接优化 ===================
profile:
  store-selected: true
  store-fake-ip: true

unified-delay: true
tcp-concurrent: true
global-client-fingerprint: chrome

# =================== 嗅探(可提升分流准确度) ===================
sniffer:
  enable: true
  sniffing:
    - tls
    - http
  parse-pure-ip: true
  override-destination: true
  force-dns-mapping: true
  skip-domain:
    - "+.apple.com"
    - "+.icloud.com"
    - "+.alipay.com"
    - "+.tenpay.com"
    - "+.mch.weixin.qq.com"
    - "+.bankofchina.com"
    - "+.icbc.com.cn"
    - "+.ccb.com"
    - "+.mi.com"
    - "+.meituan.com"
    - "+.meituan.net"
    - "+.jd.com"
    - "+.taobao.com"
    - "+.tmall.com"
    - "+.qq.com"
    - "+.weixin.qq.com"

# =================== TUN 模式 ===================
tun:
  enable: false
  stack: mixed
  dns-hijack:
    - "any:53"
    - "tcp://any:53"
  auto-route: true
  auto-redirect: true
  auto-detect-interface: true

# =================== 代理节点提供者 ===================
proxy-providers:
  自己:
    url: "http://192.168.8.89:8199/all.yaml"
    type: http
    interval: 3600
    health-check:
      enable: true
      url: "https://www.gstatic.com/generate_204"
      interval: 300
      timeout: 5000
      lazy: true
      method: GET
      disable-keepalive: true
    override:
      additional-prefix: "MY_"

# =================== 本地代理 ===================
proxies:
  - name: "🎯 直连"
    type: direct
    udp: true
  - name: "🛑 拒绝"
    type: reject
    udp: true

# =================== Geo 数据源 ===================
geodata-mode: true
geox-url:
  geoip: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.dat"
  geosite: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat"
  mmdb: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country-lite.mmdb"
  asn: "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/GeoLite2-ASN.mmdb"

# =================== DNS 设置(优化版)===================
dns:
  enable: true
  ipv6: false
  respect-rules: true
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  fake-ip-filter:
    - "+.lan"
    - "+.local"
    - "localhost"
    - "+.market.xiaomi.com"
  default-nameserver:
    - 223.5.5.5
    - 119.29.29.29
  nameserver:
    - https://120.53.53.53/dns-query
    - https://223.5.5.5/dns-query
  fallback:
    - https://cloudflare-dns.com/dns-query # 速度快
    - https://dns.google/dns-query
    - https://1.1.1.1/dns-query
  proxy-server-nameserver:
    - https://cloudflare-dns.com/dns-query
    - https://dns.google/dns-query
  fallback-filter:
    geoip: true
    geoip-code: CN
    ipcidr:
      - 240.0.0.0/4
      - 0.0.0.0/8
  nameserver-policy:
    "geosite:cn,private":
      - https://120.53.53.53/dns-query
      - https://223.5.5.5/dns-query
    "geosite:geolocation-!cn":
      - https://cloudflare-dns.com/dns-query
      - https://dns.google/dns-query

# =================== 代理组 (Proxy Groups) - 【关键修改】====================
proxy-groups:
  # --- 主策略组:必须只包含真实代理节点 ---
  - name: "PROXY"
    type: url-test
    url: "https://www.gstatic.com/generate_204"
    interval: 300
    tolerance: 200
    timeout: 5000
    method: GET
    disable-keepalive: true
    use: ["自己", "星链", "翻墙侠", "IKUUU"]  # 所有订阅中自动选最快可用节点
    lazy: true

  # --- 地区分组:自动按地区测速选择最优节点 ---
  - name: "🇭🇰 香港"
    type: url-test
    use: ["自己", "星链", "翻墙侠", "IKUUU"]
    filter: "(?i)港|hk|hongkong|🇭🇰"
    url: "https://cp.cloudflare.com/generate_204"
    interval: 300
    tolerance: 150
    timeout: 5000
    lazy: true

  - name: "🇹🇼 台湾"
    type: url-test
    use: ["自己", "星链", "翻墙侠", "IKUUU"]
    filter: "(?i)台|tw|taiwan|🇹🇼"
    url: "https://cp.cloudflare.com/generate_204"
    interval: 300
    tolerance: 150
    timeout: 5000
    lazy: true

  - name: "🇯🇵 日本"
    type: url-test
    use: ["自己", "星链", "翻墙侠", "IKUUU"]
    filter: "(?i)日|jp|japan|🇯🇵"
    url: "https://www.gstatic.com/generate_204"
    interval: 300
    tolerance: 150
    timeout: 5000
    lazy: true

  - name: "🇺🇸 美国"
    type: url-test
    use: ["自己", "星链", "翻墙侠", "IKUUU"]
    filter: "(?i)美|us|united.?states|🇺🇸"
    url: "https://www.gstatic.com/generate_204"
    interval: 300
    tolerance: 150
    timeout: 5000
    lazy: true

  - name: "🇸🇬 新加坡"
    type: url-test
    use: ["自己", "星链", "翻墙侠", "IKUUU"]
    filter: "(?i)新|sg|singapore|🇸🇬"
    url: "https://1.1.1.1/cdn-cgi/trace"
    interval: 300
    tolerance: 150
    timeout: 5000
    lazy: true

  - name: "🌍 其它地区"
    type: url-test
    use: ["自己", "星链", "翻墙侠", "IKUUU"]
    filter: "(?i)(?!.*(港|台|日|美|新|hk|tw|jp|us|sg)).*"
    url: "https://www.gstatic.com/generate_204"
    interval: 300
    tolerance: 150
    timeout: 5000
    lazy: true

  # --- 功能性策略组 ---
  - name: "🇨🇳 国内"
    type: select
    proxies:
      - "🎯 直连"

  - name: "📹 国外媒体"
    type: select
    proxies:
      - "🔄 自动选择"
      - "🇺🇸 美国"
      - "🇸🇬 新加坡"
      - "🇭🇰 香港"
      - "🇹🇼 台湾"
      - "🇯🇵 日本"
      - "🌍 其它地区"
      - "PROXY"

  - name: "💬 社媒通讯"
    type: select
    proxies:
      - "🔄 自动选择"
      - "🇺🇸 美国"
      - "🇸🇬 新加坡"
      - "🇯🇵 日本"
      - "🇭🇰 香港"
      - "PROXY"

  - name: "📺 B站"
    type: select
    proxies:
      - "🇭🇰 香港"
      - "🇹🇼 台湾"
      - "🇸🇬 新加坡"
      - "🇺🇸 美国"
      - "🎯 直连"

  - name: "🎬 Disney+"
    type: select
    proxies:
      - "🇸🇬 新加坡"
      - "🇺🇸 美国"
      - "🇭🇰 香港"
      - "🇯🇵 日本"
      - "🌍 其它地区"
      - "PROXY"

  - name: "🎬 HBO"
    type: select
    proxies:
      - "🇺🇸 美国"
      - "🇸🇬 新加坡"
      - "🇭🇰 香港"
      - "🌍 其它地区"
      - "PROXY"

  - name: "🎬 Prime Video"
    type: select
    proxies:
      - "🇸🇬 新加坡"
      - "🇺🇸 美国"
      - "🇯🇵 日本"
      - "🇭🇰 香港"
      - "PROXY"

  - name: "🎮 Steam 下载"
    type: select
    proxies:
      - "🎯 直连"
      - "🇸🇬 新加坡"
      - "🇭🇰 香港"
      - "🇺🇸 美国"
      - "PROXY"

  - name: "🧩 Steam 社区"
    type: select
    proxies:
      - "PROXY"
      - "🇺🇸 美国"
      - "🇸🇬 新加坡"
      - "🇭🇰 香港"

  - name: "🔄 自动选择"
    type: url-test
    use: ["自己", "星链", "翻墙侠", "IKUUU"]
    url: "https://www.gstatic.com/generate_204"
    interval: 300
    tolerance: 150
    timeout: 5000
    lazy: true
    disable-keepalive: true

  - name: "🛠️ 全部节点"
    type: select
    use: ["自己", "星链", "翻墙侠", "IKUUU"]

# =================== 规则 (Rules) - 保持原样即可 ===================
rules:
  - GEOIP,lan,🎯 直连,no-resolve
  - GEOSITE,private,🎯 直连,no-resolve
  - GEOIP,CN,🇨🇳 国内
  - GEOSITE,CN,🇨🇳 国内
  - GEOSITE,category-ads-all,🛑 拒绝
  - DST-PORT,123,🎯 直连,udp
  - GEOSITE,apple,🇨🇳 国内
  - GEOSITE,microsoft,PROXY
  - GEOSITE,github,PROXY
  - GEOSITE,google,PROXY
  - GEOSITE,telegram,💬 社媒通讯
  - GEOSITE,twitter,💬 社媒通讯
  - GEOSITE,facebook,💬 社媒通讯
  - GEOSITE,instagram,💬 社媒通讯
  - GEOSITE,netflix,📹 国外媒体
  - GEOSITE,youtube,📹 国外媒体
  - GEOSITE,spotify,📹 国外媒体
  - GEOSITE,bilibili,📺 B站
  - GEOSITE,bahamut,🇹🇼 台湾
  - GEOSITE,disney,🎬 Disney+
  - GEOSITE,hbo,🎬 HBO
  - GEOSITE,amazon,🎬 Prime Video
  - GEOSITE,steam@cn,🎮 Steam 下载
  - GEOSITE,steam,🧩 Steam 社区
  - GEOSITE,geolocation-!cn,PROXY
  - MATCH,PROXY

打开 webUI 并开始使用

在局域网内任意设备浏览器中输入 设备IP:9097 即可访问 metacubexd 的界面,后端地址填写 http://设备IP:9090 ,密钥留空即可,如图所示,点击添加便可管理 mihomo 的各项配置。若在前文中修改了 webUI 访问端口和外部控制端口,请自行替换为自己设置的端口号。

如果你使用 metacubexd 更改了一些设置,那将只会在 mihomo 的本次运行生效,重启 mihomo 会将所有设置重置为你第一步在 config.yaml 中所填写的配置



至此已搭建完成,在需要使用网络代理的地方在代理选项内填入 设备IP:7890 即可使用。

附上我的配置

蓝奏云

百度云 提取码: 2jff

123盘

天翼云(访问码:to8l)

0 条回应