Skip to content

iptables

在 Linux 上,iptables 块用于让 mihomo 接管那些让透明代理 (tproxy-port / redir-port)真正透明所需的防火墙规则。非 Linux 平台上该块被忽略。

选项

字段类型默认值允许值描述
enableboolfalsetrue | false让 mihomo 自行安装(并清理)Linux 透明代理所需的 iptables 规则。
inbound-interfacestring(unset)<interface>把透明代理规则限制在到达该接口的流量(如 `eth0`)。空值匹配所有接口。
bypass[]string[]<CIDR>要跳过的源 CIDR —— 这些来源的流量不做透明代理。
dns-redirectboolfalsetrue | false劫持所有出站 DNS(UDP/53)并本地应答。作为路由器运行时需要;桌面使用默认关闭。

源码: config/config.go:338-343 · 锚定版本 v1.19.27 (5184081)

示例

yaml
tproxy-port: 7895

iptables:
  enable: true
  inbound-interface: eth0
  bypass:
    - 192.168.1.0/24
    - 10.0.0.0/8
  dns-redirect: true

说明

  • iptables 管理需要 mihomo 以 root(或带 CAP_NET_ADMIN)运行。
  • 实际安装的规则文档在 mihomo 源代码的 listener/sing_tun/ 下 —— 它们创建一个自定义链与路由 mark。
  • mihomo 正常退出时会移除规则。崩溃后会残留;可用 iptables -t mangle -F MIHOMO(以及对应的 NAT 链)清理。

源码: config/config.go:338-343 · v1.19.27 (5184081)

由 Argsment 出品的 Core Tutorial