CN-122001851-A - Method for realizing multi-network port name fixing sequence in Linux system
Abstract
The application belongs to the technical field of networks, and particularly relates to a method for realizing a multi-network port name fixing sequence in a Linux system, which comprises a udev-based user mode fixed naming method and a kernel registration flow-based network port fixed naming method; the user mode fixed naming method based on udev comprises the following steps of S1, identifying hardware topological features, S2, establishing a mapping table, S3, executing renaming through udev rules, S4, executing a unified formatting step, and the network port fixed naming method based on the kernel registration flow comprises the following steps of H1, uniformly intercepting equipment registration at a register_ netdevice () function entry. The whole structure provided by the embodiment of the application enables the network interface name not to be dynamically generated by the system through the mapping of the hardware identifier and the logic name, thereby avoiding the problem of disorder of the network interface name caused by the change of the drive loading sequence and the change of the hardware enumeration sequence.
Inventors
- HOU SHICHENG
- XUE ZONGLIN
- HUANG ZEYANG
- ZHANG WEN
- LIU PEIPEI
- ZHANG CONGCAN
- YAO BAOCHENG
- CHENG YAPENG
Assignees
- 雄安威赛博智能科技有限公司
- 河钢数字技术股份有限公司
- 河北科技大学
Dates
- Publication Date
- 20260508
- Application Date
- 20251224
Claims (10)
- 1. The method for realizing the fixed sequence of the multi-network port names in the Linux system is characterized by comprising the following steps: The method for realizing the multi-portal name fixing sequence in the Linux system comprises a udev-based user mode fixing naming method and a kernel registration flow-based portal fixing naming method; The udev-based user state fixed naming method comprises the following steps: S1, identifying hardware topological features; s2, establishing a mapping table; s3, renaming is executed through udev rules; s4, executing a unified formatting step; s5, registering a final name in a system network stack; the network port fixed naming method based on the kernel registration flow comprises the following steps: h1, uniformly intercepting device registration at a register_ netdevice () function entry; h2, reading a parent node hardware identifier of the equipment; h3, matching the mapping relation according to the hardware path; And H4, registering the final name subsequently.
- 2. The method for realizing the multi-portal name fixing sequence in the Linux system according to claim 1, wherein the identification hardware topological feature names the portals through udev rules, udev is a device manager in the Linux system, names are automatically distributed to devices according to hardware information and system configuration, the portals are set to be ETHx by udev rules, x is a portal number, and the fixed format of the portal names and the fixed sequence among different portals are ensured.
- 3. The method for implementing the fixed order of the multi-port names in the Linux system according to claim 2, wherein the mapping table is established to map the physical port positions into a logical order.
- 4. The method of claim 1, wherein the renaming is performed by udev rules to create rule files in/etc/udev/rules.d/to enable the system to perform naming when the device adds an action trigger.
- 5. The method for realizing the fixed order of the multi-portal names in the Linux system according to claim 4, wherein the step of executing the unified formatting is to execute a script, uniformly convert the capitalized names into standard names, and ensure that the final formats are consistent.
- 6. The method of claim 1, wherein after renaming udev of the final names registered in the system network stack, the network ports finally registered by the kernel are presented in a fixed order.
- 7. The method for implementing the fixed order of multi-port names in the Linux system as claimed in claim 6, wherein the unified interception device registration in the register_ netdevice () function is used for acquiring the parent device node path of the network device in the register_ netdevice () function.
- 8. The method for implementing the multi-port name fixing sequence in the Linux system according to claim 1, wherein the parent node hardware identification of the reading device is specifically used for judging which physical port the device belongs to according to the hardware identification.
- 9. The method for realizing the fixed sequence of the multi-network port names in the Linux system according to claim 1, wherein the matching mapping relation of the hardware paths is specifically that the network port serial numbers are confirmed by comparing with a preset mapping relation table.
- 10. The method for implementing the multi-portal name fixing sequence in the Linux system according to claim 1, wherein the subsequent registration final name is performed by strscpy (dev- > name, "ethX", IFNAMSIZ), naming is completed in the kernel state, and the method has the highest priority.
Description
Method for realizing multi-network port name fixing sequence in Linux system Technical Field The application relates to the technical field of networks, in particular to a method for realizing a multi-network port name fixing sequence in a Linux system. Background In Linux operating systems, the network interface typically automatically recognizes and assigns names (e.g., eth0, eth1, etc.) at system start-up. However, this dynamic allocation may cause a change in the network port name after the system is restarted or the network device is replaced, which brings inconvenience to management and configuration of the system, and especially when a complex server environment or the network device needs to be statically configured, instability of the name may cause communication failure or configuration error. Currently, network interface names in Linux systems are automatically assigned by udev systems, often based on MAC addresses or other hardware characteristics. However, this dynamic naming method has some limitations, especially in scenarios where network interfaces need to be managed in a specific order. After each restart, the order of network interface names may change, resulting in network configuration errors or management confusion. In addition, the user cannot flexibly define and manage these name orders, which brings inconvenience to practical applications. In the prior art, although the dynamic distribution method of the network port names in the Linux system meets the demands of part of users, the dynamic distribution method lacks a function of fixing the sequence, so that the situation of inconsistent network port names occurs in actual use. This dynamic naming scheme is particularly prone to configuration conflicts or portal identification errors in a large-scale server environment. Although the portal name can be modified by manual configuration files, this method is not only cumbersome, but also cannot guarantee that the system remains consistent when restarted. Therefore, the invention provides a method for realizing the fixed sequence of the multi-network port names in the Linux system. Disclosure of Invention The application provides a method for realizing a multi-network port name fixing sequence in a Linux system, which aims to solve the problems. The application provides a method for realizing a multi-network port name fixing sequence in a Linux system, which comprises the following steps: The method for realizing the multi-portal name fixing sequence in the Linux system comprises a udev-based user mode fixing naming method and a kernel registration flow-based portal fixing naming method; The udev-based user state fixed naming method comprises the following steps: S1, identifying hardware topological features; s2, establishing a mapping table; s3, renaming is executed through udev rules; s4, executing a unified formatting step; s5, registering a final name in a system network stack; the network port fixed naming method based on the kernel registration flow comprises the following steps: h1, uniformly intercepting device registration at a register_ netdevice () function entry; h2, reading a parent node hardware identifier of the equipment; h3, matching the mapping relation according to the hardware path; And H4, registering the final name subsequently. Preferably, the identifying hardware topological feature names the network port through udev rule, udev is a device manager in Linux system, according to hardware information and system configuration, names are automatically allocated to devices, and the network port name ETHx is set by udev rule, wherein x is a network port number, and a fixed format of the network port name and a fixed sequence among different network ports are ensured. Preferably, the mapping table is established to map the physical network port positions into a logical order. Preferably, the renaming performed by udev rules is to create rule files in/etc/udev/rules.d/so that the system performs naming when the device adds an action trigger. Preferably, the step of executing the unified formatting is to execute a script, and uniformly convert the capitalized name into a standard name, so as to ensure that the final format is consistent. Preferably, after the renaming is completed udev in the final name of the registration in the system network stack, the network ports of the final registration of the kernel are presented in a fixed order. Preferably, the unified interception device at the register_ netdevice () function entry registers a parent device node path of the network device acquired inside the register_ netdevice () function. Preferably, the parent node hardware identifier of the reading device specifically determines which physical network port the device belongs to according to the hardware identifier. Preferably, the matching mapping relation according to the hardware path is specifically that the network port serial number is compared with a preset mapping re