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

From Alteeve Wiki
Jump to navigation Jump to search
(Created page with "{{howto_header}} {{warning|1=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...")
 
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{howto_header}}
{{howto_header}}


{{warning|1=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.}}
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.


{{warning|1=This is not finished and may well contain errors and omissions. Proceed with caution! Better yet, don't proceed at all. :) }}
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.


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.
= Assumptions =


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 makes a few assumption which may not apply to your system. Please adjust accordingly.


= Steps =
This tutorial assumes you have six network cards;
* <span class="code">eth0</span>
* <span class="code">eth1</span>
* <span class="code">eth2</span>
* <span class="code">eth3</span>
* <span class="code">eth4</span>
* <span class="code">eth5</span>


<source lang="bash">
We will rename these to;
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.
* <span class="code">bcn_link1</span>
* <span class="code">bcn_link2</span>
* <span class="code">sn_link1</span>
* <span class="code">sn_link2</span>
* <span class="code">ifn_link1</span>
* <span class="code">ifn_link2</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.
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.
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>.


<source lang="bash">
= Overview =
grub2-mkconfig
</source>
<source lang="text">
...
</source>


= ifcfg-X Configuration Files =
We will need to take the following steps;


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.
# 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.


Comment out the <span class="code">HWADDR="..."</span> lines in all <span class="code">/etc/sysconfig/network-scripts/ifcfg-*</span> files.
= Identify Interfaces =


== Mapping MAC addresses to Physical Ports ==
To start, you want to see what the names your system has already given to the network interfaces. This can be done with <span class="code">ip addr</span>, which reports all network cards, regardless if they are started or not.


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.
<syntaxhighlight lang="bash">
ip addr
</syntaxhighlight>
<syntaxhighlight lang="text">
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:bd:13:07 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.254/24 brd 192.168.122.255 scope global dynamic eth0
      valid_lft 3445sec preferred_lft 3445sec
    inet6 fe80::5054:ff:febd:1307/64 scope link
      valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:39:18:09 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:01:3f:c8 brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:c9:83:aa brd ff:ff:ff:ff:ff:ff
6: eth4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:b3:63:3e brd ff:ff:ff:ff:ff:ff
7: eth5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:fe:eb:0f brd ff:ff:ff:ff:ff:ff
</syntaxhighlight>


Now, we want to disable <span class="code">NetworkManager</span> and enable the traditional <span class="code">network</span> daemon.
So I see the six network cards named <span class="code">ethX</span>. You might have <span class="code">emX</span>, <span class="code">pXpY</span> or so on. The current names themselves doesn't matter too much, so long as you see all of your interfaces.  


<source lang="bash">
== Mapping Current Names to Desired Names ==
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
So now that we know which cards you have, we need to sort out which name maps to which device. There are several ways you can do this;
</source>
* Sorting out the [http://fedoraproject.org/wiki/Features/ConsistentNetworkDeviceNaming Consistent Network Device Names] to physical interfaces. I find this to be an imperfect art.
* Use <span class="code">ethtool -p <dev></span> and watch to see which port's light blinks. This requires driver support and a clear view of the network cards.
* Unplug a network cable and then run <span class="code">ip addr</span> and see which interface changed from <span class="code"><BROADCAST,MULTICAST,UP,LOWER_UP></span> to <span class="code"><NO-CARRIER,BROADCAST,MULTICAST,UP></span> and note the device name.
* Watch the system log and unplug each cable to see what device is reported as having disconnected. This is the method we'll use.


Once these changes are done, you need to reboot.
Before we proceed, let me give some background on what is happening behind the scenes.


Reboot.
In my case, I have three networks, each bonded across two interfaces, each link going to a separate switch (<span class="code">switch 1</span> and <span class="code">switch 2</span>). I want to name these devices after their purpose;
* [[BCN|Back-Channel Network]]; <span class="code">bcn_link1</span> and <span class="code">bcn_link2</span>
* [[SN|Storage Network]]; <span class="code">sn_link1</span> and <span class="code">sn_link2</span>
* [[IFN|Internet-Facing Network]]; <span class="code">ifn_link1</span> and <span class="code">ifn_link2</span>


= udev Rules =
Before I started, I figured out which physical port I wanted to use for a given network and link. You will obviously have your own plan and it will likely differ from the one shown here. This is no problem at all. So long as you know what name you want to give each physical interface, you are ready to go.


== Initial List ==


Start by creating a list of interfaces names you want. Then, as you pull each cable, mark the current name of the connection that went down beside the desired name.


== Fedora 17+ ==
So here is the list of desired names that I start with;


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>.
{|class="wikitable sortable"
!Current Name!!Desired Name
|-
|
|bcn_link1
|-
|
|bcn_link2
|-
|
|sn_link1
|-
|
|sn_link2
|-
|
|ifn_link1
|-
|
|ifn_link2
|}


(ToDo)
Before we begin, we'll want to watch messages being printed to the system log. We can do this using <span class="code">journalctl</span>'s 'follow' switch, <span class="code">-f</span> switch, like so;


== Fedora 16- ==
<syntaxhighlight lang="bash">
journalctl -f -n 0
</syntaxhighlight>
<syntaxhighlight lang="text">
-- Logs begin at Wed 2015-07-22 02:03:47 GMT. --
</syntaxhighlight>


In earlier versions, you can directly edit the existing <span class="code">/etc/udev/rules.d/70-persistent-net.rules</span> file.
The '<span class="code">-n 0</span>' tells it to show no previous lines in the log.


== The udev Rules File ==
Now, start by pulling the first cable and you should see a message indicating the current name of the interface having gone down. In my case, I am pulling the network cable which I want to be named <span class="code">bcn_link1</span> (the "back-channel network link to switch number 1).


As always, start with a backup.
Unplug the first cable and you should see log entries like this:


<source lang="bash">
<syntaxhighlight lang="text">
Jul 22 03:38:24 an-a03n01.alteeve.ca nm-dispatcher[14204]: Dispatching action 'dhcp4-change' for eth0
Jul 22 03:46:12 an-a03n01.alteeve.ca NetworkManager[816]: <info>  (eth4): link disconnected
</syntaxhighlight>
 
Plug the cable back in and you should see an entry like this;
 
<syntaxhighlight lang="text">
Jul 22 03:46:17 an-a03n01.alteeve.ca NetworkManager[816]: <info>  (eth4): link connected
</syntaxhighlight>
 
So in my case, I see that the current name is <span class="code">eth4</span>. So I will record this next to '<span class="code">bcn_link1</span>' in my table;
 
{|class="wikitable sortable"
!Current Name!!Desired Name
|-
|eth4
|bcn_link1
|-
|
|bcn_link2
|-
|
|sn_link1
|-
|
|sn_link2
|-
|
|ifn_link1
|-
|
|ifn_link2
|}
 
Now I unplug the device I want to be called <span class="code">bcn_link2</span>;
 
<syntaxhighlight lang="text">
Jul 22 04:00:53 an-a03n01.alteeve.ca NetworkManager[816]: <info>  (eth5): link disconnected
</syntaxhighlight>
 
Plug it back in;
 
<syntaxhighlight lang="text">
Jul 22 04:01:01 an-a03n01.alteeve.ca NetworkManager[816]: <info>  (eth5): link connected
</syntaxhighlight>
 
So here I see that the interface currently named <span class="code">eth5</span> is the one I want to rename to '<span class="code">bcn_link2</span>', so I add it to the table.
 
{|class="wikitable sortable"
!Current Name!!Desired Name
|-
|eth4
|bcn_link1
|-
|eth5
|bcn_link2
|-
|
|sn_link1
|-
|
|sn_link2
|-
|
|ifn_link1
|-
|
|ifn_link2
|}
 
Repeat this for the next four interfaces. Once done, you should have something like;
 
 
{|class="wikitable sortable"
!Current Name!!Desired Name
|-
|eth4
|bcn_link1
|-
|eth5
|bcn_link2
|-
|eth2
|sn_link1
|-
|eth3
|sn_link2
|-
|eth0
|ifn_link1
|-
|eth1
|ifn_link2
|}
 
There, now I know the existing device name and the name I wish to give it.
 
== Writing The udev Rules File ==
 
The way we're going to create the actual [[MAC]] address to device name mapping will be via <span class="code">[[udev]]</span> rules. Specifically, we're going to edit or create the <span class="code">/etc/udev/rules.d/70-persistent-net.rules</span>. As of Fedora 17, this file is no longer created, so you will need to create it yourself. I've written a little script to do this;
 
{{note|1=If this script produces no output, run <span class="code">ip addr</span>. If the output looks like: [<span class="code">eth0      Link encap:Ethernet  HWaddr 00:1b:21:72:99:ab</span>], then your system is using the old-style output and this script won't work.}}
 
<syntaxhighlight lang="perl">
#!/usr/bin/perl
 
use strict;
use warnings;
use IO::Handle;
my $conf = {};
 
# Read the 'ip addr'
my $device      = "";
my $mac_address = "";
my $file_handle = IO::Handle->new();
my $shell_call  = "ip addr";
open ($file_handle, "$shell_call 2>&1 |") or die "Failed to call: [$shell_call], error: $!\n";
while (<$file_handle>)
{
chomp;
my $line = $_;
if ($line =~ /^\d+: (\S+):/)
{
$device = $1;
next if $device eq "lo";
$mac_address = "";
next;
}
if ($line =~ /ether (.*?) /)
{
$mac_address = $1;
next if not $device;
$conf->{$device} = $mac_address;
}
}
 
foreach my $device (sort {$a cmp $b} keys %{$conf})
{
my $say_dev = lc($device);
my $say_mac = lc($conf->{$device});
print "\n# Added by 'generate-udev-net' for detected device '$device'.\n";
print "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$say_mac\", NAME=\"$say_dev\"\n";
}
 
exit(0);
 
</syntaxhighlight>
 
You can download and run this and it will print a skeleton udev file. If the output looks good, re-run it again and pipe the output to the <span class="code">70-persistent-net.rules</span> file.
 
Download it;
 
<syntaxhighlight lang="bash">
cd ~
wget -c https://alteeve.ca/files/generate-udev-net
</syntaxhighlight>
<syntaxhighlight lang="text">
--2015-07-22 04:18:01--  https://alteeve.ca/files/generate-udev-net
Resolving alteeve.ca (alteeve.ca)... 65.39.153.64
Connecting to alteeve.ca (alteeve.ca)|65.39.153.64|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 897 [text/plain]
Saving to: ‘generate-udev-net’
 
100%[====================================================================>] 897        --.-K/s  in 0s     
 
2015-07-22 04:18:02 (89.2 MB/s) - ‘generate-udev-net’ saved [897/897]
</syntaxhighlight>
 
Then you can run it;
 
<syntaxhighlight lang="bash">
chmod 755 generate-udev-net
./generate-udev-net
</syntaxhighlight>
<syntaxhighlight lang="bash">
# Added by 'generate-udev-net' for detected device 'eth0'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:bd:13:07", NAME="eth0"
 
# Added by 'generate-udev-net' for detected device 'eth1'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:39:18:09", NAME="eth1"
 
# Added by 'generate-udev-net' for detected device 'eth2'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:01:3f:c8", NAME="eth2"
 
# Added by 'generate-udev-net' for detected device 'eth3'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c9:83:aa", NAME="eth3"
 
# Added by 'generate-udev-net' for detected device 'eth4'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:b3:63:3e", NAME="eth4"
 
# Added by 'generate-udev-net' for detected device 'eth5'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:fe:eb:0f", NAME="eth5"
</syntaxhighlight>
 
What we see above are the rules telling the system that the network device with the specified MAC address is to be given the given name. We are '''not''' changing the names yet. That will come in the next step.
 
If the output looks good to you, re-run the program, but this time we will redirect the output to the <span class="code">70-persistent-net.rules</span> file.
 
<syntaxhighlight lang="bash">
./generate-udev-net > /etc/udev/rules.d/70-persistent-net.rules
cat /etc/udev/rules.d/70-persistent-net.rules
</syntaxhighlight>
<syntaxhighlight lang="bash">
# Added by 'generate-udev-net' for detected device 'eth0'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:bd:13:07", NAME="eth0"
 
# Added by 'generate-udev-net' for detected device 'eth1'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:39:18:09", NAME="eth1"
 
# Added by 'generate-udev-net' for detected device 'eth2'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:01:3f:c8", NAME="eth2"
 
# Added by 'generate-udev-net' for detected device 'eth3'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c9:83:aa", NAME="eth3"
 
# Added by 'generate-udev-net' for detected device 'eth4'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:b3:63:3e", NAME="eth4"
 
# Added by 'generate-udev-net' for detected device 'eth5'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:fe:eb:0f", NAME="eth5"
</syntaxhighlight>
 
If you are more comfortable writing this file yourself, instead of downloading some stranger's program, you can copy the output above, replace the <span class="code">ATTR{address}=="xx:xx:xx:xx:xx:xx"</span> value with the MAC addresses shown in the output from the earlier <span class="code">ip addr</span> and setting the device names you wish.
 
{{note|1=The MAC address values '''must''' be in lower-case.}}
 
== Changing The Device Names ==
 
Now that we have our skeleton <span class="code">/etc/udev/rules.d/70-persistent-net.rules</span> and our rename table, we can change the device names.
 
I like to always make a backup of any file before I edit it;
 
<syntaxhighlight lang="bash">
cp /etc/udev/rules.d/70-persistent-net.rules ~/
cp /etc/udev/rules.d/70-persistent-net.rules ~/
</source>
</syntaxhighlight>
 
Now we will edit our newly created <span class="code">/etc/udev/rules.d/70-persistent-net.rules</span> file and change the <span class="code">NAME="..."</span> values according to our table. In my case, the new file will look like this;
 
<syntaxhighlight lang="bash">
vim /etc/udev/rules.d/70-persistent-net.rules
</syntaxhighlight>
<syntaxhighlight lang="bash">
</syntaxhighlight>
 
The changes are easier to see in a <span class="code">diff</span>;
 
<syntaxhighlight lang="bash">
diff -u /etc/udev/rules.d/70-persistent-net.rules /root/70-persistent-net.rules
</syntaxhighlight>
<syntaxhighlight lang="diff">
--- /root/70-persistent-net.rules 2015-07-22 04:22:14.355000000 +0000
+++ /etc/udev/rules.d/70-persistent-net.rules 2015-07-22 04:22:44.472000000 +0000
@@ -1,18 +1,18 @@
# Added by 'generate-udev-net' for detected device 'eth0'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:bd:13:07", NAME="eth0"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:bd:13:07", NAME="ifn_link1"
# Added by 'generate-udev-net' for detected device 'eth1'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:39:18:09", NAME="eth1"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:39:18:09", NAME="ifn_link2"
# Added by 'generate-udev-net' for detected device 'eth2'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:01:3f:c8", NAME="eth2"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:01:3f:c8", NAME="sn_link1"
# Added by 'generate-udev-net' for detected device 'eth3'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c9:83:aa", NAME="eth3"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c9:83:aa", NAME="sn_link2"
# Added by 'generate-udev-net' for detected device 'eth4'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:b3:63:3e", NAME="eth4"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:b3:63:3e", NAME="bcn_link1"
# Added by 'generate-udev-net' for detected device 'eth5'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:fe:eb:0f", NAME="eth5"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:fe:eb:0f", NAME="bcn_link2"
</syntaxhighlight>
 
Now, next time we reboot, the system will use the given names for the specified MAC addresses!
 
== Reboot and Test ==
 
{{note|1=In the output below, you will see several additional interfaces, three bonds and a bridge, which were created as part of the [[Anvil!_Tutorial_3#Network|Anvil! Tutorial 3]] network setup. You can ignore those for now.}}
 
So now, reboot and we'll verify it is remapped.
 
First, call <span class="code">ip add</span> and make sure the '<span class="code">eth[05]</span>' interfaces are gone and the new '<span class="code">{bcn,sn,ifn}_link{1,2}</span>' interfaces are show.
 
<syntaxhighlight lang="bash">
ip addr
</syntaxhighlight>
<syntaxhighlight lang="text">
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: ifn_link1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ifn_bond1 state UP qlen 1000
    link/ether 52:54:00:bd:13:07 brd ff:ff:ff:ff:ff:ff
3: ifn_link2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ifn_bond1 state UP qlen 1000
    link/ether 52:54:00:bd:13:07 brd ff:ff:ff:ff:ff:ff
4: sn_link1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master sn_bond1 state UP qlen 1000
    link/ether 52:54:00:01:3f:c8 brd ff:ff:ff:ff:ff:ff
5: sn_link2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master sn_bond1 state UP qlen 1000
    link/ether 52:54:00:01:3f:c8 brd ff:ff:ff:ff:ff:ff
6: bcn_link1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bcn_bond1 state UP qlen 1000
    link/ether 52:54:00:b3:63:3e brd ff:ff:ff:ff:ff:ff
7: bcn_link2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bcn_bond1 state UP qlen 1000
    link/ether 52:54:00:b3:63:3e brd ff:ff:ff:ff:ff:ff
8: ifn_bridge1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 52:54:00:bd:13:07 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.31/24 brd 192.168.122.255 scope global ifn_bridge1
      valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:febd:1307/64 scope link
      valid_lft forever preferred_lft forever
9: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN
    link/ether fa:77:7c:ce:b9:f0 brd ff:ff:ff:ff:ff:ff
10: bcn_bond1: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 52:54:00:b3:63:3e brd ff:ff:ff:ff:ff:ff
    inet 10.20.30.1/16 brd 10.20.255.255 scope global bcn_bond1
      valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:feb3:633e/64 scope link
      valid_lft forever preferred_lft forever
11: ifn_bond1: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue master ifn_bridge1 state UP
    link/ether 52:54:00:bd:13:07 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::5054:ff:febd:1307/64 scope link
      valid_lft forever preferred_lft forever
12: sn_bond1: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 52:54:00:01:3f:c8 brd ff:ff:ff:ff:ff:ff
    inet 10.10.30.2/16 brd 10.10.255.255 scope global sn_bond1
      valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe01:3fc8/64 scope link
      valid_lft forever preferred_lft forever
</syntaxhighlight>
 
Interfaces 2 through 7 are the newly named interfaces. So now lets watch the system log again while we pull our cables.
 
<syntaxhighlight lang="bash">
journalctl -f -n 0
</syntaxhighlight>
<syntaxhighlight lang="text">
-- Logs begin at Wed 2015-07-22 04:34:09 GMT. --
</syntaxhighlight>
 
Pull the cable marked as '<span class="code">bcn_link1</span>';
 
<syntaxhighlight lang="text">
Jul 22 04:46:00 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (bcn_link1): link disconnected
</syntaxhighlight>
 
Plug it back in;


The format of this file is as follows;
<syntaxhighlight lang="text">
Jul 22 04:46:08 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (bcn_link1): link connected
</syntaxhighlight>


<source lang="bash">
Repeat for '<span class="code">bcn_link2</span>';
# 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>


The two parts we are interested in are:
<syntaxhighlight lang="text">
* <span class="code">ATTR{address}=="..."</span>; The [[MAC]] address of the interface we want to name. This '''''must''''' be entered using lower-case letters!
Jul 22 04:47:24 an-a03n01.alteeve.ca NetworkManager[703]: <info> (bcn_link2): link disconnected
* <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.
Jul 22 04:47:27 an-a03n01.alteeve.ca NetworkManager[703]: <info> (bcn_link2): link connected
</syntaxhighlight>


{{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.}}
Repeat for the other four interfaces;


<syntaxhighlight lang="text">
Jul 22 04:48:12 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (sn_link1): link disconnected
Jul 22 04:48:16 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (sn_link1): link connected
Jul 22 04:48:33 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (sn_link2): link disconnected
Jul 22 04:48:36 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (sn_link2): link connected
Jul 22 04:48:56 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (ifn_link1): link disconnected
Jul 22 04:49:00 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (ifn_link1): link connected
Jul 22 04:49:25 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (ifn_link2): link disconnected
Jul 22 04:49:29 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (ifn_link2): link connected
</syntaxhighlight>


That matches the order that we pulled the cables, so the remap worked perfectly.


<span class="code"></span>
We're done!
<source lang="bash">
</source>
<source lang="text">
</source>


{{footer}}
{{footer}}

Latest revision as of 04:51, 22 July 2015

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

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;

  • eth0
  • eth1
  • eth2
  • eth3
  • eth4
  • eth5

We will rename these to;

  • bcn_link1
  • bcn_link2
  • sn_link1
  • sn_link2
  • ifn_link1
  • ifn_link2

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

To start, you want to see what the names your system has already given to the network interfaces. This can be done with ip addr, which reports all network cards, regardless if they are started or not.

ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:bd:13:07 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.254/24 brd 192.168.122.255 scope global dynamic eth0
       valid_lft 3445sec preferred_lft 3445sec
    inet6 fe80::5054:ff:febd:1307/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:39:18:09 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:01:3f:c8 brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:c9:83:aa brd ff:ff:ff:ff:ff:ff
6: eth4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:b3:63:3e brd ff:ff:ff:ff:ff:ff
7: eth5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:fe:eb:0f brd ff:ff:ff:ff:ff:ff

So I see the six network cards named ethX. You might have emX, pXpY or so on. The current names themselves doesn't matter too much, so long as you see all of your interfaces.

Mapping Current Names to Desired Names

So now that we know which cards you have, we need to sort out which name maps to which device. There are several ways you can do this;

  • Sorting out the Consistent Network Device Names to physical interfaces. I find this to be an imperfect art.
  • Use ethtool -p <dev> and watch to see which port's light blinks. This requires driver support and a clear view of the network cards.
  • Unplug a network cable and then run ip addr and see which interface changed from <BROADCAST,MULTICAST,UP,LOWER_UP> to <NO-CARRIER,BROADCAST,MULTICAST,UP> and note the device name.
  • Watch the system log and unplug each cable to see what device is reported as having disconnected. This is the method we'll use.

Before we proceed, let me give some background on what is happening behind the scenes.

In my case, I have three networks, each bonded across two interfaces, each link going to a separate switch (switch 1 and switch 2). I want to name these devices after their purpose;

Before I started, I figured out which physical port I wanted to use for a given network and link. You will obviously have your own plan and it will likely differ from the one shown here. This is no problem at all. So long as you know what name you want to give each physical interface, you are ready to go.

Initial List

Start by creating a list of interfaces names you want. Then, as you pull each cable, mark the current name of the connection that went down beside the desired name.

So here is the list of desired names that I start with;

Current Name Desired Name
bcn_link1
bcn_link2
sn_link1
sn_link2
ifn_link1
ifn_link2

Before we begin, we'll want to watch messages being printed to the system log. We can do this using journalctl's 'follow' switch, -f switch, like so;

journalctl -f -n 0
-- Logs begin at Wed 2015-07-22 02:03:47 GMT. --

The '-n 0' tells it to show no previous lines in the log.

Now, start by pulling the first cable and you should see a message indicating the current name of the interface having gone down. In my case, I am pulling the network cable which I want to be named bcn_link1 (the "back-channel network link to switch number 1).

Unplug the first cable and you should see log entries like this:

Jul 22 03:38:24 an-a03n01.alteeve.ca nm-dispatcher[14204]: Dispatching action 'dhcp4-change' for eth0
Jul 22 03:46:12 an-a03n01.alteeve.ca NetworkManager[816]: <info>  (eth4): link disconnected

Plug the cable back in and you should see an entry like this;

Jul 22 03:46:17 an-a03n01.alteeve.ca NetworkManager[816]: <info>  (eth4): link connected

So in my case, I see that the current name is eth4. So I will record this next to 'bcn_link1' in my table;

Current Name Desired Name
eth4 bcn_link1
bcn_link2
sn_link1
sn_link2
ifn_link1
ifn_link2

Now I unplug the device I want to be called bcn_link2;

Jul 22 04:00:53 an-a03n01.alteeve.ca NetworkManager[816]: <info>  (eth5): link disconnected

Plug it back in;

Jul 22 04:01:01 an-a03n01.alteeve.ca NetworkManager[816]: <info>  (eth5): link connected

So here I see that the interface currently named eth5 is the one I want to rename to 'bcn_link2', so I add it to the table.

Current Name Desired Name
eth4 bcn_link1
eth5 bcn_link2
sn_link1
sn_link2
ifn_link1
ifn_link2

Repeat this for the next four interfaces. Once done, you should have something like;


Current Name Desired Name
eth4 bcn_link1
eth5 bcn_link2
eth2 sn_link1
eth3 sn_link2
eth0 ifn_link1
eth1 ifn_link2

There, now I know the existing device name and the name I wish to give it.

Writing The udev Rules File

The way we're going to create the actual MAC address to device name mapping will be via udev rules. Specifically, we're going to edit or create the /etc/udev/rules.d/70-persistent-net.rules. As of Fedora 17, this file is no longer created, so you will need to create it yourself. I've written a little script to do this;

Note: If this script produces no output, run ip addr. If the output looks like: [eth0 Link encap:Ethernet HWaddr 00:1b:21:72:99:ab], then your system is using the old-style output and this script won't work.
#!/usr/bin/perl

use strict;
use warnings;
use IO::Handle;
my $conf = {};

# Read the 'ip addr'
my $device      = "";
my $mac_address = "";
my $file_handle = IO::Handle->new();
my $shell_call  = "ip addr";
open ($file_handle, "$shell_call 2>&1 |") or die "Failed to call: [$shell_call], error: $!\n";
while (<$file_handle>)
{
	chomp;
	my $line = $_;
	if ($line =~ /^\d+: (\S+):/)
	{
		$device = $1;
		next if $device eq "lo";
		$mac_address = "";
		next;
	}
	if ($line =~ /ether (.*?) /)
	{
		$mac_address = $1;
		next if not $device;
		$conf->{$device} = $mac_address;
	}
}

foreach my $device (sort {$a cmp $b} keys %{$conf})
{
	my $say_dev = lc($device);
	my $say_mac = lc($conf->{$device});
	print "\n# Added by 'generate-udev-net' for detected device '$device'.\n";
	print "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$say_mac\", NAME=\"$say_dev\"\n";
}

exit(0);

You can download and run this and it will print a skeleton udev file. If the output looks good, re-run it again and pipe the output to the 70-persistent-net.rules file.

Download it;

cd ~
wget -c https://alteeve.ca/files/generate-udev-net
--2015-07-22 04:18:01--  https://alteeve.ca/files/generate-udev-net
Resolving alteeve.ca (alteeve.ca)... 65.39.153.64
Connecting to alteeve.ca (alteeve.ca)|65.39.153.64|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 897 [text/plain]
Saving to: ‘generate-udev-net’

100%[====================================================================>] 897         --.-K/s   in 0s      

2015-07-22 04:18:02 (89.2 MB/s) - ‘generate-udev-net’ saved [897/897]

Then you can run it;

chmod 755 generate-udev-net
./generate-udev-net
# Added by 'generate-udev-net' for detected device 'eth0'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:bd:13:07", NAME="eth0"

# Added by 'generate-udev-net' for detected device 'eth1'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:39:18:09", NAME="eth1"

# Added by 'generate-udev-net' for detected device 'eth2'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:01:3f:c8", NAME="eth2"

# Added by 'generate-udev-net' for detected device 'eth3'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c9:83:aa", NAME="eth3"

# Added by 'generate-udev-net' for detected device 'eth4'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:b3:63:3e", NAME="eth4"

# Added by 'generate-udev-net' for detected device 'eth5'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:fe:eb:0f", NAME="eth5"

What we see above are the rules telling the system that the network device with the specified MAC address is to be given the given name. We are not changing the names yet. That will come in the next step.

If the output looks good to you, re-run the program, but this time we will redirect the output to the 70-persistent-net.rules file.

./generate-udev-net > /etc/udev/rules.d/70-persistent-net.rules
cat /etc/udev/rules.d/70-persistent-net.rules
# Added by 'generate-udev-net' for detected device 'eth0'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:bd:13:07", NAME="eth0"

# Added by 'generate-udev-net' for detected device 'eth1'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:39:18:09", NAME="eth1"

# Added by 'generate-udev-net' for detected device 'eth2'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:01:3f:c8", NAME="eth2"

# Added by 'generate-udev-net' for detected device 'eth3'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c9:83:aa", NAME="eth3"

# Added by 'generate-udev-net' for detected device 'eth4'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:b3:63:3e", NAME="eth4"

# Added by 'generate-udev-net' for detected device 'eth5'.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:fe:eb:0f", NAME="eth5"

If you are more comfortable writing this file yourself, instead of downloading some stranger's program, you can copy the output above, replace the ATTR{address}=="xx:xx:xx:xx:xx:xx" value with the MAC addresses shown in the output from the earlier ip addr and setting the device names you wish.

Note: The MAC address values must be in lower-case.

Changing The Device Names

Now that we have our skeleton /etc/udev/rules.d/70-persistent-net.rules and our rename table, we can change the device names.

I like to always make a backup of any file before I edit it;

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

Now we will edit our newly created /etc/udev/rules.d/70-persistent-net.rules file and change the NAME="..." values according to our table. In my case, the new file will look like this;

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

The changes are easier to see in a diff;

diff -u /etc/udev/rules.d/70-persistent-net.rules /root/70-persistent-net.rules
--- /root/70-persistent-net.rules	2015-07-22 04:22:14.355000000 +0000
+++ /etc/udev/rules.d/70-persistent-net.rules	2015-07-22 04:22:44.472000000 +0000
@@ -1,18 +1,18 @@
 
 # Added by 'generate-udev-net' for detected device 'eth0'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:bd:13:07", NAME="eth0"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:bd:13:07", NAME="ifn_link1"
 
 # Added by 'generate-udev-net' for detected device 'eth1'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:39:18:09", NAME="eth1"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:39:18:09", NAME="ifn_link2"
 
 # Added by 'generate-udev-net' for detected device 'eth2'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:01:3f:c8", NAME="eth2"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:01:3f:c8", NAME="sn_link1"
 
 # Added by 'generate-udev-net' for detected device 'eth3'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c9:83:aa", NAME="eth3"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:c9:83:aa", NAME="sn_link2"
 
 # Added by 'generate-udev-net' for detected device 'eth4'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:b3:63:3e", NAME="eth4"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:b3:63:3e", NAME="bcn_link1"
 
 # Added by 'generate-udev-net' for detected device 'eth5'.
-SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:fe:eb:0f", NAME="eth5"
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:fe:eb:0f", NAME="bcn_link2"

Now, next time we reboot, the system will use the given names for the specified MAC addresses!

Reboot and Test

Note: In the output below, you will see several additional interfaces, three bonds and a bridge, which were created as part of the Anvil! Tutorial 3 network setup. You can ignore those for now.

So now, reboot and we'll verify it is remapped.

First, call ip add and make sure the 'eth[05]' interfaces are gone and the new '{bcn,sn,ifn}_link{1,2}' interfaces are show.

ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ifn_link1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ifn_bond1 state UP qlen 1000
    link/ether 52:54:00:bd:13:07 brd ff:ff:ff:ff:ff:ff
3: ifn_link2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ifn_bond1 state UP qlen 1000
    link/ether 52:54:00:bd:13:07 brd ff:ff:ff:ff:ff:ff
4: sn_link1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master sn_bond1 state UP qlen 1000
    link/ether 52:54:00:01:3f:c8 brd ff:ff:ff:ff:ff:ff
5: sn_link2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master sn_bond1 state UP qlen 1000
    link/ether 52:54:00:01:3f:c8 brd ff:ff:ff:ff:ff:ff
6: bcn_link1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bcn_bond1 state UP qlen 1000
    link/ether 52:54:00:b3:63:3e brd ff:ff:ff:ff:ff:ff
7: bcn_link2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bcn_bond1 state UP qlen 1000
    link/ether 52:54:00:b3:63:3e brd ff:ff:ff:ff:ff:ff
8: ifn_bridge1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 52:54:00:bd:13:07 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.31/24 brd 192.168.122.255 scope global ifn_bridge1
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:febd:1307/64 scope link 
       valid_lft forever preferred_lft forever
9: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN 
    link/ether fa:77:7c:ce:b9:f0 brd ff:ff:ff:ff:ff:ff
10: bcn_bond1: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 52:54:00:b3:63:3e brd ff:ff:ff:ff:ff:ff
    inet 10.20.30.1/16 brd 10.20.255.255 scope global bcn_bond1
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:feb3:633e/64 scope link 
       valid_lft forever preferred_lft forever
11: ifn_bond1: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue master ifn_bridge1 state UP 
    link/ether 52:54:00:bd:13:07 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::5054:ff:febd:1307/64 scope link 
       valid_lft forever preferred_lft forever
12: sn_bond1: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 52:54:00:01:3f:c8 brd ff:ff:ff:ff:ff:ff
    inet 10.10.30.2/16 brd 10.10.255.255 scope global sn_bond1
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe01:3fc8/64 scope link 
       valid_lft forever preferred_lft forever

Interfaces 2 through 7 are the newly named interfaces. So now lets watch the system log again while we pull our cables.

journalctl -f -n 0
-- Logs begin at Wed 2015-07-22 04:34:09 GMT. --

Pull the cable marked as 'bcn_link1';

Jul 22 04:46:00 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (bcn_link1): link disconnected

Plug it back in;

Jul 22 04:46:08 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (bcn_link1): link connected

Repeat for 'bcn_link2';

Jul 22 04:47:24 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (bcn_link2): link disconnected
Jul 22 04:47:27 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (bcn_link2): link connected

Repeat for the other four interfaces;

Jul 22 04:48:12 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (sn_link1): link disconnected
Jul 22 04:48:16 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (sn_link1): link connected
Jul 22 04:48:33 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (sn_link2): link disconnected
Jul 22 04:48:36 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (sn_link2): link connected
Jul 22 04:48:56 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (ifn_link1): link disconnected
Jul 22 04:49:00 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (ifn_link1): link connected
Jul 22 04:49:25 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (ifn_link2): link disconnected
Jul 22 04:49:29 an-a03n01.alteeve.ca NetworkManager[703]: <info>  (ifn_link2): link connected

That matches the order that we pulled the cables, so the remap worked perfectly.

We're done!

 

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.