Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to change the network interface name on CentOS7

Shulou Source: shulou.com Published: 2022-06-01 16:32:00 10月02日 Update

This article mainly explains "how to change the network interface name on CentOS7". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and study and learn "how to change the network interface name on CentOS7" together!

Question: In CentOS 7, I want to change the assigned network interface name to something else. Is there a suitable way to rename the CentOS or RHEL7 network interface?

Traditionally, Linux network interfaces have been enumerated as eth[0123...], However, these names do not necessarily correspond to actual hardware slots, PCI locations, number of USB interfaces, etc., which introduces an unpredictable naming problem (e.g., due to uncertain device probing behavior), which can lead to different network configuration errors (e.g., forbidden interfaces caused by unintentional interface renaming or firewall bypass). Udev rules based on MAC addresses are not useful in virtualized environments, where MAC addresses are as variable as the number of ports.

CentOS/RHEL6 introduces a consistent and predictable way for network devices to name network interfaces. These features uniquely identify the name of the network interface to make it easier to locate and distinguish devices, and in such a way that the name is persistent regardless of whether the machine is restarted, how much time has passed, or hardware changes. However, this naming convention is not turned on by default on CentOS/RHEL6.

Since CentOS/RHEL7, this predictable naming convention has become the default. According to this rule, interface names are automatically determined based on firmware, topology, and location information. Now, even if network devices are added or removed, interface names remain fixed without re-enumeration, and broken hardware can be seamlessly replaced.

* Two letter prefixes based on interface type:* en --Ethernet * sl --serial line IP (slip)* wl -- wlan* ww -- wwan** Name Type:* b -- BCMA bus and new book * ccw -- CCW Bus Group Name * o --Index number of on-board equipment * s[f][d] --Hot plug slot index number * x -- MAC address * [P]ps[f][d]* -- PCI Location * [P]ps[f][u][..] 1[i]* USB port number chain

A minor drawback to the new naming scheme is that interface names are a bit harder to read than traditional names. For example, you might find names like ENP0S3. Furthermore, you can no longer control the interface name.

If for some reason you prefer the old way and want to be able to choose arbitrary names to assign to CentOS/ RHEL7 devices, you need to override the default predictable naming rules and define udev rules based on MAC addresses.

Here's how to name network interfaces in CentOS or RHEL7.

First, let's disable the predictable naming convention. For this, you can pass the kernel parameter "net.ifnames=0" at startup. This is done by editing/etc/default/grub and adding "net.ifnames=0" to the GRUMDBCMDLINUX variable.

Then run this command to regenerate the GRUB configuration and update kernel parameters.

$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Next, edit (or create) a network naming rules file for udev (/etc/udev/rules.d/70-persistent-net.rules) and add the following line: Replace with your own MAC address (08:00:27:a9:7a:e1) and interface (sushi).

$ sudo vi /etc/udev/rules.d/70-persistent-net.rulesSUBSYSTEM=="net", ACTION=="add", DRIVERS=="?* ", ATTR{address}=="08:00:27:a9:7a:e1", ATTR{type}=="1", KERNEL=="eth*", NAME="sushi"

Finally, restart the computer and verify the new interface name.

Note that configuring renamed interfaces remains your responsibility. If the network configuration (e.g. IPv4 settings, firewall rules) is based on the old name (before the change), an updated network configuration is required to reflect the changed name.

Thank you for reading, the above is "how to change the network interface name on CentOS7" content, after the study of this article, I believe you have a deeper understanding of how to change the network interface name on CentOS7, the specific use of the situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Interface network name rule device address configuration name location hardware learning tradition content kernel parameter bus quantity mode method type Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Tech Info Microsoft Linux Huawei