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)

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 14 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
14 comments… add one
  • James Jan 15, 2009 @ 0:14

    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.

  • Jeff Schroeder Jan 15, 2009 @ 13:50

    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

  • Srinivas.Y May 29, 2009 @ 9:54

    Very good tip….

  • Nicholas Redgrave Jun 15, 2009 @ 16:18

    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.

  • Ploink Dec 10, 2009 @ 12:49

    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.

  • gndudeus Oct 9, 2010 @ 16:09

    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.

  • Darshak Thakore Nov 10, 2010 @ 16:35

    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.

  • Luis Talora Jan 5, 2011 @ 13:32

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

  • johnny john john Feb 3, 2011 @ 14:21

    perfect !! it works for me too

  • anas alaayah Jun 30, 2011 @ 13:00

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

  • S3nd0r Sep 18, 2011 @ 16:26

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

  • Eric Zhu Oct 22, 2011 @ 15:36

    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.

  • John McLean Feb 21, 2012 @ 11:36

    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.

  • mrbyte May 24, 2012 @ 14:47

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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum