How to randomize the WAN Mac address on each reboot?

Why do you need this: I want to get a new public IP address everytime I reboot the router in order to (for example) bypass the megaupload restrictions etc

Thanks

Only the far-end equipment of your ISP sees MAC.

Is "megaupload" an ISP "sales phrase", or a website?

If a website, changing MAC does nothing.

:bulb: So you're actually tying to force your ISP to issue new IPs to you?

IPv6 or IPv4?

:spiral_notepad: (You don't have to change MAC to get a new IP address for IPv6)

:warning: (and doing that via IPv4 without ending the lease may cause other issues with your ISP - that they'll eventually trace to you, and not like!)

:warning: also, if it's a website - @psherman notifying a mod, because asking how to violate terms-of-services, etc. is not allowed on this forum

1 Like

You wrote the abuser part in your nickname wrong.

1 Like

Im from argentina, I doubt they care. Ive been doing this since 2008 but manually.
I would like to automatize the process.

1 Like

Only the far-end equipment of your ISP sees MAC.

Why do they need to see my MAC?

Because you want Internet (i.e. ISP connection).

1 Like

So, if i understand right, it's like this:

My device with MAC --> asking ISP for IP --> ISP gives IP --> MAC is now hidden by IP and websites I visit will only see IP ?

No.

MAC- Layer 2
IP - Layer 3

(This is not OpenWrt-specific.)

1 Like

Just do a bash script to randomly modify the mac and put in /etc/init.d and call it from /etc/rc.d (like all any other init script). Use the $RANDOM variable of bash scripting.

Some ISPs change the customer public ip address when the mac is changed (they have semi fixed ip address). And I guess that's the reason of he want to do it, he want to create a random mac, to get different ip address from his ISP each time and that way he can access to certain web services who limit access by ip address.

For anyone insterested heres the solution:

To create an OpenWRT script that changes the WAN MAC address on each reboot, you can follow these steps:

  1. Connect to your OpenWRT router using SSH or the LuCI web interface.
  2. Create a new shell script file. For example, you can use the command: vi /etc/init.d/change_wan_mac.
  3. Enter the following script content into the file:
#!/bin/sh /etc/rc.common

START=99

start() {
    # Generate a random MAC address
    new_mac=$(macchanger -r eth0 | awk '/New MAC/ {print $3}')
    
    # Set the new MAC address for the WAN interface
    ifconfig eth0 down
    ifconfig eth0 hw ether $new_mac
    ifconfig eth0 up
    
    # Log the changed MAC address
    logger -t ChangeWANMAC "WAN MAC address changed to: $new_mac"
}

boot() {
    start
}

reload() {
    start
}
  1. Save and exit the file (:wq in vi editor).
  2. Make the script executable by running the command: chmod +x /etc/init.d/change_wan_mac.
  3. Enable the script to run on system startup by executing: /etc/init.d/change_wan_mac enable.

Now, whenever your OpenWRT router reboots, it will automatically generate a random MAC address for the WAN interface (eth0) and apply it. The new MAC address will be logged in the system logs for reference.

Note: This script assumes that the WAN interface is named "eth0" on your OpenWRT router. If your interface has a different name, make sure to modify the script accordingly. Also, ensure that the "macchanger" package is installed on your OpenWRT router for generating random MAC addresses. You can install it using the command: opkg update && opkg install macchanger.

1 Like

I can confirm that following the steps below enables you to obtain a new IP address every time you reboot your router, even if OpenWrt displays the same MAC addresses. I'm using PPPOE, although I'm not sure if that's relevant. Could someone with more experience explain why this occurs?

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.