Changing the ethX to Ethernet Device Mapping in EL6 and Fedora 12 to 14: Difference between revisions

From Alteeve Wiki
Jump to navigation Jump to search
(Created page with '{{howto_header}} When you have two or more ethernet devices in one machine, the Fedora install may not install them in the order you want. This document will show you how to cha…')
 
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{howto_header}}
{{howto_header}}


When you have two or more ethernet devices in one machine, the Fedora install may not install them in the order you want. This document will show you how to change the <span class="code">ethX</span> to ethernet device mapping.
{{note|1=This applies up to Fedora 14. Fedora 15 works quite differently now that it uses <span class="code">biosdevname</span>. Please follow [[Changing Ethernet Device Names in EL7 and Fedora 15+|this tutorial]] for Fedora 15 and newer.}}
 
When you have two or more ethernet devices in one machine, the [[EL6]] or Fedora install may not install them in the order you want. This document will show you how to change the <span class="code">ethX</span> to physical ethernet device mapping.
 
This is desirable in cases where specific network cards need to be used on specific networks, and you are interested in maintaining common <span class="code">ethX</span> names across servers. A practical example is found in the [[2-Node Red Hat KVM Cluster Tutorial]].


= For the Impatient =
= For the Impatient =


Assuming that <span class="code">NetworkManager</span> is already removed.
Assuming that <span class="code">NetworkManager</span> is already removed.  This example will swap <span class="code">eth0</span> and <span class="code">eth1</span>.


<source lang="bash">
<source lang="bash">
# Stop the network daemon
/etc/init.d/network stop
/etc/init.d/network stop
cd /etc/sysconfig/network-scripts
# Move your ifcfg files to the device names you desire
mv ifcfg-eth0 ifcfg-temp
mv ifcfg-eth1 ifcfg-eth0
mv ifcfg-temp ifcfg eth1
# Modify DEVICE lines to match new file names
vim /etc/sysconfig/network-scripts/ifcfg-eth*
vim /etc/sysconfig/network-scripts/ifcfg-eth*
# Make changes as needed
# Make changes as needed
vim /etc/udev/rules.d/70-persistent-net.rules
# Remove udev rules file
# Make changes as needed
rm /etc/udev/rules.d/70-persistent-net.rules
start_udev
start_udev
/etc/init.d/network start
/etc/init.d/network start
Line 22: Line 33:


I find it easier to follow instructions when I have an example to follow, so let me provide one here:
I find it easier to follow instructions when I have an example to follow, so let me provide one here:
I've got the same hardware in the same configuration in both of my storage nodes. To keep things simple, I want to make sure that both nodes use the same <span class="code">ethX</span> name for the network devices on each of the given networks.


== Desired Mapping ==
== Desired Mapping ==
Line 28: Line 41:


* <span class="code">eth0</span>
* <span class="code">eth0</span>
** MAC: <span class="code">00:aa:bb:cc:dd:ee</span>
** MAC: <span class="code">90:E6:BA:71:82:EA</span>
* <span class="code">eth1</span>
* <span class="code">eth1</span>
** MAC: <span class="code">00:11:22:33:44:55</span>
** MAC: <span class="code">00:21:91:19:96:53</span>
* <span class="code">eth2</span>
* <span class="code">eth2</span>
** MAC: <span class="code">00:ff:ee:dd:88:99</span>
** MAC: <span class="code">00:0E:0C:59:46:E4</span>


== Initial Mapping ==
== Initial Mapping ==


Now lets assume you got this:
When the Fedora install finished, you may have gotten this:


* <span class="code">eth0</span>
* <span class="code">eth0</span>
** MAC: <span class="code">00:ff:ee:dd:88:99</span>
** MAC: <span class="code">00:21:91:19:96:53</span>
* <span class="code">eth1</span>
* <span class="code">eth1</span>
** MAC: <span class="code">00:11:22:33:44:55</span>
** MAC: <span class="code">90:E6:BA:71:82:EA</span>
* <span class="code">eth2</span>
* <span class="code">eth2</span>
** MAC: <span class="code">00:aa:bb:cc:dd:ee</span>
** MAC: <span class="code">00:0E:0C:59:46:E4</span>


