MAC randomisation on my MudiV2

Hi!

Especially @admon. Can anyone, or you please help me to make my MAC be randomly generated after each reboot?

I need some kind of script or instructions. Thanks you!

Whose MAC address? wifi?

Of my Gl-Inet router.
You have manual option:
IMG_3111

But I need to make it randomised every time it reboots

Do you just need the mac address on the wan interface to be random?

I need to make all visible MACs to be random :slight_smile:

Sorry, this feature is not currently supported

That’s why I asked community. Maybe there is a custom script or something…

Nope, no script available.

It shouldn’t be too hard to create one, so give it a try.

@admon, can you check this? I found it on Reddit :slight_smile:

#!/bin/sh

# Update package list and install macchanger
opkg update
opkg install macchanger

# Create the MAC randomization script
cat << 'EOF' > /etc/init.d/randomize_mac
#!/bin/sh /etc/rc.common

START=99

start() {
    for iface in $(ip link show | grep -E '^[0-9]+:' | cut -d ':' -f 2 | cut -d ' ' -f 2); do
        if [ "$iface" != "lo" ]; then
            macchanger -r $iface
        fi
    done
}
EOF

# Make the MAC randomization script executable
chmod +x /etc/init.d/randomize_mac

# Enable the MAC randomization script
/etc/init.d/randomize_mac enable

# Delete this script
rm -- "$0"

Or this:

#!/bin/sh

INSTALL_PATH="/etc/init.d/randomize_mac"

echo "Creating MAC randomizer script..."
cat << 'EOF' > $INSTALL_PATH
#!/bin/sh /etc/rc.common

START=99

start() {
    generate_random_mac() {
        echo $(printf '%02x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%256)))
    }

    change_mac() {
        local iface=$1
        local new_mac=$(generate_random_mac)
        ip link set dev $iface down
        ip link set dev $iface address $new_mac
        ip link set dev $iface up
    }

    for iface in $(ip link show | grep -E '^[0-9]+:' | cut -d ':' -f 2 | cut -d ' ' -f 2); do
        if [ "$iface" != "lo" ]; then
            change_mac $iface
        fi
    done
}
EOF

echo "Making MAC randomizer script executable..."
chmod +x $INSTALL_PATH
echo "Success!"

echo "Enabling MAC randomizer script to run at boot time..."
/etc/init.d/randomize_mac enable
echo "Success!"

echo "Deleting installation script..."
rm -- "$0"

Here is example of output of this command:

echo $(printf '%02x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%256)))

Output:

localhost:~# echo $(printf '%02x' $((RANDOM%256)))
":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%0
2x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%2
56)))":"$(printf '%02x' $((RANDOM%256)))":"$(print
f '%02x' $((RANDOM%256)))
a7:03:f2:fa:45:5d
localhost:~# echo $(printf '%02x' $((RANDOM%256)))
":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%0
2x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%2
56)))":"$(printf '%02x' $((RANDOM%256)))":"$(print
f '%02x' $((RANDOM%256)))
f5:3f:8b:6e:f9:84
localhost:~# echo $(printf '%02x' $((RANDOM%256)))
":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%0
2x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%2
56)))":"$(printf '%02x' $((RANDOM%256)))":"$(print
f '%02x' $((RANDOM%256)))
e8:db:17:37:29:fd
localhost:~# echo $(printf '%02x' $((RANDOM%256)))
":"$(printf '%02x' $((RANDOM%256)))":"$(printf '%0
2x' $((RANDOM%256)))":"$(printf '%02x' $((RANDOM%2
56)))":"$(printf '%02x' $((RANDOM%256)))":"$(print
f '%02x' $((RANDOM%256)))