如何使用NetPlan在ubuntu 20.04上添加永久静态路由?
打开Main NetPlan配置文件:
$ sudoedit /etc/netplan/50-cloud-init.yaml
查找与要添加静态路由的网络接口相关的配置节
# This file is generated from information provided by # the datasource. Changes to it will not persist across an instance. # To disable cloud-init's network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network: ethernets: enp0s3: dhcp4: false addresses: [192.168.1.202/24] gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8,8.8.4.4,192.168.1.1] routes: - to: 172.16.0.0/24 via: 192.168.1.100 version: 2
应用所有新的NetPlan配置:
$ sudo netplan apply
检查Ubuntu系统上可用的所有静态路由:
$ ip route s default via 192.168.1.1 dev enp0s3 proto static 172.16.0.0/24 via 192.168.1.100 dev enp0s3 proto static 192.168.1.0/24 dev enp0s3 proto kernel scope link src 192.168.1.202
日期:2020-07-07 20:56:09 来源:oir作者:oir