说明
今天装了一个Ubuntu Server,发现修改IP地址的方法和其他Linux不太一样。有查到旧文章写ip地址信息在/etc/network/interfaces,我查看这个文件,里面是空白,而且修改了也不生效。
实现
最后确定是Ubuntu从17.10开始,启用了新的方式来修改IP地址,即:netplan方式
来看下配置文件,命令行下看下/etc/netplan下:
terry@terrys-ubuntu:~$ ls /etc/netplan/ 00-installer-config.yaml
/etc/netplan下有类似00-installer-config.yaml的文件
如果是DHCP,内容如下:
# This is the network config written by 'subiquity'
network:
ethernets:
ens160:
dhcp4: true
version: 2
如果是静态IP,内容如下:
# This is the network config written by 'subiquity'
network:
ethernets:
ens160:
addresses:
- 192.168.50.11/24
gateway4: 192.168.50.1
nameservers:
addresses:
- 192.168.50.1
- 223.5.5.5
version: 2
yaml中多个地址的写法 - 后面写内容,多个写多行,例如上面的DNS
修改好后测试下是否有问题
sudo netplan try
如果有问题,检查下yaml文件,例如缩进,对齐问题,yaml格式要求比较严格,子项要有缩进。
没有问题的话,应用配置文件
sudo netplan apply
文章评论