Red Hat / CentOS: Swap / Change Ethernet Aliases

last updated in Categories , , , ,

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

14 comment

  1. 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. 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. 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.

  4. 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.

  5. 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.

  6. 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.

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

  8. 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.

  9. 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.

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

    Still, have a question? Get help on our forum!