linux网卡命名规则

Consistent Network Device Naming

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.

Naming Schemes Hierarchy

By default, systemd will name interfaces using the following policy to apply the supported naming schemes:

Scheme 1:  Names incorporating ( 结合 ) Firmware or BIOS provided index numbers for on-board devices (example:  eno1 ),
are applied if that information from the firmware or BIOS is applicable and available, else falling back to scheme 2.
Scheme 2:  Names incorporating Firmware or BIOS provided PCI Express hotplug slot index numbers (example:  ens1 )
are applied if that information from the firmware or BIOS is applicable and available, else falling back to scheme 3.
Scheme 3:  Names incorporating physical location of the connector of the hardware (example:  enp2s0 ),
are applied if applicable, else falling directly back to scheme 5 in all other cases.
Scheme 4:  Names incorporating interface's MAC address (example:  enx78e7d1ea46da ), is not used by default,
but is available if the user chooses.
Scheme 5:  The traditional unpredictable kernel naming scheme, is used if all other methods fail (example:  eth0 ).

Understanding the Device Renaming Procedure

The device name procedure in detail is as follows:

1. A rule in  /usr/lib/udev/rules.d/60-net.rules 
2. A rule in  /usr/lib/udev/rules.d/71-biosdevname.rules

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 

Understanding the Predictable Network Interface Device Names

The names have two-character prefixes based on the type of interface:

1. en  for Ethernet,
2. wl  for wireless LAN (WLAN),
3. ww  for wireless wide area network (WWAN).

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.

Naming Scheme for VLAN Interfaces

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

 

Consistent Network Device Naming Using biosdevname

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

linux网卡命名规则_第1张图片

 

Controlling the Selection of Network Device Names

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

rules file introduction

60-net.rules

/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

 

71-biosdevname.rules

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.

linux网卡命名规则_第2张图片

75-net-dscription.rules

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.

linux网卡命名规则_第3张图片

 80-net-name-slot.rules

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.

linux网卡命名规则_第4张图片

 80-net-setup-link.rules

If NAME is empty and ID_NET_NAME is not empty use ID_NET_NAME

linux网卡命名规则_第5张图片

udev 网卡rename 

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

你可能感兴趣的:(基础知识,linux,运维,服务器)