I am answering to my own question now because I finally found a workaround for this problem.
I found out that it is possible to reorder the devices by unloading the drivers and then loading them in correct order.
First method (bruteforce):
So the first method I came up with was simple to bruteforce the driver reload with init.d script.
Following init script is tailored for Debian 6.0, but the same principle should work on almost any distribution using proper init.d scripts.
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: reorder-nics
# Required-Start:
# Required-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Reloads the nics in correct order
### END INIT INFO
#
# This script should reload the nic drivers in corrected order.
# Basically it just unloads and then loads the drivers in different order.
#
echo "Reloading NICs!"
# unload the drivers
modprobe -r driver_0 # eth0 nic interface
modprobe -r driver_1 # eth1 nic interface
# load the drivers in corrected order
modprobe driver_1
modprobe driver_0
#EOF
Then the script must be added to proper runlevel directory. This can be done easily on Debian with "update-rc.d" command. For example: update-rc.d reorder-nics start S
Second method (Better I think):
I also found a bit more elegant way (at least for Debian & Ubuntu systems).
First Make sure that kernel doesn't automatically load the NIC drivers. This can be done by creating a blacklist file in /etc/modprobe.d/
. I created a file named "disable-nics.conf
". Note that files in /etc/modprobe.d/
must have .conf
suffix. Also naming modules in /etc/modprobe.d/blacklist.conf
do not affect autoloading of modules by the kernel, so you have to make your own file.
# Disable automatic loading of kernel driver modules
# Disable NIC drivers
blacklist driver_0 # eth0 by default
blacklist driver_1 # eth1 by default
Then run 'depmod -ae' as root
Recreate your initrd with 'update-initramfs -u'
And finally add the driver names in corrected order into /etc/modules file.
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
# drivers in wanted order
driver_1 # this one should be loaded as eth0
driver_0 # this one should be loaded as eth1
Changes should come in effect after the next boot.
Reboot is not necessary though; it's easy to switch the devices with following command (as root, of course):
modprobe -r driver_0; modprobe -r driver_1; modprobe driver_1; modprobe driver_0
Some useful links I found while searching the solution:
The articles you found are somewhat outdated. There is now an easy method to assign names to network interfaces, through Udev.
On Debian and derivatives (including Ubuntu), look out for a file called /etc/udev/rules.d/70-persistent-net.rules
. This file is created by /lib/udev/rules.d/75-persistent-net-generator.rules
with the help of the script /lib/udev/write_net_rules
. Each time udev sees a new network device, it will assign it a new number and append that number to /etc/udev/rules.d/70-persistent-net.rules
. That way, interface numbers are persistent across reboots, and will persist after a reinstallation if you restore /etc
.
(If your distribution doesn't ship these files, look for them in the Debian package.)
If you want to give a meaningful name to an interface and you have /etc/udev/rules.d/70-persistent-net.rules
, all you need to do is to edit that file and change "eth0"
to "ethLan"
. Run udevadm trigger --sysname eth0
to rename the existing device after you've edited the file (I think this requires shutting down the interface). If you don't have that file, you can write the one-line matching yourself (the complicated scripts that Debian adds are only to do this automatically):
SUBSYSTEM=="net", DRIVERS=="?*", ATTR{address}=="01:23:45:67:89:ab", NAME="ethLan"
Best Answer
Assuming that you have just installed your debian 9 stretch.
1) For reverting back the old names for the interfaces do:
edit the line
GRUB_CMDLINE_LINUX=""
toGRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
then launch a grub-mkconfig for apply the changes inside the bootloader
You need a reboot after that.
2) For renaming the interfaces use:
For just a temporary modification take a look at the @xhienne answer.
For a permanent modification:
Start by creating / editing the /etc/udev/rules.d/70-persistent-net.rules file.
And insert inside lines like:
If you want to assign for example a name like wan0 to eth0 you can use given my example:
After the next reboot or using service networking restart you should see the changes applied.
EXTRA: Remember that after all this modifications you have to edit your /etc/network/interfaces file replacing the old interfaces names with the new ones!
EXTRA: If you want to know what MAC address your interfaces have, just do a
and look under the link/ section.