Ubuntu 22.10 netplan `gateway4` has been deprecated, use default routes instead.

本文介绍了如何使用netplan在UbuntuLinux20.04上配置网络,当遇到`gateway4`已废弃的警告时,提供了修改yaml文件以设置正确默认路由的方法,包括使用`routes`替代`gateway4`,并详细阐述了网络配置中的IP地址、子网掩码和DNS设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


前言

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机器人梦想家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值