== The Problem ==
== The Problem ==


In the above example, <span class="code">eth1</span> is where we want it, so we leave it alone. The problem is that <span class="code">eth0</span> and <span class="code">eth2</span> are reversed.
In the above example, <span class="code">eth2</span> is where we want it, so we leave it alone. The problem is that <span class="code">eth0</span> and <span class="code">eth1</span> are reversed.


== The Fix ==
== The Fix ==


First, stop <span class="code">xend</span> and <span class="code">network</span>. This is important because if you change the MAC address to <span class="code">ethX</span> mapping while the network is still up, the <span class="code">initd</span> script will fail to bring down the network devices. The reason for stopping <span class="code">xend</span> is because it is also integral to networking.
What we need to do is modify the <span class="code">DEVICE=...</span> line in each <span class="code">ifcfg-ethX</span> file to reflect the order we want.
 
To avoid confusion later on, we should also rename the files to reflect the new device names.
 
=== Stopping the Network ===
 
First, stop the <span class="code">network</span>. This is important because if you change the MAC address mapping while the network is still up, the <span class="code">init.d</span> script will fail to bring down the network devices and you will need to reboot for the changes to take effect.


<source lang="bash">
<source lang="bash">
Line 57: Line 76:
</source>
</source>


Now go to the directory that contains the network configuration files and then use <span class="code">cat</span> to see the contents of the <span class="code">ifcfg-ethX</span> network configuration files:
=== Interface Configuration ===
 
Go to the <span class="code">/etc/sysconfig/network-scripts/</span> directory and then use <span class="code">cat</span> to see the contents of the <span class="code">ifcfg-eth*</span> network configuration files:
 
