[operator]Ubuntu server 18 设置静态IP

时间:2021-03-17 14:03:51
root@ubuntu-MesosMaster-Marathon:~# cat /etc/netplan/-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/-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
ens33:
addresses: [192.168.115.148/]
gateway4: 192.168.115.2
dhcp4: false
nameservers:
addresses: [192.168.115.2]
version:

看文件格式就知道这个文件严格遵守yaml语法格式,需要 使用root权限,设置好之后可以使用如下命令进行即时生效

root@ubuntu-MesosMaster-Marathon:~# netplan apply
root@ubuntu-MesosMaster-Marathon:~# ping baidu.com
PING baidu.com (220.181.57.216) () bytes of data.
bytes from 220.181.57.216 (220.181.57.216): icmp_seq= ttl= time=25.7 ms