virtual box中安装了ubuntu,ip地址会变化,导致项目里的jdbc和mobaxterm经常需要重新设置ip,所以给ubuntu设置一个静态ip
sudo vim /etc/netplan/50-cloud-init.yaml ## ymal文件不一定叫这个名字,总之就是这个目录下类似的ymal
修改之前是这样的:
# 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: true
version: 2
~
修改成下面这样
network:
ethernets:
enp0s3:
dhcp4: no
dhcp6: no
addresses: [192.168.1.102/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8]
version: 2
## 如果报这个错
## Error in network definition /etc/netplan/50-cloud-init.yaml line 12 column 25: expected mapping
## ... ...
## addresses: [192.168.1.102/24]
## gateway: 192.168.1.1
## nameservers: 8.8.8.8
... ...
## 是因为nameservers那里,不是直接跟上ip,对比上面正确的就看出来了
sudo netplan apply ## 生效
特别看不起那一类人 18.04都已经换了网络配置文件了,他们还在自己所谓的教程里写 sudo vi /etc/network/interfaces,那么大的replaced看不着啊?
网友评论