Linux provides methods for consistent(一致) and predictable(可预测) network device naming for network interfaces.
These features change the name of network interfaces on a system in order to make locating
and differentiating the interfaces easier.
Traditionally, network interfaces in Linux are enumerated(枚举) as eth[0123…]s0, but these names do
not necessarily correspond to actual labels on the chassis.
Modern server platforms with multiple network adapters can encounter non-deterministic(遇到不确定)
and counter-intuitive(反直觉) naming of these interfaces.
This affects both network adapters embedded on the motherboard (Lan-on-Motherboard, or LOM) and
add-in (single and multiport) adapters.
In Linux, udev supports a number of different naming schemes.
The default is to assign fixed names based on firmware, topology(拓扑), and location information.
This has the advantage that the names are fully automatic, fully predictable, that they stay fixed even if hardware
is added or removed (no re-enumeration takes place), and that broken hardware can be replaced seamlessly(无缝更换).
The disadvantage is that they are sometimes harder to read than the eth or wla names traditionally used.
For example: enp5s0.
By default, systemd will name interfaces using the following policy to apply the supported naming schemes:
The device name procedure in detail is as follows:
3.A rule in /lib/udev/rules.d/75-net-description.rules
4.A rule in /usr/lib/udev/rules.d/80-net-name-slot.rules
The names have two-character prefixes based on the type of interface:
The names have the following types:
o<index>
on-board device index number
s<slot>[f<function>][d<dev_id>]
hotplug slot index number. All multi-function PCI devices will carry the [f<function>] number in the device name, including the function 0 device.
x<MAC>
MAC address
[P<domain>]p<bus>s<slot>[f<function>][d<dev_id>]
PCI geographical location. In PCI geographical location, the [P<domain>] number is only mentioned if the value is not 0. For example:
ID_NET_NAME_PATH=P1enp5s0
[P<domain>]p<bus>s<slot>[f<function>][u<port>][..][c<config>][i<interface>]
USB port number chain. For USB devices, the full chain of port numbers of hubs is composed. If the name gets longer than the maximum number of 15 characters, the name is not exported. If there are multiple USB devices in the chain, the default values for USB configuration descriptors (c1) and USB interface descriptors (i0) are suppressed.
Traditionally, VLAN interface names in the format: interface-name.VLAN-ID are used. The VLAN-ID ranges from 0 to 4096,
which is a maximum of four characters and the total interface name has a limit of 15 characters.
The maximum interface name length is defined by the kernel headers and is a global limit, affecting all applications.
In Linux , four naming conventions(习惯) for VLAN interface names are supported:
VLAN plus VLAN ID
The word vlan plus the VLAN ID. For example: vlan0005
VLAN plus VLAN ID without padding
The word vlan plus the VLAN ID without padding by means of additional leading zeros. For example: vlan5
Device name plus VLAN ID
The name of the parent interface plus the VLAN ID. For example: enp1s0.0005
Device name plus VLAN ID without padding
The name of the parent interface plus the VLAN ID without padding by means of additional leading zeros. For example: enp1s0.5
The biosdevname program uses information from the system's BIOS, specifically the type 9 (System Slot) and type 41 (Onboard Devices Extended Information) fields contained within the SMBIOS. If the system's BIOS does not have SMBIOS version 2.6 or higher and this data, the new naming convention will not be used. Most older hardware does not support this feature because of a lack of BIOSes with the correct SMBIOS version and field information. For BIOS or SMBIOS version information, contact your hardware vendor;
Install:yum install bisodevname
Boot command:
Disbale:biosdevname=0
Enable:biosdevname=1
Device naming can be controlled in the following manner(方式):
By identifying the network interface device
Setting the MAC address in an ifcfg file using the HWADDR directive enables it to be identified by udev.
The name will be taken from the string given by the DEVICE directive, which by convention is
the same as the ifcfg suffix. For example, ifcfg-enp1s0.
By turning on or off biosdevname
The name provided by biosdevname will be used (if biosdevname can determine one).
By turning on or off the systemd-udev naming scheme
The name provided by systemd-udev will be used (if systemd-udev can determine one).
/lib/udev/rename_device, to look into all /etc/sysconfig/network-scripts/ifcfg-suffix files. If it finds an ifcfg file with a HWADDR entry
matching the MAC address of an interface it renames the interface to the name given in the ifcfg file by the DEVICE directive
biosdevname to rename the interface according
to its naming policy, provided that it was not renamed in a previous step, biosdevname is installed,
and biosdevname=0 was not given as a kernel command on the boot command line.
udev to fill in the internal udev device property
values ID_NET_NAME_ONBOARD, ID_NET_NAME_SLOT, ID_NET_NAME_PATH, ID_NET_NAME_MAC by examining
the network interface device. Note, that some device properties might be undefined.
udev to rename the interface, provided that
it was not renamed in step 1 or 2, and the kernel parameter net.ifnames=0 was not given, according to the
following priority: ID_NET_NAME_ONBOARD, ID_NET_NAME_SLOT, ID_NET_NAME_PATH. It falls through to the
next in the list, if one is unset. If none of these are set, then the interface will not be renamed.
If NAME is empty and ID_NET_NAME is not empty use ID_NET_NAME
1.新建文件,数字越大越后面执行
sudo nano /etc/udev/rules.d/99-persistent-net.rules
2.根据MAC地址重命名
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:11:22:33:44:55", NAME="eth0“
3.根据BDF重命名
ACTION=="add", SUBSYSTEM=="net", KERNELS=="0000:15:00.0", NAME="eth0"
4重新生效
sudo udevadm control --reload-rules
reboot