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

Is there a way to automatically add network interfaces to systemd-networkd and/or netplan?

· 52CE 我爱测

I'm currently building pre-configured disk images for Ubuntu 18.04 servers. While the hardware is mostly the same, there are a few different network interfaces between the devices (and some are virtual machines rather than bare m…

问题原文

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

I'm currently building pre-configured disk images for Ubuntu 18.04 servers. While the hardware is mostly the same, there are a few different network interfaces between the devices (and some are virtual machines rather than bare metal). Because of this I don't know exactly what network devices will be present beforehand or what they will be called (some have a single one called ens33, others have multiples called eno1, eno2, etc.)

systemd-networkd doesn't automatically bring up interfaces on, they have to be explicitly specified in config files.

I'm currently bypassing this by using NetworkManager instead of networkd since it will automatically bring up any interfaces it finds, but considering the Ubuntu installer seems to automatically add any interfaces it finds to netplan's config, I figure there must be a way to setup a service or something that does the same thing at startup. Anyone know a way to do this?

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

systemd-networkd can apply a configuration to multiple interfaces at once, using a wildcard [Match].

For example:

# cat /etc/systemd/network/99-wildcard.network
[Match]
Name=en*

[Network]
DHCP=yes

This will bring up DHCP on any interface whose name starts with en (which is every wired interface).

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

资料来源与适用范围

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

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

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