大网数据广告活动
服务器运维问答

create alias for network link using systemd-networkd configuration

· 52CE 我爱测

I want to add aliases to my network links to use them as short descriptions. I am configuring my interfaces using systemd-networkd, having systemd version 241 on a debian buster server. I've created the file -rw-r--r-- 1 root roo…

问题原文

原帖链接 · betanummeric · CC BY-SA 4.0

I want to add aliases to my network links to use them as short descriptions. I am configuring my interfaces using systemd-networkd, having systemd version 241 on a debian buster server.

I've created the file -rw-r--r-- 1 root root 68 Feb 9 12:53 /etc/systemd/network/ens19.link with the content:

[MATCH]
MACAddress=7a:08:e8:12:fc:c7

[LINK]
Alias=myalias

I've tried to reboot the system, but the alias does not appear:

3: ens19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 7a:08:e8:12:fc:c7 brd ff:ff:ff:ff:ff:ff

Doing ip l set ens19 alias myalias gives the intended result:

3: ens19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 7a:08:e8:12:fc:c7 brd ff:ff:ff:ff:ff:ff
    alias myalias

How can I achieve that using systemd-networkd?

已采纳解答

原帖链接 · betanummeric · CC BY-SA 4.0

I should have read the manual more carefully.

The first (in lexical order) of the link files that matches a given device is applied. Note that a default file 99-default.link is shipped by the system. Any user-supplied .link should hence have a lexically earlier name to be considered at all.

Renaming /etc/systemd/network/ens19.link to /etc/systemd/network/00-ens19.link helped.

[MATCH] should be [Match] and [LINK] should be [Link].

To apply a changed .link file to the link I can reboot or run

udevadm test-builtin net_setup_link /sys/class/net/ens19

(Because .link files are processed by udev and not systemd-networkd, restarting systemd-networkd is insufficient.)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-02-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。