Run this shell script with (sudo) root permissions to change your wlan0 MAC address to a randomly generated one. If you want to change your eth0 address, just replace all wlan0′s with eth0′s.
Direct download: randomac.sh
Please post your suggestions and improvements below!
TODO:
* accept interface as parameter
* accept custom (not random) mac as parameter
#!/bin/bash --
#
# Random MAC adress changer
# http://www.360percents.com
#
#
if [ "$UID" -eq "0" ]
then
oldmac=`ifconfig -a | grep HWaddr | grep wlan0 | awk '{print $NF}'`
echo "Old mac adress: $oldmac"
newmac=`echo $RANDOM$RANDOM | md5sum | sed -r 's/(..)/\1:/g; s/^(.{17}).*$/\1/;'`
sudo ifconfig wlan0 down
sudo /etc/init.d/networking stop > /dev/null
sudo ifconfig wlan0 hw ether $newmac
sudo /etc/init.d/networking start > /dev/null
sudo ifconfig wlan0 up
sudo dhclient
echo "New mac adress: $newmac"
else
echo "You need to be root to run this script. run: sudo $0"
fi
This is great idea. I changed all wlan0 to eth0
Had to renew the lease otherwise network unreachable:
sudo dhclient
I want to run this as a startup programme, or via cron. Is there any way to not run it as root?