Sometimes the NIC name in output of ip addr
or ifconfig
is not the same with that defined in /etc/sysconfig/network-scripts/ifcfg-eth0, for example, in ifcfg-eth0, the first line is:
DEVICE="eth0"
but the output of ip addr
is:
2: eth1: <BROADCAST...
This is because the source of ip addr
is /etc/udev/rules.d/70-persistent-net.rules. Edit this file to correct the NIC name.
The total step to fix network of a centos VM is:
-
vi /etc/sysconfig/network // fix hostname and gateway IP
-
vi /etc/sysconfig/network-scripts/ifcfg-eth0 // fix NIC name, host IP and netmask
-
vi /etc/udev/rules.d/70-persistent-net.rules // NIC name and hardware address should be the same with that in file ifcfg-eth0
-
reboot
Update 2014-9-19
The MAC address is determined by ifconfig -a
, so copy IP address after "HWaddr" in command output, and modify "HWADDR" in /etc/.../ifcfg-eth0, then sudo service network restart
.