Changing the ethX to Ethernet Device Mapping in EL5

From Alteeve Wiki
Jump to navigation Jump to search

 AN!Wiki :: How To :: Changing the ethX to Ethernet Device Mapping in EL5

Note: This is for EL5 (CentOS 5.5, specifically). It also makes reference to Xen, which you can ignore if you wish.

When you have two or more ethernet devices in one machine, the Red Hat/CentOS install may not install them in the order you want. This document will show you how to change the ethX to ethernet device mapping.

Example

I find it easier to follow instructions when I have an example to follow, so let me provide one here:

Desired Mapping

Let's assume that you want this:

  • eth0
    • MAC: 00:aa:bb:cc:dd:ee
  • eth1
    • MAC: 00:11:22:33:44:55
  • eth2
    • MAC: 00:ff:ee:dd:88:99

Initial Mapping

Now lets assume you got this:

  • eth0
    • MAC: 00:ff:ee:dd:88:99
  • eth1
    • MAC: 00:11:22:33:44:55
  • eth2
    • MAC: 00:aa:bb:cc:dd:ee

The Problem

In the above example, eth1 is where we want it, so we leave it alone. The problem is that eth0 and eth2 are reversed.

If your not sure which ethX is currently mapped to which physical port, using ethtool -p ethX will make the light on the port blink.

Note: This works for most, but not all hardware.

An Assumption

This tutorial assumes that you are using Xen. Mainly because some Xen-related tutorials reference this. If you are not using Xen, you can safely ignore any reference to it.

The Fix

First, stop xend and network. This is important because if you change the MAC address to ethX mapping while the network is still up, the initd script will fail to bring down the network devices. The reason for stopping xend is because it is also integral to networking.

/etc/init.d/xend stop
/etc/init.d/network stop

Now go to the directory that contains the network configuration files and then use cat to see the contents of the ifcfg-ethX network configuration files:

cd /etc/sysconfig/network-scripts/
cat ifcfg-eth0
cat ifcfg-eth1
cat ifcfg-eth2

This will produce output something like this:

root@an_san01:/etc/sysconfig/network-scripts# cat ifcfg-eth0
# Intel Corporation 82540EM Gigabit Ethernet Controller
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR=00:AA:BB:CC:DD:EE

root@an_san01:/etc/sysconfig/network-scripts# cat ifcfg-eth1
# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
DEVICE=eth1
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR=00:11:22:33:44:55

root@an_san01:/etc/sysconfig/network-scripts# cat ifcfg-eth2
# D-Link System Inc DGE-560T PCI Express Gigabit Ethernet Adapter
DEVICE=eth2
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR=00:FF:EE:DD:88:99

The important lines are the HWADDR=... lines. Don't worry if the rest of the contents differ at this point. The above examples are intentionally generic and minimalist. For now, we are going to ignore them.

With networking stopped, all we need to do is change the HWADDR=... lines in ifcfg-eth0 to have the MAC address from ifcfg-eth2 and vice-versa.

So then, edit ifcfg-eth0 to look like this:

vim ifcfg-eth0
# D-Link System Inc DGE-560T PCI Express Gigabit Ethernet Adapter
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR=00:FF:EE:DD:88:99

And then edit ifcfg-eth2 to look like this:

vim ifcfg-eth2
# Intel Corporation 82540EM Gigabit Ethernet Controller
DEVICE=eth2
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR=00:AA:BB:CC:DD:EE

Note that I changed the comment at the top of the file to reflect the hardware description of the ethernet device. This is set by the installer and I like to keep it accurate. If you wish, you can simply delete it as it has no effect on the function of the network device.

Once the changes are complete, simply restart networking and xend:

/etc/init.d/xend start
/etc/init.d/network start

You should be able to see that it is working by typing ifconfig and seeing something like this:

ifconfig
eth0      Link encap:Ethernet  HWaddr 00:FF:EE:DD:88:99
          inet addr:192.168.1.71  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::92e6:baff:fe71:82d8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:555 errors:0 dropped:0 overruns:0 frame:0
          TX packets:331 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:60616 (59.1 KiB)  TX bytes:56370 (55.0 KiB)

eth1      Link encap:Ethernet  HWaddr 00:11:22:33:44:55
          inet addr:10.0.0.71  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::221:91ff:fe19:965a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:66 errors:0 dropped:0 overruns:0 frame:0
          TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:11802 (11.5 KiB)  TX bytes:10708 (10.4 KiB)

eth2      Link encap:Ethernet  HWaddr 00:AA:BB:CC:DD:EE
          inet addr:10.0.1.71  Bcast:10.0.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20e:cff:fe59:4578/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:65 errors:0 dropped:0 overruns:0 frame:0
          TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:11670 (11.3 KiB)  TX bytes:10734 (10.4 KiB)

As before, don't worry if the inet addr:... lines are different or missing. What is important is that the HWaddr ... entries correspond properly to the ethX devices. If they do, you are done! If they don't, double-check the ifcfg-ethX files have the proper HWADDR=... entries.

Caveat!

NOTE: If you are using a vlan, the device facing the vlan can not have the HWADDR=... value set! Set the others and leave this commented out. Otherwise, because of how the vlan loads, the OS will not see the physical device and will fail to bring up the interface at all.

 

Any questions, feedback, advice, complaints or meanderings are welcome.
Alteeve's Niche! Enterprise Support:
Alteeve Support
Community Support
© Alteeve's Niche! Inc. 1997-2024   Anvil! "Intelligent Availability®" Platform
legal stuff: All info is provided "As-Is". Do not use anything here unless you are willing and able to take responsibility for your own actions.