AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1482942
Accepted
hbogert
hbogert
Asked: 2023-08-20 04:37:59 +0800 CST2023-08-20 04:37:59 +0800 CST 2023-08-20 04:37:59 +0800 CST

有没有办法在 netplan 中将自定义配置添加到渲染的网络配置中

  • 772

我想在networkd 中使用Netplan 中不可用的选项。在适当的时候,这可能是可以实现的。在那之前,有没有办法实现自定义网络代码,使我渲染的网络配置具有以下行?

[Network]
KeepConfiguration=dhcp-on-stop

我希望 Netplan YAML 文件中有一些隐藏的配置可用于实现此目的。

非常欢迎其他解决方案。

netplan
  • 1 1 个回答
  • 33 Views

1 个回答

  • Voted
  1. Best Answer
    mpboden
    2023-08-25T11:45:20+08:002023-08-25T11:45:20+08:00

    您还没有指出您的 Ubuntu 版本。以下是在 Ubuntu 22.04 Server 上测试的。


    这可以通过为您的接口创建一个“嵌入式”配置文件来完成,该文件将添加或覆盖您的网络配置。

    每个systemd.network(5):

       Along with the network file foo.network, a "drop-in" directory
       foo.network.d/ may exist. All files with the suffix ".conf" from
       this directory will be merged in the alphanumeric order and
       parsed after the main file itself has been parsed. This is useful
       to alter or add configuration settings, without having to modify
       the main configuration file. Each drop-in file must have
       appropriate section headers.
    

    一个例子...

    您尚未包含 Netplan YAML 配置文件,因此我将使用以下内容:

    $ cat /etc/netplan/00-install-config.yaml
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: true
    

    在本例中,网络接口是eth0。您需要用您的界面替换eth0以下命令中的 。

    1. 创建放置目录

    解析 Netplan YAML 文件时,将创建以下文件:/run/systemd/network/10-netplan-eth0.network.

    插入目录名称需要与此文件名匹配并添加“.d”后缀:

    sudo mkdir /etc/systemd/network/10-netplan-eth0.network.d
    

    2.创建配置文件:

    在此目录中,创建一个以“.conf”结尾的配置文件。名称并不重要,重要的是后缀。

    sudo touch /etc/systemd/network/10-netplan-eth0.network.d/10-netplan-eth0.network.conf
    

    3.编辑如下:

    # Drop-in configuration for 10-netplan-eth0.network
    [Network]
    KeepConfiguration=dhcp-on-stop
    

    4. 重新启动systemd-networkd:

    sudo systemctl restart systemd-networkd
    

    为了其他人的完整性,我添加了有关密钥的部分KeepConfiguration=。

    每个systemd.network(5):

       KeepConfiguration=
           Takes a boolean or one of "static", "dhcp-on-stop", "dhcp".
           When "static", systemd-networkd will not drop static
           addresses and routes on starting up process. When set to
           "dhcp-on-stop", systemd-networkd will not drop addresses and
           routes on stopping the daemon. When "dhcp", the addresses and
           routes provided by a DHCP server will never be dropped even
           if the DHCP lease expires. This is contrary to the DHCP
           specification, but may be the best choice if, e.g., the root
           filesystem relies on this connection. The setting "dhcp"
           implies "dhcp-on-stop", and "yes" implies "dhcp" and
           "static". Defaults to "dhcp-on-stop" when systemd-networkd is
           running in initrd, "yes" when the root filesystem is a
           network filesystem, and "no" otherwise.
    
    • 1

相关问题

  • Netplan:如何将整个子网分配给 NIC,除了网关和广播 IP

  • Ubuntu为什么要更改网络配置

  • Ubuntu Desktop 17.10 将不接受带有 wifi 加密狗的静态 IP

  • 使用networkd,如何查看DNS Server

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve