使用如下的命令查看网络的配置文件列表:

ls /etc/netplan/

例如会得到如下的结果:

50-cloud-init.yaml

我们使用如下的命令进行编辑:

sudo vim /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 reboot.  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:
        ens18:
            addresses:
            - 192.168.11.38/24
            nameservers:
                addresses:
                - 192.168.11.1
                - 114.114.114.114
                search: []
            routes:
            -   to: default
                via: 192.168.11.1
    version: 2

提示说修改后重启可能会恢复默认值,我们可以修改如下的文件

sudo vim /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

往其中加入如下的内容:

network: {config: disabled}