Centos 7: old network interface name

Материал из Webko Wiki
Версия от 08:46, 19 мая 2017; Sol (обсуждение | вклад)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к навигации Перейти к поиску

Presentation

As people were complaining about network interface names changing each time a new one was added, it was decided to call a network interface according to its physical location. The details of the naming convention are available in the RHEL 7 Networking Guide.

However, having a network interface called enp2s0 or enp4s2f0 doesn’t satisfy everybody.

Hopefully, a solution exists to restore the previous behavior.

The old naming convention

To restore the old naming convention, you need to edit the /etc/default/grub file and add net.ifnames=0 biosdevname=0 at the end of the GRUB_CMDLINE_LINUX variable:

GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/swap vconsole.keymap=us crashkernel=auto rd.lvm.lv=centos/root vconsole.font=latarcyrheb-sun16 rhgb quiet net.ifnames=0 biosdevname=0"

Then, test the new configuration to see if no mistake has been made:

# grub2-mkconfig

Note: When preparing this tutorial, I forgot the last quote in the GRUB_CMDLINE_LINUX variable. I got the following error: /etc/default/grub: line 7: unexpected EOF while looking for matching `”‘. This is only to remind you that testing can be useful!

If everything is fine, update the grub2 configuration:

# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-123.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-123.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-123.9.3.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-123.9.3.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-eda26f60d4c948d09cd50d9086a87fcc
Found initrd image: /boot/initramfs-0-rescue-eda26f60d4c948d09cd50d9086a87fcc.img
done

Update the network interface configuration file (here the initial interface name was enp2s0 and the new one is eth0):

# cd /etc/sysconfig/network-scripts
# cp ifcfg-enp2s0 ifcfg-eth0

Edit the ifcfg-eth0 file and replace the network interface name in the NAME variable with “eth0“.

After a reboot, everything should be OK.

Note: It is also possible and perhaps quicker to use the grubby command instead of the grub2-mkconfig command. However, you don’t check the syntax of the /etc/default/grub file with this command and you only apply changes to the current kernels: if you add a new kernel later, it will not receive your change.