我已经解决了这个问题,现在已经可以 ping
www.baidu.com 。我修改了 50-cloud-init.yaml 、 resolv.conf 文件
这是 50-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/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s3:
addresses: []
dhcp4: true
optional: true
enp0s8:
addresses:
- 192.168.56.110/24
nameservers:
addresses: []
search: []
optional: true
version: 2
/run/systemd/resolve/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 192.168.2.1
search lan
deploy@deploy:/etc$
这里需要特别注意 etc下的 resolv.con 文件是链接到/run/systemd/resolve目录下的那个文件。ubuntu 18.04 默认是链接到 /run/systemd/resolve/stub-resolv.conf 文件的