Skip to content

Instantly share code, notes, and snippets.

@kbinani
Created December 12, 2012 14:46
Show Gist options
  • Save kbinani/4268293 to your computer and use it in GitHub Desktop.
Save kbinani/4268293 to your computer and use it in GitHub Desktop.
An utility script to correct MAC address configs. This script recovers MAC address mismatch between actual NIC's address and system config. This may useful for copied VM(ex. VirtualBox, VMWare) image.
#!/bin/bash
cat /etc/udev/rules.d/70-persistent-net.rules \
| grep -v 'SUBSYSTEM=="net"' \
> /tmp/net.rules
mv -f /tmp/net.rules /etc/udev/rules.d/70-persistent-net.rules
i=0
for hwaddr in $(/sbin/ifconfig -a | grep '^eth' | grep 'HWaddr' | sed 's/^.*HWaddr \([0-9A-Z:]*\).*$/\1/g'); do
cat /etc/sysconfig/network-scripts/ifcfg-eth$i \
| sed "s/HWADDR=.*/HWADDR=${hwaddr}/g" \
> /tmp/ifcfg-eth$i
mv -f /tmp/ifcfg-eth$i /etc/sysconfig/network-scripts/ifcfg-eth$i
i=$(expr $i + 1)
done
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment