Random Hostname and Mac Address AR300M

#!/bin/sh /etc/rc.common                             


start() {                                            
  OLDMAC=$(uci get wireless.sta.macaddr)              
  logger "[WIFI-MAC] Old WIFI MAC address is ${OLDMAC}."                                                    
#change wireless mac
  NEWMAC=$(echo 00:11:22:$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3'/))
  logger "[WIFI-MAC] Applying new random MAC address to WIFI (${NEWMAC})..."                                
  uci set wireless.sta.macaddr=${NEWMAC}       
  uci commit wireless
# change wan mac
# pls modify the above script and change mac address in /etc/config/network
# All WAN, LAN mac addresses are in /etc/config/network, just change them here



Thank you alzhao!

Isn’t changing mac address in /etc/config/network the same as mac overrride in LuCI? I am trying to automat it at boot for all interfaces, not only WiFi. However I can simply modify your script with network.wan.macaddr or network.lan.macaddr, right?

I also have one last question regarding WiFi. Does wireless.sta.macaddr work for the whole radio0 interface, including guest Wifi?

Yes you are right.

No. For each wireless interface you need to set an MAC address.

Pls make sure you use valid mac address. Check your prefix (OUI) using online tools e.g. MAC Address Validator

So what would the command be for a guest Wifi?

You need to check /etc/config/wireless, everything is there

Oh, okay. My bad.

Thank you!

@alzhao would this script work for a mudi router?_

Yes I think so. I answered you in another thread.