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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值