云计算百科
云计算领域专业知识百科平台

DNS 详情 && 新增 DNS 自适应服务器 ip

博主wx:yuanlai45_csdn 博主qq:2777137742 想要 深入学习 5GC IMS 等通信知识(加入51学通信),或者想要 cpp 方向修改简历,模拟面试,学习指导都可以添加博主低价指导哈。

DNS 详情

查看 /etc/resolv.conf

cat /etc/resolv.conf

sder@sde-vm:~/IM25$ 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 # 系统当前使用的 DNS 服务器地址
options edns0 trust-ad
search 59.51.78.210

对于查询解析

nameserver 127.0.0.53

  • 含义:
    • 指定系统的 DNS 服务器地址为 127.0.0.53。
    • 127.0.0.53 是一个本地回环地址,表示系统使用 systemd-resolved 的本地 DNS 存根解析器(stub resolver)。
    • 这意味着 DNS 查询不会直接发送到外部 DNS 服务器,而是由 systemd-resolved 服务处理,systemd-resolved 再将查询转发到实际的外部 DNS 服务器。
  • 为什么是 127.0.0.53:
    • systemd-resolved 在本地监听 127.0.0.53:53 提供 DNS 解析服务,实际的外部 DNS 服务器地址存储在 systemd-resolved 的配置中,而不是直接写在 /etc/resolv.conf 中。
    • 这是一种现代 Linux 发行版(如 Ubuntu 18.04+)的常见做法,用于支持动态 DNS 管理和高级功能(如 DNSSEC、DoH)。
  • 端口:
    • 默认使用 53 端口(DNS 标准端口,UDP/TCP)。

options edns0 trust-ad

  • 含义:
    • options 字段指定 DNS 解析的行为选项,影响解析器的配置。
    • edns0:
      • 启用 Extension Mechanisms for DNS (EDNS0),这是 DNS 协议的扩展(RFC 6891)。
      • 允许更大的 DNS 报文(超过 512 字节),支持高级功能,如 DNSSEC、IPv6 和更复杂的查询。
      • 几乎所有现代 DNS 服务器都支持 EDNS0,启用此选项可提高解析效率。
    • trust-ad:
      • 启用 DNSSEC 信任锚点 (Authenticated Data)。
      • 表示系统优先信任通过 DNSSEC 验证的数据(带有 AD 标志的响应),增强 DNS 解析的安全性。
      • DNSSEC 是一种防止 DNS 欺骗和篡改的安全机制。
  • 作用:
    • 这些选项确保 DNS 解析更安全(通过 DNSSEC)和高效(通过 EDNS0)。
    • 如果你的网络环境不支持 DNSSEC 或 EDNS0,可能需要禁用这些选项(但通常无需修改)。 search 59.51.78.210
  • 含义:
    • search 字段指定域名搜索列表,用于自动补全不完整的主机名。
    • 当你输入一个非完全限定域名(FQDN,如 example 而非 example.com),系统会尝试将搜索列表中的域名后缀附加到主机名后进行解析。
    • 在你的配置中,59.51.78.210 看起来像一个 IP 地址,而不是典型的域名(如 example.com)。
  • 异常分析:
    • 问题:search 字段通常应包含域名(如 mydomain.com),而不是 IP 地址。59.51.78.210 作为 search 值可能是配置错误或误解。
    • 可能原因:
      • 网络配置错误(如 DHCP 服务器错误地将 IP 地址分配到 search 字段)。
      • 手动修改 /etc/resolv.conf 或网络配置导致。
      • 59.51.78.210 可能是你期望的 DNS 服务器地址,但被错误写入 search 字段。
    • 实际效果:
      • 当前配置可能导致解析失败。例如,输入 ping myserver 会尝试解析 myserver.59.51.78.210,这是一个无效域名。
      • 建议修正为正确的域名(如果有),或移除 search 字段(如果无需域名补全)。

常见 DNS 地址

  • 常见的公共 DNS 服务器地址包括:
    • Google DNS:8.8.8.8, 8.8.4.4
    • Cloudflare DNS:1.1.1.1, 1.0.0.1
    • 阿里公共 DNS:223.5.5.5, 223.6.6.6(中国大陆常用)
    • 114DNS:114.114.114.114, 114.114.115.115(中国大陆常用)
  • 系统使用的具体地址通过上述方法(如 cat /etc/resolv.conf)查看。
  • 如果使用本地解析器(如 systemd-resolved),可能看到 127.0.0.53,实际 DNS 服务器需通过 resolvectl status 确认。

