Changing Ethernet Device Names in EL7 and Fedora 15+: Difference between revisions

From Alteeve Wiki
Jump to navigation Jump to search
No edit summary
Line 5: Line 5:
{{warning|1=This is not finished and may well contain errors and omissions. Proceed with caution! Better yet, don't proceed at all. :) }}
{{warning|1=This is not finished and may well contain errors and omissions. Proceed with caution! Better yet, don't proceed at all. :) }}


With Fedora 15, Fedora moved away from the traditional network device naming of <span class="code">ethX</span> to a variety of names, depending on how the network card is physically connected to the machine. This is possible thanks to <span class="code">[[biosdevname]]</span> which allows better tracking of hardware with the goal of making the names of devices more predictable. Given that it is predictable, there is good reason to leave the names as they are and adapt to the new naming system.
Traditionally in [[Linux]], network devices were given the name <span class="code">ethX</span>, where <span class="code">X</span> was a digit starting at <span class="code">0</span> and incremented up. The drawback to this was that there was no consistent or deterministic way to know which physical network ports would get which <span class="code">ethX</span> name. To address this, Fedora 15 (and other distributions) began using a new tool called <span class="code">[[biosdevname]]</span> which names each network device based on where it is found in the system. The result is that, ''usually'', you can predict the name of a given physical interface.


This tutorial will disable <span class="code">biosdevname</span> entirely. This will not just revert the device names to <span class="code">ethX</span>. It will allow the device names to be anything you like. This tutorial is not meant to advocate against these changes. However, there are cases ranging from simple familiarity to application compatibility that might make you want to use different network device names.  
This tutorial will show you how to change these device names to anything you would like. This tutorial is not meant to advocate against the new network naming. However, there are cases ranging from simple familiarity to application compatibility that might make you want to use different network device names. For those cases, this tutorial hopes to help you.


= Steps =
= Assumptions =


<source lang="bash">
This tutorial makes a few assumption which may not apply to your system. Please adjust accordingly.
cp /etc/default/grub ~/grub.orig
vim /etc/default/grub
</source>
 
Append <span class="code">biosdevname=0</span> to the <span class="code">GRUB_CMDLINE_LINUX="..."</span> value.
 
<source lang="bash">
diff -u ~/grub.orig /etc/default/grub
</source>
<source lang="diff">
--- /root/grub.orig    2012-10-04 20:04:11.145205513 -0400
+++ /etc/default/grub  2012-10-04 20:04:00.880206815 -0400
@@ -1,4 +1,4 @@
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="Fedora"
GRUB_DEFAULT=saved
-GRUB_CMDLINE_LINE="rd.md=0 rd.lvm=0 rd.luks=0 LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16  KEYTABLE=us rd.dm=0"
+GRUB_CMDLINE_LINE="rd.md=0 rd.lvm=0 rd.luks=0 LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16  KEYTABLE=us rd.dm=0 biosdevname=0"
</source>
 
With this changed, re-generate the grub menu.
 
<source lang="bash">
grub2-mkconfig -o /boot/grub2/grub.cfg
</source>
<source lang="text">
...
</source>
 
= ifcfg-X Configuration Files =
 
Unlike in past versions of this tutorial, we will no longer use the <span class="code">/etc/sysconfig/network-scripts/ifcfg-ethX</span> file's <span class="code">HWADDR="..."</span> values to map physical devices to <span class="code">DEVICE="..."</span> names. Instead, we will create the mapping using the <span class="code">/etc/udev/rules.d/</span> folder.


Comment out the <span class="code">HWADDR="..."</span> lines in all <span class="code">/etc/sysconfig/network-scripts/ifcfg-*</span> files.
This tutorial assumes you have six network cards;
* <span class="code">p1p1</span>
* <span class="code">p1p2</span>
* <span class="code">p2p1</span>
* <span class="code">p2p2</span>
* <span class="code">p4p1</span>
* <span class="code">p4p2</span>


This is a good time to rename the configuration files and existing device names to what you want them to be. To do this, rename the file and the <span class="code">DEVICE="..."</span> to the new name.
We will rename these to;


For example;
* <span class="code">bcn1</span>
* <span class="code">bcn2</span>
* <span class="code">sn1</span>
* <span class="code">sn2</span>
* <span class="code">ifn1</span>
* <span class="code">ifn2</span>


<source lang="bash">
The reason for these names is that, in my case, I wish to give names to interfaces that reflect their purpose in my servers. Specifically, I need three bonded networks; [[BCN]], [[SN]] and [[IFN]] in my [[AN!Cluster Tutorial 3|clusters]]. You can just as easily use <span class="code">eth0</span> to <span class="code">eth5</span> or any other name that suits your purposes.
mv /etc/sysconfig/network-scripts/ifcfg-p2p1 /etc/sysconfig/network-scripts/ifcfg-eth3
sed -i 's/p2p1/eth3/g' /etc/sysconfig/network-scripts/ifcfg-eth3
</source>


Do this for all files which you wish to rename. For this tutorial, we reverted all network devices names to <span class="code">eth{0..5}</span>.
This tutorial also assumes that you have a minimal install and that the system is designed to be a server. As such, <span class="code">[[NetworkManager]]</span> is removed and the <span class="code">network</span> [[daemon]] will be used. No attempt was made to test if the method of renaming network devices shown here works with <span class="code">NetworkManager</span>.
 
== Mapping MAC addresses to Physical Ports ==
 
Before we can remap the network devices to device names, we must first learn which ports have what [[MAC]] addresses. An easy way to do this is to edit each <span class="code">ifcfg-X</span> file, set <span class="code">ONBOOT="yes"</span> and change the protocol to <span class="code">BOOTPROTO="none"</span>. This will start each interface but will not assign an [[IP]] address.
 
Now, we want to disable <span class="code">NetworkManager</span> and enable the traditional <span class="code">network</span> daemon.
 
<source lang="bash">
yum remove NetworkManager
chkconfig network on
chkconfig --list network
</source>
<source lang="text">
Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.


network        0:off  1:off  2:on    3:on    4:on    5:on    6:off
= Overview =
</source>


Once these changes are done, you need to reboot.
We will need to take the following steps;


Reboot.
# Identify the network device names assigned to each interface.
# Generate the <span class="code">/etc/udev/rules.d/70-persistent-net.rules</span> file.
# Unplug and plug back in each network interface to create the map of current to desired names.
# Rename and edit the <span class="code">/etc/sysconfig/network-scripts/ifcfg-X</span> files to reflect the desired names.
# Edit the <span class="code">/etc/udev/rules.d/70-persistent-net.rules</span> file to create the [[MAC]] address to device name maps.
# Restart the machine to make the changes take effect.


Once back up, you should be see that all of the network devices have the names <span class="code">eth0</span> to <span class="code">eth5</span>, assuming you have six network cards.
= Identify Interfaces =


To identify which card has what MAC address, <span class="code">tail -f</span> the system log and then, one at a time, unplug each cable. As you do so, note what name is reported as going down and then back up. Note at the same time which name you want that device to be.


For example;


{|class="wikitable sortable"
{|class="wikitable sortable"
!Current Name!!Desired Name
!Current Name!!Desired Name
|-
|-
|eth1||eth0
|p2p2||bcn1
|-
|-
|eth0||eth1
|p2p1||bcn2
|-
|-
|eth3||eth2
|p1p2||sn1
|-
|-
|eth4||eth3
|p4p1||sn2
|-
|-
|eth5||eth4
|p1p1||ifn1
|-
|-
|eth2||eth5
|p4p2||ifn2
|}
|}


With this list, we can now edit the names assigned to the given MAC addresses in the next step.
<span class="code"></span>
 
= udev Rules =
 
As mentioned above, we will use the <span class="code">[[udev]]</span> file to control [[MAC]] address to device name mapping.
 
== Fedora 17+ ==
 
In Fedora 17+, the file <span class="code">/etc/udev/rules.d/70-persistent-net.rules</span> is no longer editable. Trying to modify it will simply end with it being re-written. To bypass this, we will create a blank, immutable file and put the contents we want in <span class="code">/etc/udev/rules.d/69-persistent-net.rules</span>.
 
(ToDo)
 
== Fedora 16- ==
 
In earlier versions, you can directly edit the existing <span class="code">/etc/udev/rules.d/70-persistent-net.rules</span> file.
 
== The udev Rules File ==
 
As always, start with a backup.
 
<source lang="bash">
cp /etc/udev/rules.d/70-persistent-net.rules ~/
</source>
 
The format of this file is as follows;
 
<source lang="bash">
<source lang="bash">
# Comment on where the device was found
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:11:22:33:44:55", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="ethX"
</source>
</source>
The two parts we are interested in are:
* <span class="code">ATTR{address}=="..."</span>; The [[MAC]] address of the interface we want to name. This '''''must''''' be entered using lower-case letters!
* <span class="code">NAME="ethX"</span>; The name we wish to give this device, which must match the <span class="code">DEVICE="..."</span> value in the appropriate <span class="code">ifcfg-ethX</span> file.
{{note|1=In this tutorial, we are simply reverting back to the old-style <span class="code">ethX</span> names. This can be anything you like though. All that matters is that the udev's <span class="code">NAME="..."</span> matches the <span class="code">ifcfg-...</span> file's <span class="code">DEVICE="..."</span> name.}}
== Making The Changes ==
The existing file should include all of your network cards. Armed with the old name to new name notes we wrote earlier, we just need to set the <span class="code">NAME="..."</span> attribute to the new name we desire.
Once updated, reboot.
If everything worked, after the reboot, you should have all of your network devices with the new names. You can check this by again <span class="code">tail -f</span>'ing the syslog and, one by one, unplug the cables and confirm that the log reports the properly named device going down and coming back up.
Done!


{{footer}}
{{footer}}

Revision as of 12:52, 7 October 2012

 AN!Wiki :: How To :: Changing Ethernet Device Names in EL7 and Fedora 15+

Warning: The topic includes RHEL v7, which has not be released. It may well prove that the methods described here will not work with the final release of Red Hat Enterprise Linux version 7. Best guesses on how things will work inform this tutorial and may prove wrong.
Warning: This is not finished and may well contain errors and omissions. Proceed with caution! Better yet, don't proceed at all. :)

Traditionally in Linux, network devices were given the name ethX, where X was a digit starting at 0 and incremented up. The drawback to this was that there was no consistent or deterministic way to know which physical network ports would get which ethX name. To address this, Fedora 15 (and other distributions) began using a new tool called biosdevname which names each network device based on where it is found in the system. The result is that, usually, you can predict the name of a given physical interface.

This tutorial will show you how to change these device names to anything you would like. This tutorial is not meant to advocate against the new network naming. However, there are cases ranging from simple familiarity to application compatibility that might make you want to use different network device names. For those cases, this tutorial hopes to help you.

Assumptions

This tutorial makes a few assumption which may not apply to your system. Please adjust accordingly.

This tutorial assumes you have six network cards;

  • p1p1
  • p1p2
  • p2p1
  • p2p2
  • p4p1
  • p4p2

We will rename these to;

  • bcn1
  • bcn2
  • sn1
  • sn2
  • ifn1
  • ifn2

The reason for these names is that, in my case, I wish to give names to interfaces that reflect their purpose in my servers. Specifically, I need three bonded networks; BCN, SN and IFN in my clusters. You can just as easily use eth0 to eth5 or any other name that suits your purposes.

This tutorial also assumes that you have a minimal install and that the system is designed to be a server. As such, NetworkManager is removed and the network daemon will be used. No attempt was made to test if the method of renaming network devices shown here works with NetworkManager.

Overview

We will need to take the following steps;

  1. Identify the network device names assigned to each interface.
  2. Generate the /etc/udev/rules.d/70-persistent-net.rules file.
  3. Unplug and plug back in each network interface to create the map of current to desired names.
  4. Rename and edit the /etc/sysconfig/network-scripts/ifcfg-X files to reflect the desired names.
  5. Edit the /etc/udev/rules.d/70-persistent-net.rules file to create the MAC address to device name maps.
  6. Restart the machine to make the changes take effect.

Identify Interfaces

Current Name Desired Name
p2p2 bcn1
p2p1 bcn2
p1p2 sn1
p4p1 sn2
p1p1 ifn1
p4p2 ifn2

 

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.