Systemd-udev 修改网络接口名

如果使用ifconfig 产生了下面的现象:

$ ifconfig
enp0s25 Link encap:Ethernet HWaddr 77:5a:5e:a6:86:d5
inet addr:192.168.31.239 Bcast:192.168.31.255 Mask:255.255.255.0
inet6 addr: fe80::725a:b6ff:fea6:86d7/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4833 errors:1332 dropped:0 overruns:0 frame:666
TX packets:5589 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3266446 (3.2 MB) TX bytes:1046654 (1.0 MB)
Interrupt:20 Memory:d3500000-d3520000

原来不是ethx么? 怎么变成enp0s25了。看着不习惯,想把他改成原来的eth 命名方案。

这其实就是systemd-udevd采用的预测型网络接口命名方案。
为了禁止这种命名方案, 你需要在rootfs 中找到 一个叫99-default.link 的文件。 该文件常在的可能目录有 /etc/systemd/network/99-default.link, /lib/systemd/network/99-default.link 和 /usr/lib/systemd/network/99-default.link.
找到后, 你可以将该文件删除,或者可以只屏蔽 文件中的NamePolicy 哪一行。

下面show一些关于这个解释的链接的和文字:
关于Namepliocy可以参考:这里

这个文件的内容如下:

[Link]
NamePolicy=kernel database onboard slot path
MACAddressPolicy=persistent

With this policy, if the kernel uses a persistent name, udev does not rename the interface. If the kernel does not use a persistent name, udev renames the interface to the name provided by the hardware database of udev. If this database is not available, Red Hat Enterprise Linux falls back to the mechanisms described above.
Alternatively, set the NamePolicy parameter in this file to mac for media access control (MAC) address-based interface names.

这些字段的具体含义,参考如下:

MACAddress=
The MAC address to use, if no MACAddressPolicy= is specified.
NamePolicy=
An ordered, space-separated list of policies by which the interface name should be set. NamePolicy= may be disabled by specifying net.ifnames=0 on the kernel command line. Each of the policies may fail, and the first successful one is used. The name is not set directly, but is exported to udev as the property ID_NET_NAME, which is, by default, used by a udev rule to set NAME. The available policies are:
kernel
If the kernel claims that the name it has set for a device is predictable, then no renaming is performed.
database
The name is set based on entries in the udev’s Hardware Database with the key ID_NET_NAME_FROM_DATABASE.
onboard
The name is set based on information given by the firmware for on-board devices, as exported by the udev property ID_NET_NAME_ONBOARD.
slot
The name is set based on information given by the firmware for hot-plug devices, as exported by the udev property ID_NET_NAME_SLOT.
path
The name is set based on the device’s physical location, as exported by the udev property ID_NET_NAME_PATH.
mac
The name is set based on the device’s persistent MAC address, as exported by the udev property ID_NET_NAME_MAC.
keep
If the device already had a name given by userspace (as part of creation of the device or a rename), keep it.

你可能感兴趣的:(armlinux,Filesystem)