#!/bin/bash # #script to change MAC ("hardware address") #Pete Nesbitt Sept 2005 # prompt for change or rest # if new, prompt for new mac # store existing hwadress # get confirmation to continue or exit program CHANGE_MAC="Y" echo "" echo "" printf " => Change MAC Address? (N/n/R/r to Reset to Old Mac): [${CHANGE_MAC}]" read CHANGE_MAC if [ "$CHANGE_MAC" = "" ]; then CHANGE_MAC="Y" fi if [ "$CHANGE_MAC" = "Y" ] || [ "$CHANGE_MAC" = "y" ] ; then echo "" # Save original MAC (save to file for next run, tmp is okay as system resets anyway on reboot) OLD_MAC="`/sbin/ifconfig|grep eth0|awk '{print $5}'`" echo $OLD_MAC > /tmp/old_mac.txt # save the default route DEFAULT_ROUTE="`/sbin/route -n|grep UG|awk '{print $2}'`" echo $DEFAULT_ROUTE > /tmp/default_route.txt # Get new MAC NEW_MAC="" printf " => Enter NEW MAC Address? (aa:bb:cc:dd:ee:ff): [${NEW_MAC}]" read NEW_MAC /sbin/ifconfig eth0 down /sbin/ifconfig eth0 hw ether $NEW_MAC /sbin/ifconfig eth0 up # reinstate default route /sbin/route add default gw ${DEFAULT_ROUTE} dev eth0 else # reset old MAC # now we will need to read data from files, not vars RESET_MAC="Y" echo "" echo " Reset MAC to original?" echo "" printf " => Reset to original MAC Address?: [${RESET_MAC}]" read RESET_MAC if [ "$RESET_MAC" = "" ]; then RESET_MAC="Y" fi if [ "$RESET_MAC" != "Y" ] && [ "$RESET_MAC" != "y" ] ; then echo "Program exited by user." echo "" exit 0 else /sbin/ifconfig eth0 down /sbin/ifconfig eth0 hw ether `cat /tmp/old_mac.txt` /sbin/ifconfig eth0 up /sbin/route add default gw `cat /tmp/default_route.txt` fi fi echo "" echo "" echo "NEW ETHERNET (eth0) CONFIGURATION:" /sbin/ifconfig eth0 echo "" echo "ROUTING INFORMATION:" /sbin/route -n