What's new

How to set a Random WAN Mac at each boot?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Forerunner

Occasional Visitor
Hi, I have been using Merlin firmware for a long time and never needed help up until now as I have search absolutely everywhere for a script I can have run on the router at each boot so that i can have a random MAC on the WAN port each time i boot the router as i like to get a different IP from time to time id prefer to have the script auto run when i just switch the router off then on again rather than login and have to change it myself ( Lazy yes ) I have a cable modem from a UK ISP that gives a New IP when the router MAC is changed.

Thanks I will donate also to this Amazing Firmware thanks Merlin!
 
This sample code will put a random MAC address in a variable, for an Asuswrt-Merlin router. However, I don't know what the next step is?
Code:
AUTOMAC=$(m=$(/usr/sbin/openssl rand -hex 6|/usr/bin/tr [a-z] [A-Z]) && /bin/echo ${m:0:2}:${m:2:2}:${m:4:2}:${m:6:2}:${m:8:2}:${m:10:2})
echo $AUTOMAC


Next step?
Code:
#/sbin/ifconfig eth0 down
#/sbin/ifconfig eth0 hw ether $AUTOMAC
#/sbin/ifconfig eth0 up
#/sbin/service restart_wan_if
#  OR
#/usr/sbin/nvram set lan_hwaddr=$AUTOMAC
#/usr/sbin/nvram set wan_hwaddr=$AUTOMAC
#/usr/sbin/nvram set wan0_hwaddr=$AUTOMAC
#/usr/sbin/nvram set wl0_hwaddr=$AUTOMAC
#/usr/sbin/nvram set boardnum=$AUTOMAC
#/usr/sbin/nvram set 0:macaddr=$AUTOMAC
#/usr/sbin/nvram commit
#/sbin/reboot
 
I still can't quite figure it out I used to have it working on DD-WRT a long time ago but can't find how to get it working on Merlin Firmware. Does anyone have any ideas?
 
Just remember that with Virgin Media the CMTS will only allow 4 changes in a 24 hour period.
 
Just remember that with Virgin Media the CMTS will only allow 4 changes in a 24 hour period.

Yeah i would only want to change the IP once a week probably. I will most likely be leaving them soon anyway as their logic is pay for 200 Mbps and get 2 - 4
 
You must be in an area with a high utilisation issue. I get 200Mbps consistently no matter what time of the day.
 
Anyone can share a script?

I tried this script but it's not working.


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

echo "00:${MAC}"

ifconfig eth1 hw ether 00:${MAC}

nvram set def_hwaddr="00:${MAC}"

nvram set wan_hwaddr="00:${MAC}"
 
That looks like a script for DD-WRT, this is a Asuswrt-Merlin forum. What router and firmware are you using?
 
You could try this. It will setup the new MAC address but as noted in the comments, in my experience the change won't be effective until the cable modem is power cycled. YMMV.
Code:
#!/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"     # This doesn't work, nor a reboot.
                               # The modem needs to be power cycled.
 
Last edited:
Hi Colin!
Don't you also need to set wan_hwaddr_x to the random mac? (In addition to or maybe instead of wan0_hwaddr_x)
I ask because I tried using the webui WAN page "clone mac address" and looking at the NVRAM afterwards I see both variables are set to the new MAC.
Thanks!

You could try this. It will setup the new MAC address but as noted in the comments, in my experience the change won't be effective until the cable modem is power cycled. YMMV.
Code:
#!/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     # This doesn't work, nor a reboot.
                        # The modem needs to be power cycled.
 
Hi Colin!
Don't you also need to set wan_hwaddr_x to the random mac? (In addition to or maybe instead of wan0_hwaddr_x)
I ask because I tried using the webui WAN page "clone mac address" and looking at the NVRAM afterwards I see both variables are set to the new MAC.
Thanks!
No, that's just a temporary variable used by the GUI.
 

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top