在 /etc/netplan/0...yaml 中设置静态 ip 后,暂时无法解决“mirrors.aliyun.com”错误

在 /etc/netplan/0...yaml 中设置静态 ip 后,暂时无法解决“mirrors.aliyun.com”错误

我在vmware player里有个vm,dhcp4:ture改成

 dhcp4: no
        addresses:
            - 192.168.134.127/24
        gateway4: 192.168.134.1
        nameservers:
            addresses: [127.0.0.53,192.168.134.1, 8.8.8.8, 1.1.1.1]

/etc/netplan/00-installer-config.yaml

IP设置成功,但是服务器好像无法再访问网络了。

我明白了Temporary failure resolving 'mirrors.aliyun.com'。看来我的 DNS 有问题。如何解决?


更新输出sudo netplan --debug apply

    root@server1:/home/hzg# netplan --debug apply
** (generate:1305968): DEBUG: 13:18:39.135: Processing input file /etc/netplan/00-installer-config.yaml..
** (generate:1305968): DEBUG: 13:18:39.136: starting new processing pass
** (generate:1305968): DEBUG: 13:18:39.137: We have some netdefs, pass them through a final round of validation
** (generate:1305968): DEBUG: 13:18:39.137: ens33: setting default backend to 1
** (generate:1305968): DEBUG: 13:18:39.137: Configuration is valid
** (generate:1305968): DEBUG: 13:18:39.138: Generating output files..
** (generate:1305968): DEBUG: 13:18:39.139: openvswitch: definition ens33 is not for us (backend 1)
** (generate:1305968): DEBUG: 13:18:39.139: NetworkManager: definition ens33 is not for us (backend 1)
(generate:1305968): GLib-DEBUG: 13:18:39.140: posix_spawn avoided (fd close requested) 
(generate:1305968): GLib-DEBUG: 13:18:39.142: posix_spawn avoided (fd close requested) 
DEBUG:netplan generated networkd configuration changed, restarting networkd
DEBUG:ens33 not found in {}
DEBUG:Merged config:
network:
  ethernets:
    ens33:
      addresses:
      - 192.168.134.127/24
      dhcp4: false
      gateway4: 192.168.134.1
      nameservers:
        addresses:
        - 192.168.134.1
        - 8.8.8.8
        - 1.1.1.1
  version: 2

DEBUG:no netplan generated NM configuration exists
DEBUG:ens33 not found in {}
DEBUG:Merged config:
network:
  ethernets:
    ens33:
      addresses:
      - 192.168.134.127/24
      dhcp4: false
      gateway4: 192.168.134.1
      nameservers:
        addresses:
        - 192.168.134.1
        - 8.8.8.8
        - 1.1.1.1
  version: 2

DEBUG:Link changes: {}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for ens33
DEBUG:netplan triggering .link rules for docker0
DEBUG:ens33 not found in {}
DEBUG:Merged config:
network:
  ethernets:
    ens33:
      addresses:
      - 192.168.134.127/24
      dhcp4: false
      gateway4: 192.168.134.1
      nameservers:
        addresses:
        - 192.168.134.1
        - 8.8.8.8
        - 1.1.1.1
  version: 2

答案1

Netplan 对间距和缩进的要求非常严格。此外,您的 yaml 文件省略了渲染器。我建议您将文件编辑为:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      addresses:
        - 192.168.134.127/24
      gateway4: 192.168.134.1
      nameservers:
        addresses: [192.168.134.1, 8.8.8.8, 1.1.1.1]

来源:/usr/share/doc/netplan/examples/static.yaml

接下来是:

sudo netplan generate
sudo netplan apply

你连接了吗?测试:

ping -c3 8.8.8.8
ping -c3 www.ubuntu.com

相关内容