将 IP 分配给每个状态下的接口(DOWN、NO CARRIER)

将 IP 分配给每个状态下的接口(DOWN、NO CARRIER)

我有一个依赖于主机的主 IP 地址的服务,如果主机上未配置该地址,该服务将无法启动。有没有一种方法可以使systemd-networkd静态配置的接口启动,即使该接口的链路在启动时已关闭,并且在链路在任何给定时间丢失时仍保持该状态?

我发现 fornetplan存在ignore-carrier: true。我需要同样的systemd-networkd

答案1

阅读 systemd.network 手册我发现这两个参数:

ConfigureWithoutCarrier=
           Takes a boolean. Allows networkd to configure a specific link even if it has no carrier. Defaults to false. If IgnoreCarrierLoss= is not explicitly set, it will default to this value.
 ActivationPolicy=
           Specifies the policy for systemd-networkd managing the link administrative state. Specifically, this controls how systemd-networkd changes the network device's "IFF_UP" flag, which is sometimes controlled by system administrators by running e.g., ip
           link set dev eth0 up or ip link set dev eth0 down, and can also be changed with networkctl up eth0 or networkctl down eth0.

           Takes one of "up", "always-up", "manual", "always-down", "down", or "bound". When "manual", systemd-networkd will not change the link's admin state automatically; the system administrator must bring the interface up or down manually, as desired. When
           "up" (the default) or "always-up", or "down" or "always-down", systemd-networkd will set the link up or down, respectively, when the interface is (re)configured. When "always-up" or "always-down", systemd-networkd will set the link up or down,
           respectively, any time systemd-networkd detects a change in the administrative state. When BindCarrier= is also set, this is automatically set to "bound" and any other value is ignored.

           When the policy is set to "down" or "manual", the default value of RequiredForOnline= is "no". When the policy is set to "always-down", the value of RequiredForOnline= forced to "no".

           The administrative state is not the same as the carrier state, so using "always-up" does not mean the link will never lose carrier. The link carrier depends on both the administrative state as well as the network device's physical connection. However,
           to avoid reconfiguration failures, when using "always-up", IgnoreCarrierLoss= is forced to true.

设置ConfigureWithoutCarrier=trueActivationPolicy=always-up成功

相关内容