DNS

54

关于DNS的实现方式

查看DN解析的方法

cat /etc/resolv.conf

DNS直通

nameserver 8.8.8.8
nameserver 8.8.4.4

systemd-resolved服务

nameserver 127.0.0.53

大家都熟知的一种方法是直接改/etc/resolv.conf文件

编辑/etc/resolv.conf 文件:

[Resolve]
DNS=8.8.8.8 8.8.4.4
FallbackDNS=1.1.1.1 1.0.0.1  

DNS= 行指定了主 DNS 服务器(例如,Google 的公共 DNS 服务器 8.8.8.8 和 8.8.4.4)。
FallbackDNS= 行指定了备份 DNS 服务器(例如,Cloudflare 的公共 DNS 服务器 1.1.1.1 和 1.0.0.1)。

还有一种DNS解析方式systemd-resolved服务!!

systemd-resolved 是 systemd 提供的一个系统服务,用于网络名称解析。它实现了一个本地 DNS 缓存,负责处理 DNS 请求并提供缓存的结果,从而提高 DNS 查询的效率。systemd-resolved 还支持 DNS-over-TLS、LLMNR(Link-Local Multicast Name Resolution)、mDNS(Multicast DNS)等功能

主要功能

DNS 解析和缓存、支持多个 DNS 服务器、DNS-over-TLS、LLMNR 和 mDNS、DNSSEC、分离的 DNS 配置

检查服务状态

systemctl status systemd-resolved

启动服务

systemctl start systemd-resolved

重启服务

systemctl restart systemd-resolved

查看当前 DNS 配置

resolvectl status

给不同的网络接口配备不同的DNS服务器

resolvectl dns ens3 8.8.8.8 8.8.4.4#主要的网络接口(如 ens3)你的或许不同

检测是否生效

resolvectl status ens3

配置全局 DNS 服务器

编辑 /etc/systemd/resolved.conf 文件

nano /etc/systemd/resolved.conf

确保添加或修改以下内容

[Resolve]
DNS=8.8.8.8 8.8.4.4

保存文件后,重启 systemd-resolved 服务

systemctl restart systemd-resolved

检查 /etc/resolv.conf

cat /etc/resolv.conf

确保其内容包含指定的 DNS 服务器

nameserver 127.0.0.53

验证 DNS 解析

ping google.com

希望这篇文章能让大家更加了解DNS服务器的解析!!