首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >什么是与网络接口相关的DNS解析器?

问什么是与网络接口相关的DNS解析器?
EN

Ask Ubuntu用户
提问于 2023-04-06 17:24:43
回答 1查看 95关注 0票数 0

我目前工作在ubuntu20.04机器上。

什么是与网络接口相关联的DNS解析器/名称服务器?当我检查/etc/rupv.conf文件时,我可以看到nameserver 127.0.0.53,而当我检查resolvectl status时,我得到的是实例的网络接口(eth0)的DNS Servers: 172.31.0.2。我的实例的网络接口配置了dhcp4: true

  1. 为什么有两个不同的输出?这有什么关系?
  2. 我从resolvectl status命令获得的DNS服务器输出172.31.0.2是否由DHCP动态分配给eth0?如果没有,我是否可以看到DHCP提供的DNS解析器IP?
EN

回答 1

Ask Ubuntu用户

回答已采纳

发布于 2023-04-06 18:01:24

127.0.0.53是DNS存根解析器,它是本地DNS缓存服务器。如果输入以下命令,您将看到/etc/resolv.conf是指向/run/systemd/resolve/stub-resolve.conf的符号链接。

代码语言:javascript
复制
$ ls -la /etc/resolv.conf
lrwxrwxrwx 1 root root 37 Mar 20 10:16 /etc/resolv.conf -> /run/systemd/resolve/stub-resolv.conf

然后,如果您查看该文件的内容,它将显示127.0.0.53作为DNS服务器。

代码语言:javascript
复制
$ cat /etc/resolv.conf
# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# 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 "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically 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 trust-ad
search .

另一个DNS服务器172.31.0.2通过DHCP提供给您的计算机,并自动添加到/run/systemd/resolve/resolv.conf。这是你的上行服务器。

如果您更喜欢使用上行链路服务器,您可以简单地删除指向存根解析器的当前符号链接,并为该文件创建一个新的符号链接。

代码语言:javascript
复制
sudo rm /etc/resolve.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

无论哪种方式,如果您运行一个dig命令,您将看到实际使用的是哪个DNS服务器。在我的系统里:

代码语言:javascript
复制
$ dig google.com

; <<>> DiG 9.18.12-0ubuntu0.22.04.1-Ubuntu <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52917
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             213     IN      A       142.250.72.142

;; Query time: 3 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Thu Apr 06 10:59:05 PDT 2023
;; MSG SIZE  rcvd: 55

注意,它指定的是127.0.0.53。那是因为我的/etc/resolv.conf是/run/systemd/resolve/stub-resolv.conf的一个符号链接。

票数 3
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1462604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档