DNS 端口

  • 默认端口:53(UDP 用于常规查询,TCP 用于大响应或区域传输)。
  • 示例输出(如 dig 的 ;; SERVER: 8.8.8.8#53)中,#53 表示端口。
  • 特殊情况:
    • 如果使用 DNS over HTTPS (DoH) 或 DNS over TLS (DoT),端口可能不同:
      • DoH:通常使用 443 端口(HTTP/2)。
      • DoT:使用 853 端口。

检查是否使用 DoH/DoT:

resolvectl status | grep Protocol

如果显示 DNSSEC 或 TLS,可能涉及非标准端口。

如何查看实际的 DNS 配置

由于你的 /etc/resolv.conf 显示 nameserver 127.0.0.53,说明实际的 DNS 服务器地址由 systemd-resolved 管理。你需要使用以下命令查看真正的外部 DNS 服务器地址和端口。

步骤 1:运行 resolvectl status

resolvectl status ```sder@sde-vm:~/IM25$ resolvectl status Global Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported resolv.conf mode: stub

Link 2 (ens33) Current Scopes: DNS Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported Current DNS Server: 222.246.129.80 DNS Servers: 222.246.129.80 DNS Domain: 59.51.78.210

Link 3 (ens35) Current Scopes: none Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

Link 4 (ens36) Current Scopes: none Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

Link 5 (ens37) Current Scopes: none Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

Link 6 (docker0) Current Scopes: none Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

全局配置

Global Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported resolv.conf mode: stub

Protocols:

  • -LLMNR 和 -mDNS:禁用 Link-Local Multicast Name Resolution 和 Multicast DNS,减少本地网络的广播解析。
  • -DNSOverTLS:未启用 DNS over TLS(DoT),意味着 DNS 查询使用标准 UDP/TCP 协议(端口 53)。
  • DNSSEC=no/unsupported:未启用 DNSSEC(与 /etc/resolv.conf 中的 trust-ad 选项冲突,可能是配置未生效)。 resolv.conf mode: stub:
  • 确认系统使用 systemd-resolved 的存根解析器(stub resolver)。
  • /etc/resolv.conf 指向 127.0.0.53,DNS 查询由 systemd-resolved 处理并转发到外部 DNS 服务器。

网络接口配置(Link 2 – ens33) Link 2 (ens33) Current Scopes: DNS Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported Current DNS Server: 222.246.129.80 DNS Servers: 222.246.129.80 DNS Domain: 59.51.78.210 Current Scopes: DNS:

  • 接口 ens33 是当前活跃的网络接口,负责 DNS 解析。 Current DNS Server: 222.246.129.80:
  • 系统当前使用的 DNS 服务器地址是 222.246.129.80。
  • 这是一个中国大陆的公共 DNS 服务器(可能由本地 ISP 或企业提供)。 DNS Servers: 222.246.129.80:
  • 仅配置了一个 DNS 服务器,建议添加备用 DNS(如 8.8.8.8)以提高可靠性。 DNS Domain: 59.51.78.210:
  • 与 /etc/resolv.conf 中的 search 59.51.78.210 一致。
  • 问题:59.51.78.210 是一个 IP 地址,不是有效的域名,可能导致域名补全失败(例如,解析 myserver 会尝试 myserver.59.51.78.210,无效)。
  • 可能来源:DHCP 服务器错误分配,或手动配置错误。 Port:
  • 未明确指定端口,默认使用 53(标准 DNS 端口,UDP/TCP)。

其他接口(Link 3-6)

  • Link 3 (ens35), Link 4 (ens36), Link 5 (ens37), Link 6 (docker0):
    • 这些接口未配置 DNS(Current Scopes: none),不参与 DNS 解析。
    • docker0 是 Docker 的默认桥接网络接口,通常不用于系统 DNS。

解析

  • DNS Servers:列出实际的外部 DNS 服务器地址(如 8.8.8.8)。
  • Current DNS Server:当前使用的首选 DNS 服务器。
  • Protocols:显示是否使用 DNSSEC、DoH 等高级协议。
  • Port:默认 53(未明确显示,但可通过 dig 确认)。 检查 59.51.78.210:
  • 如果 59.51.78.210 出现在 DNS Servers 列表中,说明它是你实际使用的 DNS 服务器。
  • 如果未出现,可能是配置错误或 DHCP 分配问题。

步骤 2:测试 DNS 服务器和端口

dig example.com | grep SERVER

输出示例:

;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)

含义:

  • dig 查询由本地存根解析器 127.0.0.53 处理,端口为 53,使用 UDP 协议。
  • 这与 /etc/resolv.conf 中的 nameserver 127.0.0.53 一致,表明查询首先到达 systemd-resolved。
  • systemd-resolved 再将查询转发到实际的 DNS 服务器(222.246.129.80)。 为什么显示 127.0.0.53 而非 222.246.129.80:
  • dig 显示的是直接响应的服务器地址,即本地解析器 127.0.0.53。
  • 要查看实际的外部 DNS 服务器,需通过 dig @222.246.129.80 测试或检查 resolvectl status。

当前 DNS 配置总结

  • DNS 服务器:
    • 实际 DNS 服务器:222.246.129.80(由 systemd-resolved 转发)。
    • 本地解析器:127.0.0.53(systemd-resolved 的存根解析器)。
  • 端口:
    • 默认 53(UDP/TCP),未配置 DoH/DoT。
  • 问题:
    • DNS Domain: 59.51.78.210 无效,应为域名(如 mydomain.com)或移除。
    • trust-ad 选项与 DNSSEC=no 冲突,可能未生效。
  • 连接方式:
    • 当前系统通过 systemd-resolved 连接到 222.246.129.80:53 进行 DNS 解析。

配置

sder@sde-vm:~/IM25$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 sde-vm
The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

项目场景

10.18.2.11 dnsnasq 配置

当前配置

sder@sde-vm:~/IM25/go-server$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 sde-vm

#The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

10.18.2.11 sip-server.com
10.18.2.11 rtp-server.com

DNS 命令!!!

  • 查看虚拟机dns收到的请求!!!
  • sudo journalctl -u dnsmasq | tail -30 | cat

  • 查看 总配置;127.0.0.53 是原来的,改成了本地 127.0.0.1
  • cat /etc/resolv.conf

  • 查看 dnsmasq 配置!!! dnsmasq优先使用了 /etc/hosts 中的记录
  • sudo vim /etc/hosts

  • 网络接口信息:
  • ip link show

  • 重启dnsmasq服务!!!
  • sudo systemctl restart dnsmasq

  • 清除dns缓存!!!
  • sudo systemctl restart systemd-resolved

  • 检查服务状态
  • sudo systemctl status dnsmasq

  • 确保 dnsmasq 正在监听 UDP 53 端口
  • sudo netstat -ulnp | grep :53

  • 最新的 dnsmasq 日志 ???
  • sudo tail -n 30 /var/log/dnsmasq.log

  • 如果使用防火墙,也需要确保UDP/TCP 53端口允许来自10.18.11.0/24网段的访问:
  • sudo firewall-cmd –permanent – -add-rich-rule='rule family="ipv4" source address="10.18.11.0/24" port protocol="udp" port="53" accept'
    sudo firewall-cmd –permanent –add-rich-rule='rule family="ipv4" source address="10.18.11.0/24" port protocol="tcp" port="53" accept'
    sudo firewall-cmd –reload

    前提

  • 本地部署 Dns 服务器
  • Dns 配置 信令、媒体服务器
  • App 与 Dns 在同一个局域网
  • 运行本地 DNS 服务器

    目标:在 10.18.2.11 上运行 dnsmasq,提供 DNS 服务,让手机解析 sip-server.com 到 10.18.2.11。 步骤:

  • 安装 dnsmasq 在 10.18.2.11:
  • sudo apt update
    sudo apt install dnsmasq

  • 配置 dnsmasq
  • sudo vim /etc/dnsmasq.conf

    添加:

    address=/sip-server.com/10.18.2.11
    server=8.8.8.8
    server=8.8.4.4

    address=/sip-server.com/10.18.2.11:将 sip-server.com 解析到 10.18.2.11。 server=8.8.8.8 和 server=8.8.4.4:其他域名转发到 Google DNS。 3. 禁用 systemd-resolved(避免 53 端口冲突):

    sudo systemctl disable –now systemd-resolved

  • 更新 /etc/resolv.conf 在 10.18.2.11
  • sudo nano /etc/resolv.conf

    设置:

    nameserver 127.0.0.1

    防止覆盖:

    sudo chattr +i /etc/resolv.conf

  • 重启 dnsmasq
  • sudo systemctl restart dnsmasq

  • 测试 DNS 服务(在 10.18.2.11)
  • dig sip-server.com @127.0.0.1

    预期

    ;; ANSWER SECTION:
    sip-server.com. 0 IN A 10.18.2.11

    创作不易,希望读者三连支持 💖 赠人玫瑰,手有余香 💖

    赞(0)
    未经允许不得转载:网硕互联帮助中心 » DNS 详情 && 新增 DNS 自适应服务器 ip
    分享到: 更多 (0)

    评论 抢沙发

    评论前必须登录!