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.

Advertisement

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

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

14 comments… add one
  • 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:

    /etc/udev/rules.d/70-persistent-net.rules

    also remove mac info from:

    /etc/sysconfig/network-scripts/ifcfg-eth0

    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. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.