系统启动时不支持 Netplan

系统启动时不支持 Netplan

我的系统具有通过自定义内部域名与 LAN 上的其他服务器通信的服务。我的 netplan 设置如下:

network:
    ethernets:
        ens160:
            addresses:
            - 192.168.12.10/24
            gateway4: 192.168.12.1
            nameservers:
                addresses: [192.168.12.1, 8.8.8.8, 8.8.4.4]
            optional: true
    version: 2

当服务器在重启后启动时,似乎 192.168.12.1 被忽略为名称服务器,因为尝试curl -v 或 ajax 到本地服务时的响应不是来自我的本地 dns 服务器。但如果我运行,netplan --debug apply我的输出是正常的,一切都会再次正常工作,直到我重新启动系统。

cron除了设置运行作业之外,还知道如何修复此问题@reboot /usr/sbin/netplan apply吗?

系统:

  Operating System: Ubuntu 18.04.4 LTS
            Kernel: Linux 4.15.0-99-generic

netplannetplan在启动时分配正确的静态 IP,但不使用名称服务器。系统外部没有任何其他自定义网络配置/静态路由ufwufw允许 22 和 nginx 已满。

dig @192.168.12.1 www.ebay.com

; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> @192.168.12.1 www.ebay.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4332
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.ebay.com.          IN  A

;; ANSWER SECTION:
www.ebay.com.       229 IN  CNAME   slot9428.ebay.com.edgekey.net.
slot9428.ebay.com.edgekey.net. 21403 IN CNAME   e9428.b.akamaiedge.net.
e9428.b.akamaiedge.net. 20  IN  A   104.96.86.47

;; Query time: 139 msec
;; SERVER: 192.168.12.1#53(192.168.12.1)
;; WHEN: Tue May 19 14:51:43 EDT 2020
;; MSG SIZE  rcvd: 133



dig @8.8.8.8 www.ebay.com

; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> @8.8.8.8 www.ebay.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18574
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.ebay.com.          IN  A

;; ANSWER SECTION:
www.ebay.com.       117 IN  CNAME   slot9428.ebay.com.edgekey.net.
slot9428.ebay.com.edgekey.net. 19569 IN CNAME   e9428.b.akamaiedge.net.
e9428.b.akamaiedge.net. 19  IN  A   104.96.86.47

;; Query time: 27 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue May 19 14:52:09 EDT 2020
;; MSG SIZE  rcvd: 133



dig @8.8.4.4 www.ebay.com

; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> @8.8.4.4 www.ebay.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5372
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.ebay.com.          IN  A

;; ANSWER SECTION:
www.ebay.com.       286 IN  CNAME   slot9428.ebay.com.edgekey.net.
slot9428.ebay.com.edgekey.net. 15226 IN CNAME   e9428.b.akamaiedge.net.
e9428.b.akamaiedge.net. 19  IN  A   104.96.86.47

;; Query time: 33 msec
;; SERVER: 8.8.4.4#53(8.8.4.4)
;; WHEN: Tue May 19 14:52:36 EDT 2020
;; MSG SIZE  rcvd: 133


systemd-resolve --status

Global
          DNSSEC NTA: 10.in-addr.arpa
                      16.172.in-addr.arpa
                      168.192.in-addr.arpa
                      17.172.in-addr.arpa
                      18.172.in-addr.arpa
                      19.172.in-addr.arpa
                      20.172.in-addr.arpa
                      21.172.in-addr.arpa
                      22.172.in-addr.arpa
                      23.172.in-addr.arpa
                      24.172.in-addr.arpa
                      25.172.in-addr.arpa
                      26.172.in-addr.arpa
                      27.172.in-addr.arpa
                      28.172.in-addr.arpa
                      29.172.in-addr.arpa
                      30.172.in-addr.arpa
                      31.172.in-addr.arpa
                      corp
                      d.f.ip6.arpa
                      home
                      internal
                      intranet
                      lan
                      local
                      private
                      test

Link 2 (ens160)
      Current Scopes: DNS
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
         DNS Servers: 192.168.12.1
                      8.8.8.8
                      8.8.4.4



cat /etc/network/interfaces
# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown


cat /etc/NetworkManager/NetworkManager.conf
cat: /etc/NetworkManager/NetworkManager.conf: No such file or directory



cat /etc/systemd/resolved.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details

[Resolve]
#DNS=
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes


ls -al /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Apr 26  2018 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf



cat /etc/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 127.0.0.53
options edns0

答案1

netplan 对缩进、间距和制表符非常挑剔。

尝试我的.yaml 文件...

network:
  version: 2
  renderer: networkd
  ethernets:
    ens160:
      addresses:
        - 192.168.12.10/24
      gateway4: 192.168.12.1
      nameservers:
        addresses: [192.168.12.1, 8.8.8.8, 8.8.4.4]
        search: [enter custom internal domain name]
      optional: true

sudo netplan --debug generate

sudo netplan apply

reboot

相关内容