不依赖插件!教你如何直接运行 mihomo 内核代理(跑裸核),极致精简

openwrt裸核运行mihomo:

安装mihomo内核:https://github.com/morytyann/OpenWrt-mihomo

1、yaml配置文件放在/etc/mihomo/run目录 名字为config.yaml

启动

mihomo -d /etc/mihomo/run

停止

service mihomo stop

防火墙三项全部接受

Linux裸核运行mihomo

下载二进制执行文件:
https://github.com/MetaCubeX/mihomo/releases
根据CPU架构选择版本

将下载压缩包解压得到二进制文件重名名为 mihomo 并移动到 /usr/local/bin/
给予执行文件755权限

创建运行配置文件夹

mkdir /etc/mihomo

把配置文件放进去

创建系统systemd 配置文件

nano /etc/systemd/system/mihomo.service

复制以下内容:

[Unit]
Description=mihomo Daemon, Another Clash Kernel.
After=network.target NetworkManager.service systemd-networkd.service iwd.service

[Service]
Type=simple
LimitNPROC=500
LimitNOFILE=1000000
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_TIME CAP_SYS_PTRACE CAP_DAC_READ_SEARCH CAP_DAC_OVERRIDE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW CAP_NET_BIND_SERVICE CAP_SYS_TIME CAP_SYS_PTRACE CAP_DAC_READ_SEARCH CAP_DAC_OVERRIDE
Restart=always
ExecStartPre=/usr/bin/sleep 1s
ExecStart=/usr/local/bin/mihomo -d /etc/mihomo
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

使用以下命令重新加载 systemd:

systemctl daemon-reload

启用 mihomo 服务:

systemctl enable mihomo

使用以下命令立即启动 mihomo:

systemctl start mihomo

使用以下命令使 mihomo 重新加载:

systemctl reload mihomo

使用以下命令检查 mihomo 的运行状况:

systemctl status mihomo

使用以下命令检查 mihomo 的运行日志:

journalctl -u mihomo -o cat -e

journalctl -u mihomo -o cat -f

访问web页面地址为 192.168.10.55:9090/ui 一定要注意后面的/ui 不然会显示 mihomo 而没有其他的显示。

透明网关模式:
启用IP转发,作为透明网关的关键。

sudo sed -i '/net.ipv4.ip_forward/s/^#//;/net.ipv6.conf.all.forwarding/s/^#//' /etc/sysctl.conf && sudo sysctl -p

或者手动操作:
编辑

nano /etc/sysctl.conf

把下面两个前面的注释去掉,使其生效。
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1

应用更改

sudo sysctl -p

网络重启命令(比如更改网关后需要重启生效)

systemctl restart networking