I'm trying to figure out a way to invoke the "mac clone" command found under the "setup" menu in DD-WRT v24SP2. I can do it in the GUI (of course), but I want to place it in a script so that I can cron and randomize it.

Perhaps it would be best if I explained my plight? What I want to create is a script that I can run that will randomly set the MAC address of the router to get a new IP address. I've tried many different scripts , but none seem to work with my router model (Buffalo WZR-HP-G300NH). After giving up on scripts, I decided to try using the built in "MAC clone" function in the GUI; It worked like a charm. Unfortunately, I can't exactly cron the GUI, nor can I have it select the MAC randomly from the GUI.

Here is what I have to set the MAC to a random value:

MAC=`(date; cat /proc/interrupts) | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;'`
echo "00:${MAC}"

The echoed value is the randomly generated MAC address (it always starts with 00, I know it's bad.).

So (bad grammar), the question I have is: How do I call whatever built-in function is used to clone the MAC address using the above script?

Thanks in advance!


There are some command line options which I think you are looking for... these are as follows:


1 turns the MAC cloning on and 0 turns it off



The random MAC address you want goes in both... I am not sure what the difference is but in my configuration, they are both the same.

| improve this answer | |
  • I'll test this and get back to you – VerTiGo_Etrex May 5 '11 at 14:18
  • This appears to be right. I was missing "mac_clone_enable" in my script. Unfortunately, it appears as though my ISP's dhcp server doesn't like certain macs... oh well... – VerTiGo_Etrex May 5 '11 at 14:51

Here is my full custom script which appears to work well:

MAC=`(date; cat /proc/interrupts) | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;'`
nvram set mac_clone_enable=1
nvram set wan_hwaddr="00:${MAC}"
nvram set def_hwaddr="00:${MAC}"
nvram commit
echo "00:${MAC}"
/bin/sleep 90

Call it via cron (In Administration --> Management) like so:

0 0 * * 1,5 root /bin/sh /tmp/custom.sh

Make sure once you've saved the cronjob in the gui, you check to make sure it's actually configured in the file system:

cat /etc/cron.d/cron_jobs

Hope this helps someone. Thanks for the randomized MAC address code.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.