Cloning VMs creates new network interface everytime on CentOS/RedHat VMs. I need to rename the ifcfg-eth* to the same name as the live interface on the VM.
What I would like to do is to use a script to compare MAC address of live NIC (take it from 'ifconfig' result) tp MAC addresses in all existing ifcfg-* files and rename the corresponding one to ifcfg-liveNICname.
Example:
# ifconfig
eth2 Link encap:Ethernet HWaddr 00:50:56:8F:5B:D5
there are 3 configuration files in /etc/sysconfig/network-scripts/:
ifcfg-eth0
ifcfg-Auto_eth0
ifcfg-eth1
script compares the MAC address 00:50:56:8F:5B:D5
to MAC addresses in all 3 files and renames the correct one (with the MAC address in question) to:
ifcfg-eth2
Preferably it could also change line NAME in the ifcfg file:
NAME=eth2
but not necessary.
I need that 'fix' so I could run a script on bunch of VMs to change DNS entries in one go. I have script for that but when ran on a test VM it creates a new ifcfg-eth2 file with just DNS entries in it while an active interface has a different name in the file e.g. ifcfg-eth0
As I'm no good in scripting I started with that:
nic=$(/sbin/route -n | grep "^0.0.0.0" | rev | cut -d' ' -f1 | rev)
ifconfig -a | grep $nic`
and that's all I got :(
Can anyone help please?