- A+
所属分类:linux技术
前段时间,我偶然进行查看linux DNS配置,通过查看 /etc/resolv.conf 文件,得到如下结果:
➜ devices ll /etc/resolv.conf lrwxrwxrwx 1 root root 39 12月 28 18:55 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf ➜ devices 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 "resolvectl 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 trust-ad
之前,我曾经简单写过一个linux下如何获取dns服务器的博客:Linux 中查看 DNS 与 配置;但是无论怎么查找,显示的都是 127.0.0.53 回环地址。说明 ubuntu 对dns服务器做了一层管理,但是内部的机制我还不是很明白。所以今天进行简要了解一下,填一下年前遗留的一个坑。通过上述注释我们可以了解到,我们可以使用 resolvectl status 命令查看上行链路的dns服务器。我们也可以使用自己创建regular文件进行手动配置;命令运行情况如下:
这显然于我们在netplan中配置的dns相同:
但是,127.0.0.53 代表的是什么呢,其存在的必要性是什么呢?我对此进行了进一步探究,并进行简要记录,方便我个人记忆,如果对你也有启发,欢迎留言讨论:
- Resolved is a local, caching, DNS nameserver resolver and is used by default on Ubuntu.
- https://www.freedesktop.org/software/systemd/man/systemd-resolved.service.html (通过阅读此链接和多问题可得到答案)
- 关于配置文件,可以参考:/etc/systemd/resolved.conf
参考文档:
How and why (not) to use the 127.0.0.53 nameserver, systemd-resolved and resolvctl