Red Hat / CentOS: Swap / Change Ethernet Aliases

by on January 14, 2009 · 14 comments· LAST UPDATED January 14, 2009

in , ,

Q. My Ethernet aliases are randomly switched and they are bound to the wrong interface. My eth0 became eth1 and eth1 become eth0. This is causing all sort of trouble for services and firewall configurations. How do I swap back and make sure Ethernet aliases works correctly under CentOS Linux server?

A. It is possible to bind the MAC address to the network interfaces in configuration files. This will ensure that eth0,eth1 are assigned the way you want it.

Open each interfaces configuration file:

  1. /etc/sysconfig/network-scripts/ifcfg-eth0 - eth0 configuration file
  2. /etc/sysconfig/network-scripts/ifcfg-eth1 - eth1 configuration file

Open file for eth0 using vi, type:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Add the following line:

HWADDR=<MAC address of the network interface> 

Here is my sample config file:

# Intel Corporation 80003ES2LAN Gigabit Ethernet Controller (Copper)

Save and close the file. Update /etc/sysconfig/network-scripts/ifcfg-eth1 file with correct HWADDR entry. Once done restart networking or just reboot the server:
# reboot

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 14 comments… read them below or add one }

1 James January 15, 2009 at 12:14 am

Althought the HW address does address the problem in RHEL4/CentOS4 it doesn’t work right in RHEL5/CentOS5 if the box has mixed onboard and PCI Nics or 3 or more Nics. I’ve had a devil of a time with these two and the kernel on RHEL/CentOS getting around this.

In the end my solution (that worked) was to build my own kernel from a newer version of source than RH provides (one from Fedora to be exact). Once I did, I stopped losing NIC’s and having them switch names on me.

What happens in the above scenario is if you do already have the HWADDR line it will refuse to initialize the NIC since the HWADDR (mac) doesn’t match.


2 Jeff Schroeder January 15, 2009 at 1:50 pm

For those who don’t know, the Redhat/Fedora ifup/ifdown scripts that read the HWADDR variable are using the ip(8) command to set the names.

You can rename eth5 to eth0 like this:
ip link set down eth5
ip link set eth5 name eth0

Afterwards you’ll need to add an ip and up the interface with the ip(8) or ifconfig(8) commands.

Jeff Schroeder


3 Srinivas.Y May 29, 2009 at 9:54 am

Very good tip….


4 Nicholas Redgrave June 15, 2009 at 4:18 pm

I followed the original tip with my Fedora 11 installation but it didn’t work due to a conflict with udev.
I found that I also had to edit “/etc/udev/rules.d/70-persistent-net.rules” and swap the “NAME=eth0″ and “NAME=eth1″ entries over in that file before it worked.


5 Ploink December 10, 2009 at 12:49 pm

In Fedora, aliases are assigned by udev.
As Nicholas did, you can simply change the order by editing /etc/udev/rules.d/70-persistent-net.rules and reboot. You do not need to edit/change anything else.

I figured this out when I replaced a network card. I started with eth0 and eth1, then replaced eth1 with a different card and ended up with eth0 and eth2. I deleted the old card from the rules file and changed the new from eth2 to eth1.

I do not recommend to specify the HW address in the ifcfg* files.


6 gndudeus October 9, 2010 at 4:09 pm

I encountered this problem today and was able to resolve it using the following steps;

OS: CentOS release 5.2

1) First check hwaddress of your eth0 and eth1 (and any others you may have)-do this by simply using ‘ifconfig’ command and note down the hwaddress.
2) Next enter into your interface config and insert the hwaddr like this vi /etc/sysconfig/network-scripts/ifcfg-eth0. HWADD=mac_address
3) Repeat step 2 for your other network cards.
4) goto /etc/sysconfig/hwconf and under NETWORK, note your driver, e.g device: eth1 driver: r8169. Check this for all your network cards.
5) Now finally goto /etc/modprobe.conf
6) Match your ethernet cards with their correct drivers, e.g. alias eth0 skge
7) Save and reboot.

The above worked perfectly for me. I hope it does help you too.


7 Darshak Thakore November 10, 2010 at 4:35 pm

Thanks for the tip gndudeus.

Your tip worked for me with CentOS 5.5

With systems that have switched to udev (Fedora, Ubuntu), editing the 70-persistent-net.rules work but for older systems like CentOS 5, this tip is the only way to safely swap eth devices.


8 Luis Talora January 5, 2011 at 1:32 pm

Excelent tip! Just what I was looking for. Thanks!


9 johnny john john February 3, 2011 at 2:21 pm

perfect !! it works for me too


10 anas alaayah June 30, 2011 at 1:00 pm

i’ve followed the steps but when i reboot the system the original mac address back
is there any other solution
thanks all


11 S3nd0r September 18, 2011 at 4:26 pm

It definitely does not work on CentOS 6.0; I get back the old address just like anas.


12 Eric Zhu October 22, 2011 at 3:36 pm

CentOS 6.0 implement a new system called NetworkManger to manage network . I have to stop this service first to rename network interface with this resolution.


13 John McLean February 21, 2012 at 11:36 am

On a cloned (VM) Centos 6.2 machine you will need to delete the below file:


also remove mac info from:


Sourced from here.

Edited by admin. Reason – formatting.


14 mrbyte May 24, 2012 at 2:47 pm

the step described by gndudeus worked perfectly for me with Centos 5.2 and 3 network interface, great.


Leave a Comment

Tagged as: , , , , , , , , , , , , ,

Previous Faq:

Next Faq: