Ubuntu 18.04 配置固定IP和DNS
1.修改静态IP地址
root@ubuntu:/etc/netplan# pwd /etc/netplan root@ubuntu:/etc/netplan# ls 50-cloud-init.yaml
编辑50-cloud-init.yaml
root@ubuntu:/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:
addresses: [172.16.5.140/24]
gateway4: 172.16.5.254
dhcp4: true
optional: true
version: 2
以上会把IP配置为,172.16.5.140,DNS为172.16.5.254
2.修改DNS
sudo vi /etc/systemd/resolved.conf
取消"dns"一行的注释,并添加需要的dns地址即可