Skip to content

Instantly share code, notes, and snippets.

@trevorackerman
Created February 28, 2014 23:59
Show Gist options
  • Save trevorackerman/9282489 to your computer and use it in GitHub Desktop.
Save trevorackerman/9282489 to your computer and use it in GitHub Desktop.
A Script that fixes broken eth0 on CentOS VM Clones
#!/bin/sh
echo "To attempt to fix networking on eth0 (part of which involves rebooting) enter 'y'"
read answer
echo "Answer was $answer"
if [ "$answer" == "y" ]
then
echo "Attempting to fix eth0"
newaddr=`find /sys/devices -name eth0 -exec cat {}/address \;`
find /etc/sysconfig -type f -name 'ifcfg-eth0' -exec sed -i -e "s/HWADDR=.*/HWADDR=$newaddr/g" {} \;
rm -f /etc/udev/rules.d/70-persistent-net.rules
shutdown -r now
else
echo "You have chosen to not fix eth0 at this time"
fi

A Script for fixing broken eth0 on CentOS VM

Whenever I go to clone a CentOS VM, I can expect that eth0 will be broken. There are plenty of articles on the web that give instructions on how to manually fix this. There also seems to be some confusion when you start reading forum posts on the same topic.

How boring!

Instead one can use this script which will fix up your CentOS VM Clone's eth0!

Note that it reboots your VM, however it is friendly enough to require you to enter 'y'.

Now of course the next step is for a startup script that detects a broken eth0 and run this for you automatically. I haven't done this yet. What can I say, I had to quit while I was ahead ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment