sudo vi /etc/netplan/50-cloud-init.yaml

 原先的文件内容:

huike@huike:/etc/netplan$ cat 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:
        eth0:
            dhcp4: true
            optional: true
    version: 2

改变后的:

假设IP地址修改为192.168.1.103,

子网掩码24位即255.255.255.0,16位即255.255.0.0;8位即255.0.0.0;

网关设置为192.168.1.1,

# 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:
        eth0:
            addresses: [192.168.1.103/24]
            gateway4: 192.168.1.1
            dhcp4: no
            optional: true
    version: 2

应用:

sudo netplan apply

执行ifocnfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.103  netmask 255.255.255.0  broadcast 192.168.1.255
        ether b8:27:eb:e9:8e:b7  txqueuelen 1000  (Ethernet)
        RX packets 274  bytes 18372 (18.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 356  bytes 63867 (63.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

参考:

假设IP地址修改为192.168.1.100,子网掩码24位即255.255.255.0,网关设置为192.168.1.1,DNS1:223.5.5.5,DNS2:223.6.6.6

1

2

3

4

5

6

7

8

9

10

11

network:

    ethernets:

        ens33:

            dhcp4: no

            addresses: [192.168.1.100/24]

            optional: true

            gateway4: 192.168.1.1

            nameservers:

                    addresses: [223.5.5.5,223.6.6.6]

    version: 2

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