Skip to content

Instantly share code, notes, and snippets.

@DBezemer
Created September 18, 2017 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DBezemer/c86b0d4ade563b9da33b0e927ec37b1f to your computer and use it in GitHub Desktop.
Save DBezemer/c86b0d4ade563b9da33b0e927ec37b1f to your computer and use it in GitHub Desktop.
Fix CentOS 6 network after VM clone
#!/bin/bash
# Annoying bug in vmware guest centos6
# eth0 doesn't exist
ifconfig eth0 2>/dev/null >/dev/null
if [ $? -ne 0 ] ; then
# Rename eth1 with eth0
echo "UDEV Config..."
rm /etc/udev/rules.d/70-persistent-net.rules
# Change ifcfg-eth0 with hostname address (in /etc/hosts)
echo "Changing eth0 address..."
mac=`ifconfig eth1 | grep eth1 | awk '{ print $5}'`
hostname=`hostname`
ip=`grep $hostname /etc/hosts|cut -s -f 1`
rm -f /etc/sysconfig/network-scripts/ifcfg-eth1
cfg=`grep -v IPADDR /etc/sysconfig/network-scripts/ifcfg-eth0 |grep -v HWADDR`
echo "$cfg" > /etc/sysconfig/network-scripts/ifcfg-eth0
echo "HWADDR=\"$mac\"" >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo "IPADDR=\"$ip\"" >> /etc/sysconfig/network-scripts/ifcfg-eth0
# Apply changes
echo "Applying changes..."
service network stop
service NetworkManager stop
ifconfig eth1 down
udevadm trigger
udevadm control --reload-rules
service network start
service NetworkManager start
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment