Red Hat (RHEL) / CentOS on VMWare

Thought I’d share this since I’m sure others have ran into the same grumpiness I have.
When copying RHEL or CentOS around on VMWare, the MAC on the ethernet interfaces do change. This is a normal thing, but RHEL & CentOS have pieces that link to MAC addresses instead of simply utilizing the name “eth0″, etc. This is an easy fix.. slap the following into a shell script and run it on the new copy. It will remove the persistent link, and update the /etc/sysconfig/network-scripts/ifcfg-eth0 with the current MAC. I did this by hand for the longest time but I’m tired of that now.. just got this together into a script.

#!/bin/sh
if grep -q eth1 /etc/udev/rules.d/70-persistent-net.rules; then
sed -i ‘/eth0/d’ /etc/udev/rules.d/70-persistent-net.rules;
sed -i ‘s/eth1/eth0/g’ /etc/udev/rules.d/70-persistent-net.rules;
ETHERNET=`grep eth0 /etc/udev/rules.d/70-persistent-net.rules | awk -F”,” ‘{print $4}’ | awk -F”\”” ‘{print $2}’`;
echo Ethernet Addr: $ETHERNET;
sed -i ‘s/HWADDR=”.*”/HWADDR=”‘$ETHERNET'”/’ /etc/sysconfig/network-scripts/ifcfg-eth0;
/sbin/start_udev
/sbin/service network restart;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.