Ubuntu20和22的 /etc/netplan/*.yaml 一些配置静态IP的文件收集

这篇具有很好参考价值的文章主要介绍了Ubuntu20和22的 /etc/netplan/*.yaml 一些配置静态IP的文件收集。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Ubuntu20和22的 /etc/netplan/*.yaml 一些配置静态IP的文件收集

Ubuntu22.04Desktop原始 /etc/netplan/01-network-manager-all.yaml

cat /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

Ubuntu22.04Server原始 /etc/netplan/00-installer-config.yaml
注释中的 subiquity 是服务安装程序的名称
开头的数字00或01等, 有优先级的作用

cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
      dhcp4: true
  version: 2

Ubuntu22, server版和desktop版使用netplan管理下层 不同 的网络工具

  • Server版用 netplan 配置 systemd-networkd
    systemctl status systemd-networkd
    
  • Desktop版用 netplan 配置 NetworkManager
    systemctl status NetworkManager
    

Ubuntu20.04 Server版 /etc/netplan/00-installer-config.yaml

cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    enp0s3:
      dhcp4: true
  version: 2

221015 , 安装Ubuntu22.04Server版, 安装过程中设置网络

/etc/netplan/00-installer-config.yaml,# Linux CentOS Ubuntu 等,网络 物联 通讯协议,安装软件 开发环境搭建,tcp/ip,linux,网络,ubuntu
👆安装操作系统过程中,通过安装程序设置网络,
系统安装好后,/etc/netplan/00-installer-config.yaml的内容为👇

# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
      addresses:
      - 192.168.168.220/24
      gateway4: 192.168.168.2
      nameservers:
        addresses:
        - 192.168.168.2
        search:
        - 192.168.168.2
        - 8.8.8.8
        - 8.8.4.4
        - 1.1.1.1
  version: 2

👆 Ubuntu22.04Server版, 来自安装程序的设置 ,
奇怪的是, 自带手册man netplan 上说, gateway4, gateway6 Deprecated(不赞成使用,已过时)

gateway4, gateway6 (scalar)
       Deprecated, see Default routes.  Set default gateway for IPv4/6, for manual address configuration.  This requires  setting  addresses  too.
       Gateway  IPs  must be in a form recognized by inet_pton(3).  There should only be a single gateway per IP address family set in your global
       config, to make it unambiguous.  If you need multiple default routes, please define them via routing-policy.

       Example for IPv4: gateway4: 172.16.0.1 Example for IPv6: gateway6: "2001:4::1"

经测试, 安装程序 ‘subiquity’ 生成的配置, 原封不动 执行 sudo netplan apply` ,
虽然能生效, 但是会报👇

** (generate:51833): WARNING **: 08:43:30.441: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

** (process:51831): WARNING **: 08:43:32.216: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

/etc/netplan/00-installer-config.yaml,# Linux CentOS Ubuntu 等,网络 物联 通讯协议,安装软件 开发环境搭建,tcp/ip,linux,网络,ubuntu






来自 Ubuntu22.04 , man netplan 的摘抄

这是具有多个IPv4地址和多个网关的静态配置接口的示例,
具有相同的路由度量级别和静态DNS名称服务器(本例中为Google DNS):

#This is an example of a static-configured interface with multiple IPv4 addresses and multiple gateways with networkd, with equal route	metric levels, and static DNS nameservers (Google DNS for this example):

	  network:
		version: 2
		renderer: networkd
		ethernets:
		  eno1:
		    addresses:
		    - 10.0.0.10/24
		    - 11.0.0.11/24
		    nameservers:
		      addresses:
			- 8.8.8.8
			- 8.8.4.4
		    routes:
		    - to: 0.0.0.0/0
		      via: 10.0.0.1
		      metric: 100
		    - to: 0.0.0.0/0
		      via: 11.0.0.1
		      metric: 100

对于设置静态Ip
👆上方例子可以看出, 以前的DNS是 nameservers 下的 addresses ,
👇下方的例子可看出nameservers 下的 search 值是字母名称, 可以不出现


This is a complex example which shows most available features:
#This is a complex example which shows most available features:

	      network:
		version: 2
		# if specified, can only realistically have that value, as networkd cannot
		# render wifi/3G.
		renderer: NetworkManager
		ethernets:
		  # opaque ID for physical interfaces, only referred to by other stanzas
		  id0:
		    match:
		      macaddress: 00:11:22:33:44:55
		    wakeonlan: true
		    dhcp4: true
		    addresses:
		      - 192.168.14.2/24
		      - 192.168.14.3/24
		      - "2001:1::1/64"
		    nameservers:
		      search: [foo.local, bar.local]
		      addresses: [8.8.8.8]
		    routes:
		      - to: default
			via: 192.168.14.1
		      - to: default
			via: "2001:1::2"
		      - to: 0.0.0.0/0
			via: 11.0.0.1
			table: 70
			on-link: true
			metric: 3
		    routing-policy:
		      - to: 10.0.0.0/8
			from: 192.168.14.2/24
			table: 70
			priority: 100
		      - to: 20.0.0.0/8
			from: 192.168.14.3/24
			table: 70
			priority: 50
		    # only networkd can render on-link routes and routing policies
		    renderer: networkd
		  lom:
		    match:
		      driver: ixgbe
		    # you are responsible for setting tight enough match rules
		    # that only match one device if you use set-name
		    set-name: lom1
		    dhcp6: true
		  switchports:
		    # all cards on second PCI bus unconfigured by
		    # themselves, will be added to br0 below
		    match:
		      name: enp2*
		    mtu: 1280
		wifis:
		  all-wlans:
		    # useful on a system where you know there is
		    # only ever going to be one device
		    match: {}
		    access-points:
		      "Joe's home":
			# mode defaults to "infrastructure" (client)
			password: "s3kr1t"
		  # this creates an AP on wlp1s0 using hostapd
		  # no match rules, thus the ID is the interface name
		  wlp1s0:
		    access-points:
		      "guest":
			 mode: ap
			 # no WPA config implies default of open
		bridges:
		  # the key name is the name for virtual (created) interfaces
		  # no match: and set-name: allowed
		  br0:
		    # IDs of the components; switchports expands into multiple interfaces
		    interfaces: [wlp1s0, switchports]
		    dhcp4: true

官方例子可以看出, 以前的DNS是 nameservers 下的 addresses ,
nameservers 下的 search 值是字母名称, 可以不出现

自设一些配置到 VMware 下的 Ubuntu22.04Server 测试成功
sudo vi /etc/netplan/00-installer-config.yaml
network:
  ethernets:
    ens33:
      addresses:
      - 192.168.168.204/24
      gateway4: 192.168.168.2
      nameservers:
        addresses:
        - 192.168.168.2 # 本地
        - 8.8.8.8 # 谷歌
        - 8.8.4.4
        - 1.1.1.1
        - 223.6.6.6 # 阿里
        - 114.114.114.114
        - 180.76.76.76 # 百度
        - 119.29.29.29 # 腾讯
        - 101.226.4.6
        - 123.125.81.6
        search:
        - 192.168.168.2 # 本地
        - 8.8.8.8 # 谷歌
        - 8.8.4.4
        - 1.1.1.1
        - 223.6.6.6 # 阿里
        - 114.114.114.114
        - 180.76.76.76 # 百度
        - 119.29.29.29 # 腾讯
        - 101.226.4.6
        - 123.125.81.6
  version: 2

👆执行sudo netplan apply能成功, 但会报
/etc/netplan/00-installer-config.yaml,# Linux CentOS Ubuntu 等,网络 物联 通讯协议,安装软件 开发环境搭建,tcp/ip,linux,网络,ubuntu
所以改为👇

network:
  ethernets:
    ens33:
      addresses:
      - 192.168.168.204/24
      # gateway4: 192.168.168.2  # 2204以前的网关
      routes:
        - to: default # default 等效 0.0.0.0/0 等效 0/0   # could be 0/0 or 0.0.0.0/0 optionally
          via: 192.168.168.2  # 2204的新网关
      nameservers:
        addresses:
        - 192.168.168.2 # 本地
        - 8.8.8.8 # 谷歌
        - 8.8.4.4
        - 1.1.1.1
        - 223.6.6.6 # 阿里
        - 114.114.114.114
        - 180.76.76.76 # 百度
        - 119.29.29.29 # 腾讯
        - 101.226.4.6
        - 123.125.81.6
        search:
        - 192.168.168.2 # 本地
        - 8.8.8.8 # 谷歌
        - 8.8.4.4
        - 1.1.1.1
        - 223.6.6.6 # 阿里
        - 114.114.114.114
        - 180.76.76.76 # 百度
        - 119.29.29.29 # 腾讯
        - 101.226.4.6
        - 123.125.81.6
  version: 2





下面的来自网络摘抄
network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no
      addresses:
        - 192.168.121.221/24
      gateway4: 192.168.121.1
      nameservers:
          addresses: [8.8.8.8, 1.1.1.1]

20.04 server

network:
  ethernets:
    eth0: #配置的网卡的名称
      addresses: [10.248.201.18/23] #配置的静态ip地址和掩码
      dhcp4: false #关闭DHCP
      optional: true
      gateway4: 10.248.201.1 #网关地址
      nameservers:
        addresses: [8.8.8.8,8.8.4.4,1.1.1.1] #DNS服务器地址,多个用","分隔
  version: 2

20.04server

network:
  ethernets:
    eth0:
      addresses:
      - 10.248.201.18/23
      gateway4: 10.248.201.1 # ubuntu20.04server , 2204版把 gateway4 换成了 routes
      nameservers:
        addresses:
        - 8.8.8.8
        - 8.8.4.4
      search: []  # 2204版 search 也不再使用
  version: 2

22.04server

network:
  ethernets:
    eth0:
      addresses:
      - 10.248.201.18/23
      routes:  # 在ubuntu22.04中,gateway4已弃用了,替代的参数为:routes,另外search也不再使用
      - to: default
        via: 10.248.201.1
      nameservers:
        addresses:
        - 8.8.8.8
        - 8.8.4.4
  version: 2

22.04 server

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp0s3:
      dhcp4: false
      dhcp6: false
      addresses:
        - 192.168.1.227/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [192.168.1.1]
  version: 2


22.04 server

network:
  ethernets:
    eth0:
      dhcp4: false
      dhcp6: false
      addresses: 
        - 192.168.10.120/24
      optional: true
      routes:
        - to: default
          via: 192.168.10.1
      set-name: eth0
      nameservers:
        addresses: 
          - 223.5.5.5
          - 223.6.6.6
        search:
          - localhost
          - local
  version: 2


21.04

network:
  version: 2
  renderer: networkd
  ethernets:
    ens32:
      addresses:
        - 192.168.187.101/24
      gateway4: 192.168.187.2
      nameservers:
          search: [mydomain, otherdomain]
          addresses: [114.114.114.114, 8.8.8.8]


network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      addresses:
        - 10.0.0.10/8
      gateway4: 10.0.0.1
      nameservers:
          search: [mydomain, otherdomain]
          addresses: [10.0.0.5, 1.1.1.1]

22.04 desktop

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      ## 可以ip a查看以太网连接名称
      dhcp4: true
    enp0s8:
      # addresses: []
      ## addresses添加网络掩码,如192.168.56.3/24
      addresses: [192.168.5.3/24]
      # gateway4: 10.10.10.1
      ## gateway4已经废弃,推荐使用routes
      routes:
      - to: "default"
        via: "192.168.5.1"
      nameservers:
        search: [mydomain , otherdomain ]
        addresses: [192.168.5.1 , 114.114.114.114]
      optional: true
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s25:
      addresses: [192.168.5.243/24]
      routes:
        - to: default
          via: 192.168.5.1
      nameservers: 
        addresses: [192.168.5.1, 114.114.114.114]
netplan

netplan generate :生成与后端管理工具对应的配置;
netplan apply :应用配置,必要时重启管理工具;
netplan try :在配置得到确认之后才应用,如果配置存在错误,则回滚;
netplan get:获取当前 netplan 配置;
netplan set:修改当前 netplan 的配置。文章来源地址https://www.toymoban.com/news/detail-792768.html

sudo netplan generate # 生成与后端管理工具对应的配置;
sudo netplan apply # 应用配置,必要时重启管理工具;
sudo netplan --debug apply # 调试,返回错误信息;
sudo netplan try # 在配置得到确认之后才应用,如果配置存在错误,则回滚,类似test;
sudo netplan get # 获取当前 netplan 配置;
sudo netplan set # 修改当前 netplan 的配置。

到了这里,关于Ubuntu20和22的 /etc/netplan/*.yaml 一些配置静态IP的文件收集的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Netplan使用(高版本Ubuntu静态/动态IP设置方法)

    NetworkManager and netplan Ubuntu 18.04开始,Ubuntu和Debian移除了以前的 ifup/ifdown 命令和/etc/network/interfaces配置文件,转而使用 ip link set 或者 /etc/netplan/01-netcfg.yaml 模板和 sudo netplan apply 命令实现网络管理。 Netplan 是抽象网络配置描述器,用于配置 Linux 网络。 通过 netplan 命令,你只需用

    2024年01月16日
    浏览(32)
  • ubuntu22.04 配置静态ip

    存储在/etc/netplan目录中。 您可能会在此目录中找到一个或多个YAML文件。 文件的名称可能因安装程序而异。 通常,该文件名为01-netcfg.yaml,50-cloud-init.yaml或NN_interfaceName.yaml, 通过运行以下命令保存文件并应用更改: 校验修改是否生效 选择ipv4 选择 Manual 配置静态ip 结束

    2024年02月14日
    浏览(38)
  • Ubuntu22.04配置静态ip

    老规矩 - 上官网链接 为修改的文件内容如下 cat vim /etc/netplan/00-network-manager-all.yaml 修改对应文件 sudo vim /etc/netplan/00-network-manager-all.yaml

    2024年02月22日
    浏览(47)
  • Ubuntu 22LTS 配置静态IP

    可行方法,需界面配置 转载自:哔哩哔哩链接地址 命令行配置:待补充

    2024年02月11日
    浏览(22)
  • Ubuntu22.04网络配置,静态IP配置

    Ubuntu22.04网络配置,静态IP配置 或

    2024年02月15日
    浏览(43)
  • Ubuntu22.04 netplan 网络配置

     Ubuntu18.04修改IP地址的方法(error in network definition ......is missing /prefixlength)_error in network definition: expected sequence-CSDN博客 Ubuntu20.04 单网卡配置多ip_ubuntu单网卡多ip-CSDN博客  ubuntu配置多网段IP-CSDN博客  Netplan使用(高版本Ubuntu静态/动态IP设置方法)-CSDN博客  Canonical Netplan

    2024年01月16日
    浏览(32)
  • Ubuntu 22.04配置静态IP地址

    1、查看ip地址网卡名称:ifconfig 2、编辑网卡配置文件:sudo vim /etc/netplan/01-network-manager-all.yaml 默认样式: network:         version: 2         renderer: NetworkManager  3、修改为: network:         ethernets:                 enp7s0:                         dhcp4: no                

    2024年02月03日
    浏览(49)
  • Ubuntu 20.04配置静态ip

    根据需求增加

    2024年02月12日
    浏览(32)
  • 在Ubuntu 22.04上配置静态IP地址

    在Ubuntu 22.04上配置静态IP地址需要进行以下步骤: 打开终端:在桌面上,按下 Ctrl + Alt + T 组合键,或者在应用程序搜索栏中键入“终端”。 编辑网络配置文件:使用文本编辑器(例如 nano 或 vim )打开网络配置文件。在终端中,输入以下命令以使用 nano 编辑器打开配置文件:

    2024年02月11日
    浏览(40)
  • Ubuntu22.04配置静态IP-网关-DNS

    要在Ubuntu系统中配置网络,可以通过以下步骤进行操作: 1.打开终端:可以使用“Ctrl+Alt+T”快捷键打开终端,或者从应用程序菜单中找到“终端”。 2.检查网络接口:输入以下命令检查当前系统中的网络接口列表: 接口列表将显示在终端中。常见的接口名称可能包括\\\"eth0\\\"、

    2024年02月13日
    浏览(50)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包