Script to set a random MAC address for WAN when booting?

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware
Author Message
JN
DD-WRT Guru


Joined: 29 Mar 2007
Posts: 771

PostPosted: Sun Sep 07, 2014 19:18    Post subject: Script to set a random MAC address for WAN when booting? Reply with quote
I would like to set my DD-WRT router to choose one of a handful of WAN MAC addresses when booting the router (or at another time of my choosing). Ideally, the script should run early enough in the boot that the cable modem sees only the newly chosen WAN mac address and not the one left over from the last time. This will enable a new IP address if the modem is booting at the same time, eg when I am turning my network equipment on after an absence.

My cable company uses a sticky address that only changes if the router's WAN MAC address is different than last time as the modem is booting, and I would like it be a little more dynamic that that.

I would like the WAN MAC address to be chosen from a list, rather than totally random so I can use addresses selected from devices I own to ensure I do not accidentally create a conflict on the network. The modem runs in bridge mode and exposes the WAN MAC address to the larger cable network.

Thanks
Sponsor
cdmarshall
DD-WRT User


Joined: 09 Jul 2014
Posts: 308

PostPosted: Mon Sep 08, 2014 15:23    Post subject: Reply with quote
#!/bin/ash
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}"
stopservice wan
startservice wan


try that and let me know if it works. if so you shoudl be able to set a cron to run it at different times.

_________________
EA-6900
Asus 68U
JN
DD-WRT Guru


Joined: 29 Mar 2007
Posts: 771

PostPosted: Mon Sep 08, 2014 17:57    Post subject: Reply with quote
I saw the above script, but I do not want totally random. I want to rotate between, say five specific MAC addresses (that are for devices I own so I don't step on anyone's MAC address).
Per Yngve Berg
DD-WRT Guru


Joined: 13 Aug 2013
Posts: 5850
Location: Romerike, Norway

PostPosted: Tue Sep 09, 2014 6:22    Post subject: Reply with quote
Don't worry about a collision. There are so many combinations that a collision will hardly ever occur.
cdmarshall
DD-WRT User


Joined: 09 Jul 2014
Posts: 308

PostPosted: Tue Sep 09, 2014 13:34    Post subject: Reply with quote
MAC's are only an issue within your collision domain I.E. your network. Other than that it all take place at layer 3 (IP ADDRESSES) so MAC collisions are nearly impossible unless you do something very wrong on your network. You will never collide with your ISP.
_________________
EA-6900
Asus 68U
JN
DD-WRT Guru


Joined: 29 Mar 2007
Posts: 771

PostPosted: Wed Sep 10, 2014 3:08    Post subject: Reply with quote
In this case, the MAC address of the router is exposed to the cable provider, with the modem in bridge mode. In fact the WAN MAC address is used by the cable company for their DHCP leases, and changing it gets a new public IP address. I would like to choose a WAN MAC address from a small list that I set up.
Per Yngve Berg
DD-WRT Guru


Joined: 13 Aug 2013
Posts: 5850
Location: Romerike, Norway

PostPosted: Wed Sep 10, 2014 9:56    Post subject: Reply with quote
The first 4 digits of the MAC denotes the manufacturer. If you keep that static, you will be safe.
JN
DD-WRT Guru


Joined: 29 Mar 2007
Posts: 771

PostPosted: Wed Sep 10, 2014 19:32    Post subject: Reply with quote
cdmarshall wrote:
#!/bin/ash
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}"
stopservice wan
startservice wan


try that and let me know if it works. if so you shoudl be able to set a cron to run it at different times.
If I put something like this in the startup script, will that be run early enough in the bootup that the modem will not see the old MAC address?

Also any suggestions on how to choose MAC address randomly from a list instead of totally random?
cdmarshall
DD-WRT User


Joined: 09 Jul 2014
Posts: 308

PostPosted: Thu Sep 11, 2014 13:10    Post subject: Reply with quote
as long as your Cable modem boots up after wards it will be fine. Some cable modems bind to a mac of the connected device on boot-up. So boot your router first and it will change the mac then boot the cable modem.

