#!/bin/bash ## rndmac -- Randomize network interface MAC addresses ## ## Only the second half of the MAC address is randomized. ## The OUI half is left the same. # Get interface names if ! echo :$PATH: | grep -q ":/sbin:"; then # $PATH has /sbin? PATH=$PATH:/sbin; fi IFs=$(ip -o link show | awk -F':' '{print $2}' ) # Generate random addresses, set them, and display some output if sudo service network-manager stop; then for nic in $IFs; do if test $nic != "lo"; then # exclude local interface macb4=$(cat /sys/class/net/$nic/address) randmac=$(openssl rand -hex 1):$(openssl rand -hex 1):$(openssl rand -hex 1) fullnewmac=$(cat /sys/class/net/$nic/address | cut -c -9)$randmac sudo ifconfig $nic down && \ sudo ifconfig $nic hw ether $fullnewmac && \ sudo ifconfig $nic up && \ macafter=$(cat /sys/class/net/$nic/address) # Output echo "$nic" echo "Previous MAC: $macb4" echo "Current MAC: $macafter" fi done sudo service network-manager start fi