Red Hat / CentOS: Swap / Change Ethernet Aliases

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)
DEVICE=eth0
BOOTPROTO=static
DHCPCLASS=
HWADDR=00:19:B1:2A:BA:B8
IPADDR=10.10.11.24
NETMASK=255.255.255.192
ONBOOT=yes

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

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 4 comments… read them below or add one }

1 James 01.15.09 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 01.15.09 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
http://www.digitalprognosis.com

3 Srinivas.Y 05.29.09 at 9:54 am

Very good tip….

4 Nicholas Redgrave 06.15.09 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.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

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

Previous post: Red Hat / CentOS: Check / List Running Services

Next post: Can I Use Multiple Virtualization Technologies Simultaneously under Linux?