18.04 由于“名称解析暂时失败”而无法连接到服务器

usb*_*ash 4 dns resolv.conf systemd-resolved 18.04

我有点不知所措。我能够对地址“imap.comcast.net”执行 nslookup 和挖掘,但是如果我尝试 ping 它或从我的应用程序连接到它,我会收到“名称解析暂时失败”。我的 DNS 配置一定有问题,但我不确定它是什么。

> ping imap.comcast.net
ping: imap.comcast.net: Temporary failure in name resolution

> systemd-resolve --status --no-pager
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 (ens3)
      Current Scopes: DNS
       LLMNR setting: yes
MulticastDNS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
         DNS Servers: 10.0.0.2
          DNS Domain: ec2.internal

> 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
search ec2.internal
Run Code Online (Sandbox Code Playgroud)

一些更多的取证信息 /etc/resolv.conf 是一个符号链接,如下所示

> readlink -f /etc/resolv.conf
/run/systemd/resolve/stub-resolv.conf
Run Code Online (Sandbox Code Playgroud)

如果我更改符号链接并重新启动 systemd.resolve 我可以 ping 地址,但它似乎禁用了 dns 缓存

>sudo service systemd-resolved stop
>sudo rm -f /etc/resolv.conf
>sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
>sudo service systemd-resolved start
>ping imap.comcast.net
>sudo systemd-resolve --statistics
DNSSEC supported by current servers: no

Transactions
Current Transactions: 0
  Total Transactions: 0

Cache
  Current Cache Size: 0
          Cache Hits: 0
        Cache Misses: 0

DNSSEC Verdicts
              Secure: 0
            Insecure: 0
               Bogus: 0
       Indeterminate: 0
Run Code Online (Sandbox Code Playgroud)

And*_*rra 8

我想我以前有过这个问题。我使用这个问题中的第一个答案来解决它: resolvconf 和 NetworkManager 设置的名称服务器错误

答案是更改 resolv.conf 符号链接:

sudo rm -f /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
reboot
Run Code Online (Sandbox Code Playgroud)