“Device eth0 does not seem to be present” after moving or cloning a RHEL/CentOS 6.3 Virtual Machine in VSphere
You may see this error message after cloning or moving a machine in VSphere. It could happen when you are not using distributed switch or you are moving one Virtual Machine to another host where this machine is unable to find the same network label. When you power on CentOS/RHEL 6.4 linux machine it encounters the error “Device eth0 does not seem to be present”.
The problem arises when CentOS/RHEL 6.4 tries to remember the existing NIC of the virtual machine. But in case of moving or cloning VSphere changes the MAC address. Accordingly linux OS changes the device name from eth0 to eth1 and so on after finding a new MAC address. Backup your old files. You need to change and delete the old “SUBSYSTEM” entries (in case are not being used) and rename eth1 to etho in the file:
/etc/udev/rules.d/70-persistent-net.rule
accordingly to reflect the changes. After completing you also need to change
/etc/sysconfig/network-scripts/ifcfg-eth0 to change MAC and name of the eth0.
vi /etc/udev/rules.d/70-persistent-net.rule
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:02:bf:b5", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:8b:2f:fd", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:8b:6e:15", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
After editing the file it should look like this:
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:8b:6e:15", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
UUID="99ffe715-5ce4-4f00-a82a-34d7bbde30a0"
IPADDR=1.2.3.4
PREFIX=24
GATEWAY=1.2.3.4
DNS1=8.8.8.8
DOMAIN=abc.com
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
HWADDR=00:0c:29:02:bf:b5
USERCTL=no
Change the HWADDR entry to the MAC address with the one in Subsystem udev rules file. You may also confirm the MAC address in the Edit virtual machine settings, network cards in VCenter:
HWADDR=00:50:56:8b:6e:15
After completing this now we need to reload udev configuration to reflect the changes:
start_udev
Now restart network services:
service network restart
Updated: A python script that takes a MAC address as an input and replaces this MAC with old MAC address to solve the problem.
#!/usr/bin/env python
import os, subprocess
''' Check and tested with CentOS 6.4 for KVM machines
with Python 2.7 and Python 3.3
You just need to change 'new_mac_addr'
field to the address from VM details.
You can find it in details of VM in KVM or in VCenter.
Using python's subprocess.
Popen to execute the commands in shell. '''
def executeCmd(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
print('Command completed successfully')
''' return number of lines in /etc/udev/rules.d/70-persistent-net.rules '''
def line_count(file_name):
with open(file_name) as f:
return (len(f.readlines()))
rules_file = '/etc/udev/rules.d/70-persistent-net.rules'
eth_file = '/etc/sysconfig/network-scripts/ifcfg-eth0'
new_mac_addr = input('Please enter new MAC address: ') #'00:00:00:00:00:00' Don't forget to change it.
cmd_mac_replace = "sed -i -r 's/(..:){5}../"+new_mac_addr+"/' "+eth_file
cmd_subsystem_comment = "sed -i -r 's/^SUBSYSTEM/#SUBSYSTEM/g' " + rules_file
last_line = line_count(rules_file)
cmd_subsystem_uncomment = "sed -i -r '"+str(last_line)+"s/^#SUBSYSTEM/SUBSYSTEM/' "+rules_file
cmd_subsystem_replace_mac = "sed -i -r '"+ str(last_line)+"s/(..:){5}../"+new_mac_addr+"/' "+rules_file
cmd_subsystem_replace_eth_name = "sed -i -r '"+ str(last_line)+"s/eth1/eth0/' "+rules_file
cmd_udev = "start_udev"
#Executing commands in shell
executeCmd(cmd_mac_replace)
executeCmd(cmd_subsystem_comment)
executeCmd(cmd_subsystem_uncomment)
executeCmd(cmd_subsystem_replace_mac)
executeCmd(cmd_subsystem_replace_eth_name)
executeCmd(cmd_udev)
Andrew K
Thank you very much. I have spent 4 hours finding the solution of this problem. You have saved my life. Thanks a million