Incus 运行 OpenWrt

容器 #

创建 profile #

$ incus profile create openwrt
$ incus profile edit openwrt
config:
  boot.autorestart: "false"
  boot.autostart: "true"
devices:
  eth0:
    name: eth0
    network: incusbr-1000
    type: nic
  root:
    path: /
    pool: default
    type: disk

配置 #

查看可用版本:

$ incus image list images: openwrt

初始化容器:

$ incus init images:openwrt/25.12 openwrt -p openwrt

静态 IP:

$ incus config device override openwrt eth0 ipv4.address=192.168.20.120

OpenWrt 配置(单 lan 口):

$ incus start openwrt
$ incus exec openwrt -- ash

[先修改密码]
# passwd root

[关闭 ntp 并设置国内时区]
# /etc/init.d/sysntpd disable
# uci set system.ntp.enabled='0'
# uci set system.@system[0].zonename='Asia/Shanghai'
# uci set system.@system[0].timezone='CST-8'
# uci commit system

[查看:eth0 默认分配给了 wan]
# uci show network.wan
network.wan=interface
network.wan.device='eth0'
network.wan.proto='dhcp'

[查看:wan 区域的入站请求是被拒绝的,此时无法打开网页后台]
# uci show firewall | grep -e 'zone' | grep -E '\.name|\.input'
firewall.@zone[0].name='lan'
firewall.@zone[0].input='ACCEPT'
firewall.@zone[1].name='wan'
firewall.@zone[1].input='REJECT'

[删除 wan]
# uci delete network.wan
# uci delete network.wan6

[添加 lan,设置 dhcp 从上游获取 ip,即从 incus 网桥提供的 DHCP 服务获取地址]
# uci set network.lan=interface
# uci set network.lan.proto='dhcp'
# uci set network.lan.device='eth0'
# uci commit network

[忽略 lan 口的 DHCP 服务,即不在 lan 口提供 DHCP 服务,避免和 incus 的 DHCP 服务冲突]
# uci set dhcp.lan.ignore='1'
# uci commit dhcp

[替换清华源并更新]
# sed -i 's_https\?://downloads.openwrt.org_https://mirrors.tuna.tsinghua.edu.cn/openwrt_' /etc/apk/repositories.d/distfeeds.list
# apk update
# apk upgrade
# reboot

重启后,就能进入网页后台了。

OpenClash #

插件 #

OpenClash 插件:https://github.com/vernesong/OpenClash/releases/latest

$ incus file push luci-app-openclash-0.47.156.apk openwrt/root
$ incus exec openwrt -- ash
# apk add --allow-untrusted ./luci-app-openclash-0.47.156.apk
# reboot

内核 #

mihomo 内核:https://github.com/MetaCubeX/mihomo/releases/latest

查看 CPU 信息:

$ grep -m1 'flags' /proc/cpuinfo | grep -o 'avx2\|sse4_2'

如果输出包含 avx2,说明可以用 v3;如果只有 sse4_2,可以用 v2;如果都没有,请使用 v1。

$ incus file push mihomo-linux-amd64-v3-v1.19.32.gz openwrt/root
$ incus exec openwrt -- ash
# gzip -d mihomo-linux-amd64-v3-v1.19.32.gz
# mv mihomo-linux-amd64-v3-v1.19.32 /etc/openclash/core/clash_meta
# chmod +x /etc/openclash/core/clash_meta

设置 #

记得每一步之后要点击页面最下方的 [ Commit Settings ]。

接口设置 #

Plugin Settings → Traffic Control → WAN Interface Name → eth0

Plugin Settings → Traffic Control → LAN Interface Name → eth0

模式设置 #

Plugin Settings → Operation Mode → Select Mode → fake-ip

Plugin Settings → Operation Mode → Proxy Mode → Rule Proxy Mode

GEO Update #

Plugin Settings → GEO Update → 全部勾选

DNS 设置 #

Plugin Settings → Redirect Local DNS Setting → Dnsmasq Redirect


Overwrite Settings → DNS Settings → Custom DNS Setting ✅

Overwrite Settings → DNS Settings → Respect Rules(respect-rules) ✅

Overwrite Settings → DNS Settings → Fake-IP Range (IPv4 Cidr) → 198.18.0.1/16

Overwrite Settings → DNS Settings → Nameserver-Policy ✅

"geosite:cn,private": [https://223.5.5.5/dns-query]
"geosite:geolocation-!cn": [https://1.1.1.1/dns-query, https://8.8.8.8/dns-query]

Overwrite Settings → DNS Settings → Add Custom DNS Servers → nameserver

✅   nameserver    1.1.1.1/dns-query    HTTPS
✅   nameserver    8.8.8.8/dns-query    HTTPS

Overwrite Settings → DNS Settings → Add Custom DNS Servers → fallback → 全部取消勾选


Overwrite Settings → DNS Settings → Add Custom DNS Servers → default-nameserver

✅   nameserver    223.5.5.5/dns-query    HTTPS

点击这条 DNS 的 → Edit 按钮 → Node Domain Resolve ✅

取消 SOCKS5/HTTP(S) 的认证 #

Overwrite Settings → General Settings → Set Authentication of SOCKS5/HTTP(S) → 取消勾选或删除

http 代理 #

宿主机测试:

$ proxy='http://192.168.20.120:7890'
$ http_proxy=$proxy https_proxy=$proxy no_proxy='localhost,127.0.0.1' bash
$ curl www.google.com

虚拟机 #

创建 profile #

$ incus profile create openwrtvm
$ incus profile edit openwrtvm
config:
  limits.cpu: "4"
  limits.memory: 1GiB
  boot.autostart: "true"
  boot.autorestart: "false"
  security.secureboot: "false"
devices:
  root:
    path: /
    pool: default
    type: disk
    size: 10GiB
  eth0:
    name: eth0
    network: incusbr-1000
    type: nic

其余设置和容器一样。