How to change the network device name from eth5 to eth0

As I’m using a lot Virtualbox, I have often encountered the situation where I had to adapt the network adapters to follow some naming standards (to match my scripts 🙂 of course).

I’ve created some time ago a BASE VM where I deployed all the packages that I would possibly need for any ORACLE installation. On this BASE VM I have created 3 network adapters (1 bridged one and 2 host-only ones). Each time I need to create a VM, I’m just cloning the BASE VM – it saves A LOT of time. However, I still need to apply some changes, such as the hostname and network adapters.

So, here is what I did:

After the new VM is up&running, grab the MAC addresses first:

[[email protected] rules.d]# ifconfig | grep HWadd
eth3      Link encap:Ethernet  HWaddr 08:00:27:50:9C:9D
eth4      Link encap:Ethernet  HWaddr 08:00:27:B6:B4:99
eth5      Link encap:Ethernet  HWaddr 08:00:27:B1:8F:0A
[[email protected] rules.d]#

Go to /etc/udev/rules.d/ and edit 70-persistent-net.rules

This is what I have:

[[email protected] rules.d]# cat 70-persistent-net.rules
# 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 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:22:74:f9", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:b1:b2:5c", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:89:47:fd", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:50:9c:9d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:b6:b4:99", ATTR{type}=="1", KERNEL=="eth*", NAME="eth4"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:b1:8f:0a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth5"
[[email protected] rules.d]#

As you can see, the new names are eth3 – eth4 – eth5. I’m going to delete the previous ones and rename the new ones as eth0 – eth1 – eth2. My file is going to look like this:

[[email protected] rules.d]# cat 70-persistent-net.rules
# 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 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:50:9c:9d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:b6:b4:99", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:b1:8f:0a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
[[email protected] rules.d]#

The second step is to go here “/etc/sysconfig/network-scripts” and adapt the ifcfg-eth* files accordingly.

[[email protected] network-scripts]# ll ifcfg-eth*
-rw-r--r--. 1 root root 231 Jun 18  2014 ifcfg-eth0
-rw-r--r--. 1 root root 231 Jun 18  2014 ifcfg-eth1
-rw-r--r--. 1 root root 231 Jun 18  2014 ifcfg-eth2
[[email protected] network-scripts]#

Delete in each file the UUID line, replace the MAC address with the one u get with “ifconfig | grep HW” and adapt the Name with a proper one.

The last step is to REBOOT the server and check the network adapters.

Leave Comment

Your email address will not be published. Required fields are marked *