{{note|1=The <span class="code">cat</span> output below only shows the lines we're interested in. You will likely see several more lines not shown below.}}


<source lang="bash">
<source lang="bash">
cd /etc/sysconfig/network-scripts/
cd /etc/sysconfig/network-scripts
cat ifcfg-eth0
cat ifcfg-eth0
</source>
<source lang="text">
DEVICE="eth0"
HWADDR="00:21:91:19:96:53"
</source>
<source lang="bash">
cat ifcfg-eth1
cat ifcfg-eth1
</source>
<source lang="text">
DEVICE="eth1"
HWADDR="90:E6:BA:71:82:EA"
</source>
<source lang="bash">
cat ifcfg-eth2
cat ifcfg-eth2
</source>
<source lang="text">
DEVICE="eth2"
HWADDR="00:0E:0C:59:46:E4"
</source>
</source>


This will produce output something like this:
The important lines are the <span class="code">DEVICE=...</span> and <span class="code">HWADDR=...</span> lines. The rest of the lines will very likely differ from the output above. It is outside the scope of this tutorial to cover the various settings.  For an exhaustive list of available options, please see the [https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-networkscripts-interfaces.html Red Hat EL6] or the [http://docs.fedoraproject.org/en-US/Fedora/12/html/Deployment_Guide/s1-networkscripts-interfaces.html Fedora 12] documentation.


<source lang="text">
First, change the file names to reflect the device order that you want.  In this example we need to swap <span class="code">eth0</span> and <span class="code">eth1</span>.
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
<source lang="bash">
# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
cd /etc/sysconfig/network-scripts
DEVICE=eth1
mv ifcfg-eth0 ifcfg-temp
BOOTPROTO=dhcp
mv ifcfg-eth1 ifcfg-eth0
ONBOOT=yes
mv ifcfg-temp ifcfg-eth1
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
</source>
</source>


The important lines are the <span class="code">HWADDR=...</span> 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.
Using your editor of choice, open each file and change the <span class="code">DEVICE=...</span> to match the new filename.


With networking stopped, all we need to do is change the <span class="code">HWADDR=...</span> lines in <span class="code">ifcfg-eth0</span> to have the MAC address from <span class="code">ifcfg-eth2</span> and vice-versa.
Here is the updated files with updated network settings:


So then, edit <span class="code">ifcfg-eth0</span> to look like this:
<source lang="bash">
<source lang="bash">
vim ifcfg-eth0
cd /etc/sysconfig/network-scripts
cat ifcfg-eth0
</source>
<source lang="text">
DEVICE="eth0"
HWADDR="90:E6:BA:71:82:EA"
</source>
<source lang="bash">
cat ifcfg-eth1
</source>
</source>
<source lang="text">
<source lang="text">
# D-Link System Inc DGE-560T PCI Express Gigabit Ethernet Adapter
DEVICE="eth1"
DEVICE=eth0
HWADDR="00:21:91:19:96:53"
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR=00:FF:EE:DD:88:99
</source>
</source>
And then edit <span class="code">ifcfg-eth2</span> to look like this:
<source lang="bash">
<source lang="bash">
vim ifcfg-eth2
cat ifcfg-eth2
</source>
</source>
<source lang="text">
<source lang="text">
# Intel Corporation 82540EM Gigabit Ethernet Controller
DEVICE="eth2"
DEVICE=eth2
HWADDR="00:0E:0C:59:46:E4"
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR=00:AA:BB:CC:DD:EE
</source>
</source>


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.
=== 'udev' Configuration ===


Once the changes are complete, simply restart networking and xend:
The user-space device manager, [http://en.wikipedia.org/wiki/Udev udev], maintains a list of configuration files that help ensure that hardware to <span class="code">/dev</span> (software) mappings stay consistent, even when hardware is hot swapped or moved between physical connections. For networking hardware, this mapping is recorded in the <span class="code">70-persistent-net.rules</span>.
 
Simply delete this file.


<source lang="bash">
<source lang="bash">
/etc/init.d/xend start
rm /etc/udev/rules.d/70-persistent-net.rules
/etc/init.d/network start
</source>
</source>


You should be able to see that it is working by typing <span class="code">ifconfig</span> and seeing something like this:
=== Making the Changes Take Effect ===
 
First, you need to reload <span class="code">udev</span> so that it updates the mapping in memory. This is done using the <span class="code">start_udev</span> program:


<source lang="bash">
<source lang="bash">
ifconfig
start_udev
</source>
</source>
<source lang="text">
<source lang="text">
eth0      Link encap:Ethernet HWaddr 00:FF:EE:DD:88:99
Starting udev:                                             [ OK ]
          inet addr:192.168.1.71 Bcast:192.168.1.255  Mask:255.255.255.0
</source>
          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
With <span class="code">udev</span> updated, the last step is to restart the <span class="code">network</span> daemon:
          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
<source lang="bash">
          inet addr:10.0.1.71  Bcast:10.0.1.255  Mask:255.255.255.0
/etc/init.d/network start
          inet6 addr: fe80::20e:cff:fe59:4578/64 Scope:Link
</source>
          UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
<source lang="text">
          RX packets:65 errors:0 dropped:0 overruns:0 frame:0
Bringing up loopback interface:                           [ OK ]
          TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
Bringing up interface eth0:                               [  OK  ]
          collisions:0 txqueuelen:0
Bringing up interface eth1:                               [  OK  ]
          RX bytes:11670 (11.3 KiB) TX bytes:10734 (10.4 KiB)
Bringing up interface eth2:                               [  OK ]
</source>
</source>


As before, don't worry if the <span class="code">inet addr:...</span> lines are different or missing. What is important is that the <span class="code">HWaddr ...</span> entries correspond properly to the <span class="code">ethX</span> devices. If they do, you are done! If they don't, double-check the <span class="code">ifcfg-ethX</span> files have the proper <span class="code">HWADDR=...</span> entries.
Done! use <span class="code">ifconfig</span> to verify that the network cards are properly assigned to the specified <span class="code">ethX</span> names.


== Caveat! ==
== Caveat! ==

Latest revision as of 02:37, 20 November 2012

 AN!Wiki :: How To :: Changing the ethX to Ethernet Device Mapping in EL6 and Fedora 12 to 14

Note: This applies up to Fedora 14. Fedora 15 works quite differently now that it uses biosdevname. Please follow this tutorial for Fedora 15 and newer.

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

This is desirable in cases where specific network cards need to be used on specific networks, and you are interested in maintaining common ethX names across servers. A practical example is found in the 2-Node Red Hat KVM Cluster Tutorial.

For the Impatient

Assuming that NetworkManager is already removed. This example will swap eth0 and eth1.

# Stop the network daemon
/etc/init.d/network stop
cd /etc/sysconfig/network-scripts
# Move your ifcfg files to the device names you desire
mv ifcfg-eth0 ifcfg-temp
mv ifcfg-eth1 ifcfg-eth0
mv ifcfg-temp ifcfg eth1
# Modify DEVICE lines to match new file names
vim /etc/sysconfig/network-scripts/ifcfg-eth*
# Make changes as needed
# Remove udev rules file
rm /etc/udev/rules.d/70-persistent-net.rules
start_udev
/etc/init.d/network start

Thanks for fenris02 and mutk

Example

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

I've got the same hardware in the same configuration in both of my storage nodes. To keep things simple, I want to make sure that both nodes use the same ethX name for the network devices on each of the given networks.

Desired Mapping

Let's assume that you want this:

  • eth0
    • MAC: 90:E6:BA:71:82:EA
  • eth1
    • MAC: 00:21:91:19:96:53
  • eth2
    • MAC: 00:0E:0C:59:46:E4

Initial Mapping

When the Fedora install finished, you may have gotten this:

  • eth0
    • MAC: 00:21:91:19:96:53
  • eth1
    • MAC: 90:E6:BA:71:82:EA
  • eth2
    • MAC: 00:0E:0C:59:46:E4

The Problem

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

The Fix

What we need to do is modify the DEVICE=... line in each ifcfg-ethX file to reflect the order we want.

To avoid confusion later on, we should also rename the files to reflect the new device names.

Stopping the Network

First, stop the network. This is important because if you change the MAC address mapping while the network is still up, the init.d script will fail to bring down the network devices and you will need to reboot for the changes to take effect.

/etc/init.d/network stop

Interface Configuration

Go to the /etc/sysconfig/network-scripts/ directory and then use cat to see the contents of the ifcfg-eth* network configuration files:

Note: The cat output below only shows the lines we're interested in. You will likely see several more lines not shown below.
cd /etc/sysconfig/network-scripts
cat ifcfg-eth0
DEVICE="eth0"
HWADDR="00:21:91:19:96:53"
cat ifcfg-eth1
DEVICE="eth1"
HWADDR="90:E6:BA:71:82:EA"
cat ifcfg-eth2
DEVICE="eth2"
HWADDR="00:0E:0C:59:46:E4"

The important lines are the DEVICE=... and HWADDR=... lines. The rest of the lines will very likely differ from the output above. It is outside the scope of this tutorial to cover the various settings. For an exhaustive list of available options, please see the Red Hat EL6 or the Fedora 12 documentation.

First, change the file names to reflect the device order that you want. In this example we need to swap eth0 and eth1.

cd /etc/sysconfig/network-scripts
mv ifcfg-eth0 ifcfg-temp
mv ifcfg-eth1 ifcfg-eth0
mv ifcfg-temp ifcfg-eth1

Using your editor of choice, open each file and change the DEVICE=... to match the new filename.

Here is the updated files with updated network settings:

cd /etc/sysconfig/network-scripts
cat ifcfg-eth0
DEVICE="eth0"
HWADDR="90:E6:BA:71:82:EA"
cat ifcfg-eth1
DEVICE="eth1"
HWADDR="00:21:91:19:96:53"
cat ifcfg-eth2
DEVICE="eth2"
HWADDR="00:0E:0C:59:46:E4"

'udev' Configuration

The user-space device manager, udev, maintains a list of configuration files that help ensure that hardware to /dev (software) mappings stay consistent, even when hardware is hot swapped or moved between physical connections. For networking hardware, this mapping is recorded in the 70-persistent-net.rules.

Simply delete this file.

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

Making the Changes Take Effect

First, you need to reload udev so that it updates the mapping in memory. This is done using the start_udev program:

start_udev
Starting udev:                                             [  OK  ]

With udev updated, the last step is to restart the network daemon:

/etc/init.d/network start
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]
Bringing up interface eth1:                                [  OK  ]
Bringing up interface eth2:                                [  OK  ]

Done! use ifconfig to verify that the network cards are properly assigned to the specified ethX names.

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.