本文介绍如何将小米红米 AC2100 路由器刷入 OpenWrt,包括启用 SSH 权限、连接设备、上传与刷入固件等操作步骤,适合新手按图索骥操作。
📥 准备工作
- 下载 OpenWrt 固件:
📎 官方文档参考:Xiaomi Redmi Router AC2100
- 安装工具:
- 安装 Python 环境(建议 3.x)
- 安装 SSH 客户端(Windows 可直接使用 CMD)
🔓 开启路由器 SSH 权限
- 浏览器访问管理后台:
http://192.168.31.1/cgi-bin/luci/web
- 登录后按下
F12
打开浏览器控制台(Console),粘贴以下 JS 脚本:
function getSTOK() {
let match = location.href.match(/;stok=(.*?)\//);
if (!match) {
return null;
}
return match[1];
}
function execute(stok, command) {
command = encodeURIComponent(command);
let path = `/cgi-bin/luci/;stok=${stok}/api/misystem/set_config_iotdev?bssid=SteelyWing&user_id=SteelyWing&ssid=-h%0A${command}%0A`;
console.log(path);
return fetch(new Request(location.origin + path));
}
function enableSSH() {
stok = getSTOK();
if (!stok) {
console.error('stok not found in URL');
return;
}
console.log(`stok = "${stok}"`);
password = prompt('Input new SSH password');
if (!password) {
console.error('You must input password');
return;
}
execute(stok,
`
nvram set ssh_en=1
nvram commit
sed -i 's/channel=.*/channel=\\"debug\\"/g' /etc/init.d/dropbear
/etc/init.d/dropbear start
`
)
.then((response) => response.text())
.then((text) => console.log(text));
console.log('New SSH password: ' + password);
execute(stok, `echo -e "${password}\\n${password}" | passwd root`)
.then((response) => response.text())
.then((text) => console.log(text));
}
enableSSH();
- 回车执行,输入新 SSH 密码(建议设为
root
方便记忆)
🔗 通过 SSH 连接路由器
第一步:运行本地 HTTP 服务器
cd C:\Users\你的用户名\Documents\openwrt
python -m http.server 8000
Windows 可在 CMD 或 PowerShell 中执行
第二步:确认本机 IP 地址
ipconfig
记录 IPv4 地址,例如 192.168.31.250
第三步:连接路由器
ssh -o HostKeyAlgorithms=ssh-rsa root@192.168.31.1
输入刚才设置的 SSH 密码登录
⬇️ 上传并刷入 OpenWrt 固件
下载固件到路由器 /tmp
目录
wget http://192.168.31.250:8000/openwrt-23.05.5-ramips-mt7621-xiaomi_redmi-router-ac2100-squashfs-kernel1.bin -O /tmp/kernel1.bin
wget http://192.168.31.250:8000/openwrt-23.05.5-ramips-mt7621-xiaomi_redmi-router-ac2100-squashfs-rootfs0.bin -O /tmp/rootfs0.bin
执行以下命令准备刷机
nvram set uart_en=1
nvram set boot_wait=on
nvram set bootdelay=5
nvram set flag_try_sys1_failed=1
nvram commit
刷入 OpenWrt
mtd write /tmp/kernel1.bin kernel1
mtd -r write /tmp/rootfs0.bin rootfs0
等待路由器自动重启,稍后访问 http://192.168.1.1
即可进入 OpenWrt 界面。
✅ 刷机完成后建议:
- 第一时间设置密码
- 安装 luci-i18n-base-zh-cn 获取中文界面