If you own your own cable modem then you can work some other magic to reset it form the router with a script. Let me know if you own it or rent it.

_________________
EA-6900
Asus 68U
JN
DD-WRT Guru


Joined: 29 Mar 2007
Posts: 771

PostPosted: Fri Sep 12, 2014 13:37    Post subject: Reply with quote
cdmarshall wrote:
as long as your Cable modem boots up after wards it will be fine. Some cable modems bind to a mac of the connected device on boot-up. So boot your router first and it will change the mac then boot the cable modem.

If you own your own cable modem then you can work some other magic to reset it form the router with a script. Let me know if you own it or rent it.
I rent the modem (for no extra charge).

Some Arris modems can be rebooted from a web browser by requesting the below URL, but it don't work on this one (TM822). What does?

http://192.168.100.1/reset.htm?reset_modem=Restart+Cable+Modem

I do not have access to the Advance page of the settings, as the password generators on the Internet do not work.
cdmarshall
DD-WRT User


Joined: 09 Jul 2014
Posts: 308

PostPosted: Fri Sep 12, 2014 15:34    Post subject: Reply with quote
yeah then you may be out of luck when you change the MAC as most modems don't like it but ya never know till you try
_________________
EA-6900
Asus 68U
JN
DD-WRT Guru


Joined: 29 Mar 2007
Posts: 771

PostPosted: Tue Sep 16, 2014 18:17    Post subject: Reply with quote
cdmarshall wrote:
yeah then you may be out of luck when you change the MAC as most modems don't like it but ya never know till you try
I have no issue changing MAC address of the router as long as I reboot the modem too. Ideally I would like to create a script in DD-WRT that changes the MAC address to one of several chosen randomly or sequentially, and then reboot the modem with an appropriate wget or something.
HalfBit
DD-WRT Guru


Joined: 04 Sep 2009
Posts: 761
Location: AR, USA

PostPosted: Tue Sep 16, 2014 19:06    Post subject: Reply with quote
JN wrote:
cdmarshall wrote:
yeah then you may be out of luck when you change the MAC as most modems don't like it but ya never know till you try
I have no issue changing MAC address of the router as long as I reboot the modem too. Ideally I would like to create a script in DD-WRT that changes the MAC address to one of several chosen randomly or sequentially, and then reboot the modem with an appropriate wget or something.

wget with maybe a sleep after to reboot the router which would allow the modem to at least start rebooting before you reboot the router. I'm not a script expert, but it seems like this should be possible.

_________________
R7000 Nighthawk - DD-WRT v3.0-r40270M kongac (07/11/19)
R7000 Nighthawk - DD-WRT v3.0-r40270M kongac (07/11/19)
~~~~~~~~~~Dismantled for learning opportunities~~~~~~~~~~
WRT54Gv2
WRT54Gv8.2
cdmarshall
DD-WRT User


Joined: 09 Jul 2014
Posts: 308

PostPosted: Wed Sep 17, 2014 12:34    Post subject: Reply with quote
If you own the router it is possible at times. some will do it via a http request other do not really depends on the modem.
_________________
EA-6900
Asus 68U
JN
DD-WRT Guru


Joined: 29 Mar 2007
Posts: 771

PostPosted: Thu Sep 18, 2014 13:33    Post subject: Reply with quote
cdmarshall wrote:
If you own the router it is possible at times. some will do it via a http request other do not really depends on the modem.
As I said, I "rent" the modem (for no extra charge). (I, of course, own the router attached to it, which has DD-WRT.)

Some Arris modems can be rebooted from a web browser by requesting the below URL, but it don't work on this one (TM822). What does?

http://192.168.100.1/reset.htm?reset_modem=Restart+Cable+Modem

I can get to the modem status pages at http://192.168.100.1, but there are no controls to reboot or do anything at all to the modem.

I do not have access to the Advance page, as the password generators on the Internet do not work for this newer Arris modem.

Just wondering if others have this modem and figured out anything more about it?
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum