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
的内容为👇
# 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.
来自 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
能成功, 但会报
所以改为👇
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文章来源:https://www.toymoban.com/news/detail-792768.html
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模板网!