如何自定义 NIC 名称
使用 systemd 链接文件
你可以创建一个包含 Ignition 配置的 systemd 链接文件。
例如,要将 MAC 地址为 "12:34:56:78:9a:bc "的网卡命名为 "infra",可使用下图所示的 Butane 配置片段在"/etc/systemd/network/25-infra.link "中放置 systemd 链接文件:
variant: fcos
version: 1.7.0
storage:
files:
- path: /etc/systemd/network/25-infra.link
mode: 0644
contents:
inline: |
[Match]
MACAddress=12:34:56:78:9a:bc
[Link]
Name=infra
使用 Udev 规则
同样,要通过 Ignition 配置将 MAC 地址为 "12:34:56:78:9a:bc "的网卡命名为 "infra",请使用下图所示的 Butane 配置片段在 /etc/udev/rules.d/80-ifname.rules 中创建 udev规则:
variant: fcos
version: 1.7.0
storage:
files:
- path: /etc/udev/rules.d/80-ifname.rules
mode: 0644
contents:
inline: |
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="12:34:56:78:9a:bc", ATTR{type}=="1", NAME="infra"
通过内核参数在 Initramfs 中联网
如果需要在 initramfs 中联网,内核参数 ifname= 将动态创建一条 udev 规则来更改网卡名称。
Currently, unlike other parts of the networking config from the initramfs (e.g. static IPs, hostnames, etc.), these udev rules are not persisted into the real root. If the custom name needs to be applied to the real root, either a link file or udev rule must be created, as shown above. See this issue for more details.
例如,要给 MAC 地址为 "12:34:56:78:9a:bc "的网卡命名为 "infra",需要提供一个 "ifname=infra:12:34:56:78:9a:bc "内核参数。就会在 initramfs 中创建一个类似的 udev 规则:
# cat /etc/udev/rules.d/80-ifname.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="12:34:56:78:9a:bc", ATTR{type}=="1", NAME="infra"
Want to help? Learn how to contribute to Fedora Docs ›