前言
netplan 是一个命令行工具,用于在某些 Linux 发行版(例如 Ubuntu Linux 20.04)上配置网络。
以前我们配置网络都是在 /etc/network/interfaces 文件里配置。但是现在我们不用这么麻烦了,因为有了netplan。
netplan 使用 yaml 描述文件来配置网络接口,然后,通过这些描述为任何给定的呈现工具生成必要的配置选项。
解决问题流程
报错内容
配置时遇到如下报错
# /etc/netplan/01-network-manager-all.yaml
network:
version: 2
renderer: NetworkManager
# 此处为补充项
ethernets:
eno1:
dhcp4: no
addresses:
- 192.168.1.88/24
- 192.168.1.89/24
- 192.168.1.90/24
gateway4: 192.168.1.1
nameservers:
addresses: [192.168.1.1]
** (process:619341): WARNING **: 19:46:34.642: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.
修改如下
# /etc/netplan/01-network-manager-all.yaml
network:
version: 2
renderer: NetworkManager
# 此处为补充项
ethernets:
eno1:
dhcp4: no
addresses:
- 192.168.1.88/24
- 192.168.1.89/24
- 192.168.1.90/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [192.168.1.1]
routes
:填写网关地址
addresses
:填写想要配置的ip地址
nameservers
:填写dns地址,优先使用第一个
测试&确认
usage: /usr/sbin/netplan [-h] [--debug] ...
Network configuration in YAML
options:
-h, --help show this help message and exit
--debug Enable debug messages
Available commands:
help Show this help message
apply Apply current netplan config to running system
generate Generate backend specific configuration files from /etc/netplan/*.yaml
get Get a setting by specifying a nested key like "ethernets.eth0.addresses", or "all"
info Show available features
ip Retrieve IP information from the system
set Add new setting by specifying a dotted key=value pair like ethernets.eth0.dhcp4=true
rebind Rebind SR-IOV virtual functions of given physical functions to their driver
try Try to apply a new netplan config to running system, with automatic rollback
# 使用 netplan try 测试是否有左右,测试后在120秒内按Enter也可使其生效
# 使用 netplan apply 使其生效
总结
此处主要是解决系统报错,无法上网的原因,由于routs不正确。
这一篇文章写内部网络参数设置比较详细,大家可以参考。
netplan说明–Msmartavs