Linux Script to Enable Randomization of MAC Address on Startup

Linux Script to Enable Randomization of MAC Address on Startup

Made up this little thing for use on Debian\Ubuntu based systems in order to spoof the address for wlan0 to a different address every start up.

So whether you’re trying to preserve anonymity by installing it on a device that you use a lot on public networks, or cover your tracks in the snow when up to mischief by putting it on your Kali install, it is pretty handy.

Worth to note that it’s probably not a wise idea to assign this to an interface that you use static IP addressing for as you’d have to change your MAC in the router settings every start up, in which case it’s better to create a fake MAC address and make it set it to that every start up instead of randomizing by changing:

macchanger -r wlan0 —to–> macchanger –mac=XX:XX:XX:XX:XX:XX wlan0

To enable for other devices besides wlan0 just uncomment out the lines corresponding to your desired NIC in the part of the script as follows:

  1. echo “
  2. #! bin/sh
  3.  
  4. ifconfig wlan0 down
  5. #ifconfig wlan1 down
  6. #ifconfig eth0 down
  7. #ifconfig eth1 down
  8.  
  9. macchanger -r wlan0
  10. #macchanger -r wlan1
  11. #macchanger -r eth0
  12. #macchanger -r eth1
  13.  
  14. ifconfig wlan0 up
  15. #ifconfig wlan1 up
  16. #ifconfig eth0  up
  17. #ifconfig eth1 up
  18.  
  19. ”  > /etc/init.d/macchangerstartup

Instructions:

  1. Copy script and save as macchanger.sh to your home directory.
  2. Open up a terminal. Mark file as executable:                 
      sudo chmod +x macchanger.sh
  3. Simply run as root:
      sudo bash macchanger.sh

To temporarily disable MAC address to default:

    sudo macchanger -p wlan0

To revert permanently:

    sudo update-rc.d macchangerstartup

    sudo rm /etc/init.d/macchangerstartup