Sunday, 2 June 2013

Centos 6/RHEL change eth1 back to eth0 or rename device

Occasionally because of a hardware change (you may have used a different ethernet device & then removed it) your original eth0 gets it's name changed to eth1, or if using a number of devices the names get changed around out of the order in which you prefer to see them. This can be annoying and you may want to change the names back. You can do this by altering two files in your system.

First go into /etc/udev/rules.d/ 

Vi and Vim commands

$ sudo vi /etc/udev/rules.d/70-persistent-net.rules 

/etc/udev/rules.d/70-persistent-net.rules
First establish if there are any unused devices still present and delete the entry, remembering to rename or remove the corresponding ifcfg file in /etc/sysconfig/network-scripts.

For example, above I want to delete the old eth0 entry and then find the eth1 device I am still using but wish to rename and change the NAME parameter from eth1 back to eth0.

So make your adjustments or removals in 70-persistent-net.rules and then go to /etc/sysconfig/network-scripts where you will alter and rename the ifcfg-eth1 file.

$ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth1

eth1 renamed to eth0
Change the parameters to suit, DEVICE="eth0" etc, not forgetting the HWADDR, which is the Mac address from the ifconfig or dmesg command. Then you can rename it as in the examples above where you can see the that the Hwaddr for eth0 in the lower image is the same as the Hwaddr for the renamed eth1 from the top image.

$ sudo mv /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth0

Or write a new file completely with contents similar to below

TYPE=Ethernet
DEVICE=eth0        
BOOTPROTO=static
DHCPCLASS=
IPADDR=192.168.0.100
GATEWAY=192.168.0.1
BROADCAST=192.168.0.255
HWADDR=6C:F0:49:09:47:17 
NETMASK=255.255.255.0
ONBOOT=yes
ONHOTPLUG=yes
PEERDNS=no
USERCTL=yes
IPV6INIT=no


Which are typical parameters for someone using a static IP address on a wired ethernet card. Finally, issue the command

$ sudo service network restart

Or reboot your system to enable the new named device.

2 comments:

  1. The interface name of a network device increases if the mac address of the physical or virtual network card changes. A common case is if you made a clone of a virtual machine for example via VMware or KVM or replaced a physical network card in a non virtualized server http://namhuy.net/376/change-network-device-name-from-eth1-back-to-eth0.html

    ReplyDelete
  2. It increments appropriately according to each address change.

    ReplyDelete