How to change the ra0 MAC address


#1

Hi All,
Is there any way to change the ra0 MAC address permanently? Thanks.


#2

Why do you want to change it? You shouldn’t change it.

If you indeed need that, you can build a firmware with lock the factory partition.

If you use OpenWRT-18.06, you can edit the file target/linux/ramips/dts/GL-MT300N-V2.dts, and remove read-only flag in factory section. It would looks like:

factory: partition@40000 {
    label = "factory";
    reg = <0x40000 0x10000>;
};

Here is a shell script to change mac address. Just for your information.

#!/bin/sh

. /lib/functions/system.sh

[ $# -ne 1 ] && {
	echo "Usage: setmac <mac>"
	exit 0
}

w_mac=$(macaddr_canonicalize "$1")
[ -z "$w_mac" ] && {
	echo "Invalid MAC address: $1"
	exit 0
}

PART="/dev/mtd2"
FACTORY_BIN="/tmp/factory.bin"

# Create backup for factory partition
dd if=${PART} of=${FACTORY_BIN} 2>/dev/null

# Write MAC address
real_mac="\x${w_mac:0:2}\x${w_mac:3:2}\x${w_mac:6:2}\x${w_mac:9:2}\x${w_mac:12:2}\x${w_mac:15:2}"
printf "$real_mac" | dd of=${FACTORY_BIN} bs=1 count=6 seek=$((0x0004)) conv=notrunc 2>/dev/null

mtd write ${FACTORY_BIN} factory 1>/dev/null 2>/dev/null

# Double check
r_mac=$(hexdump -v -n 6 -s $((0x4)) -e '5/1 "%02x:" 1/1 "%02x"' ${PART})
if [ "$r_mac" == "$w_mac" ]; then
	echo "Success"
else
	echo "Failed"
fi

jffs2reset -y && reboot

#3

编译时选哪一个是MT300N-V2的选项?


#4

image

你是说这个么?


AR-300M Lite: Is it possible to change the MAC address of the WIFI?
#6

编译出来后,使用哪个bin文件升级呢,带factory.bin那个吗?是在openwrt的luci网页中升级还是在GL的网页中升级呢,谢谢。


#7

我编译出来,没有WIFI的东西,也没有apcli0和ra0接口,请问是MTK的驱动得自己移植吗?麻烦指导一下,谢谢。或者你能提供一个你们的git地址,我直接下载编译吗


#8

呵呵,你不是要改mac而已吗?你改完再刷会我们的固件就行了。MTK的驱动是不开源的,我们也没办法提供!

如果要自己编译的话,可以用我们的imagebuilder,不过是二进制形式的。


#9

也就是说,我编译出来的固件,烧写进去,先把MAC改了,再烧回原来的?就用你昨天发的那个脚本就可以改了吗?


#10

就是这样的!修改flash分区不需要无线驱动啥的。只是为了用一个unlock固件把mac地址换掉而已,要刷回标准固件使用。


#11

没懂呢,我如果不刷我自己编译的固件(去掉read-only那个),只使用你昨天的那个脚本也能改MAC吗?


#12

改不了啊,标准固件是带了read-only的,那个分区是只读的属性,无法修改的。


#14

你好,我改完MAC后,再烧回你们官网上的MT300N-V2的固件,网页打不开了,

麻烦帮忙看下怎么回事呢


#15

忘了告诉你,我们的web绑定了MAC,所以更换MAC是无法使用我们的web的,只能访问Luci。


#16

那我怎么改变绑定呢,怎么操作呢?不然我的无线都设置不了了