How to randomize the WAN Mac address on each reboot?

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