Skip to content

Instantly share code, notes, and snippets.

@groundcat
Last active September 16, 2023 12:43
Show Gist options
  • Select an option

  • Save groundcat/95be89e5fb33dbdb646651c51d93f0f8 to your computer and use it in GitHub Desktop.

Select an option

Save groundcat/95be89e5fb33dbdb646651c51d93f0f8 to your computer and use it in GitHub Desktop.
Asuswrt-Merlin set random MAC

Create random-mac.sh script:

echo "#!/bin/sh
MAC=\$(m=\$(openssl rand -hex 5) && echo \"00\":\${m:0:2}:\${m:2:2}:\${m:4:2}:\${m:6:2}:\${m:8:2})
logger \"Changing MAC address to \$MAC\"
nvram set wan0_hwaddr_x=\"\$MAC\"
nvram commit
service \"restart_wan_if 0\"" > /jffs/scripts/random-mac.sh

Append to /jffs/scripts/services-start:

echo "cru a random-mac \"0 5 * * * /jffs/scripts/random-mac.sh\" # Randomize MAC address" >> /jffs/scripts/services-start

Make sure you set executable permission using the chmod command:

chmod a+rx /jffs/scripts/services-start
chmod a+rx /jffs/scripts/random-mac.sh

Enable boot time support for /jffs/scripts/ Support for these scripts stored under /jffs/scripts/ must be enabled, under Administration -> System on the webui:

  • Format JFFS partition at next boot = No
  • Enable JFFS custom scripts = Yes

Make it effective now:

cru a random-mac "0 5 * * * /jffs/scripts/random-mac.sh" # Randomize MAC address

To list current jobs run:

cru l

To delete current jobs run:

cru d random-mac

Verify it:

cru l

Reference: https://www.cyberciti.biz/faq/how-to-add-cron-job-on-asuswrt-merlin-wifi-router/

#!/bin/sh
MAC=$(m=$(openssl rand -hex 5) && echo "00":${m:0:2}:${m:2:2}:${m:4:2}:${m:6:2}:${m:8:2})
logger "Changing MAC address to $MAC"
nvram set wan0_hwaddr_x="$MAC"
nvram commit
service "restart_wan_if 0"
@onward-web
Copy link

for me working: replace "service "restart_wan_if 0" and add
killall -USR1 udhcpc
sleep 10
service "restart_wan"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment