记一次更改openwrt默认mac地址,长城宽带kj30-n路由器

处于某些原因,我希望为刷好 openwrt 的长城宽带 kj30-n 路由器更改 mac 地址,涉及到 wan 口、lan 口的 mac 以及 WiFi 的 bssid。由于定制固件,我尝试了多种方法,仅最后一种方式成功。

ifconfig命令

1
2
3
ifconfig lan down
ifconfig lan hw ether 11:22:33:44:55:66
ifconfig lan up

但是,在修改 WiFi 时,报错 ifconfig: SIOCSIFHWADDR operation not support

修改 /etc/config

  • /etc/config/networkconfig interface 'wan' 下新增 option macaddr '11:22:33:44:55:66'
  • /etc/config/networkconfig interface 'wan' 下新增 option macaddr '11:22:33:44:55:67'
  • /etc/config/wirelessconfigwifi-iface 'my_wifi_2.4g' 下新增 option macaddr '11:22:33:44:55:68'
  • /etc/config/wirelessconfigwifi-iface 'my_wifi_5g' 下新增 option macaddr '11:22:33:44:55:69'

/etc/config/wireless 中,也可以使用option bssid,但仅在 adhoc 或 sta 模式有效。

具体可以参考官方文档 Wi-Fi /etc/config/wirelessNetwork configuration /etc/config/network

openwrt 下刷写 Factory 分区

此操作存在变砖风险!请务必做好备份,并在操作之前明确清楚你正在做什么。

安装 kmod-mtd-rw,解锁mtd分区,备份后修改覆盖。

先通过 cat /proc/mtd 确定你的 Factory 或者 art 分区。例如以下,为 mtd3。

1
2
3
4
5
6
7
dev:    size   erasesize  name
mtd0: 08000000 00020000 "spi0.0"
mtd1: 00100000 00020000 "BL2"
mtd2: 00080000 00020000 "u-boot-env"
mtd3: 00200000 00020000 "Factory"
mtd4: 00200000 00020000 "FIP"
mtd5: 07200000 00020000 "ubi"
1
2
3
4
5
6
7
opkg update
opkg install kmod-mtd-rw
dd if=/dev/mtd4 of=/tmp/factory_bak.bin
cp /tmp/factory_bak.bin /tmp/factory_new.bin
# 修改/tmp/factory_new.bin
insmod mtd-rw.ko i_want_a_brick=1
mtd write /tmp/factory_new.bin Factory

但是,kmod-mtd-rw 无法安装,该固件的内核版本在软件源中没有匹配的包,放弃。

u-boot 下刷写 Factory 分区

此操作存在变砖风险!请务必做好备份,并在操作之前明确清楚你正在做什么。

首先,你需要用 ttl 连接路由器,相关教程很多。你的 u-boot 命令可能和我不同,请使用 help 命令自行阅读。

这部分有时间再补,总体思路是拷贝原factory分区,更改mac地址,再拷贝回去。

参考


记一次更改openwrt默认mac地址,长城宽带kj30-n路由器
https://boyinthesun.cn/posts/e804536f9e17.html
作者
BoyInTheSun
发布于
2025年5月18日
许可协议