AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1647407
Accepted
a.t.
a.t.
Asked: 2021-05-08 03:56:44 +0800 CST2021-05-08 03:56:44 +0800 CST 2021-05-08 03:56:44 +0800 CST

如何在本地正确测试本地 DNS 服务器?

  • 772

语境

我打算使用 Technitium 设置本地 DNS 服务器,并希望验证本地 DNS 服务器在查询域时返回正确的响应。它在使用时不起作用nslookup mydomain.com。我希望这是因为本地 dns 服务器无法从公共/互联网位置访问。

为了排除这是由于我的本地 DNS 服务器(本地)无法正常工作引起的,我想验证至少本地 DNS 服务器在查询我的域时返回正确的 IP 地址。

尝试

本地 DNS 服务器127.0.0.1在端口的本地 IP 地址上运行,5379因此我尝试了以下命令及其各自的输出:

nslookup 127.0.0.1 somedomain.com
;; connection timed out; no servers could be reached

nslookup 127.0.0.1:5379 somedomain.com
nslookup: couldn't get address for 'somedomain.com': failure

nslookup http://127.0.0.1:5379 somedomain.com
;; connection timed out; no servers could be reached

nslookup https://127.0.0.1:5379 somedomain.com
;; connection timed out; no servers could be reached

所以要么测试命令nslookup 127.0.0.1:5379 somedomain.com是一种可能的方式来测试本地DNS服务器在查询某个域时是否返回正确的IP地址,而我没有正确设置本地DNS服务器,或者我使用了不正确的测试命令。

问题

如何测试本地 DNS 服务器的响应在查询域时是否返回正确的 IP 地址(从托管 DNS 服务器的设备)?

networking dns
  • 4 4 个回答
  • 9566 Views

4 个回答

  • Voted
  1. Best Answer
    user1686
    2021-05-08T05:04:42+08:002021-05-08T05:04:42+08:00

    您的 nslookup 语法是向后的:服务器在域名之后。

    nslookup example.com 127.0.0.1
    

    您不能使用 Windows 的 nslookup 指定自定义端口。(虽然它有一个隐藏-port=选项,但不幸的是它被忽略了。)

    URL 在这里不起作用:DNS 不是基于 HTTP 的。(有一个在 HTTP 中携带 DNS 消息的规范,但它需要特殊的客户端和服务器。)

    如果您有 Linux 或一些可用的 BSD(适用于 Linux 的 Windows 子系统也可以使用),则有更多种类的工具,例如dig、drill或delv. 例如:

    host -p 5379 example.com 127.0.0.1
    
    dig @127.0.0.1 -p 5379 example.com
    
    • 10
  2. mdfst13
    2021-05-08T16:36:33+08:002021-05-08T16:36:33+08:00

    正如一些人所指出的,这个答案的弱点是 ping 解析并不能证明您的 DNS 服务器已回答。它只是证明某些 DNS 服务器做到了。假设您无法从 nslookup 切换到支持指定端口的其他命令(如本答案中所建议的那样),那么我会看到两个可能对您有所帮助的选项:

    1. 关闭您的 DNS 服务器,这样它肯定不会响应。尝试 ping,如果它没有返回任何内容,但在您打开服务器时确实提供了结果,那么它正在工作。弱点:如果互联网可以解析地址,它将无法工作。

    2. 拔下网线。确认您无法访问任何东西(因此您知道您没有 WiFi 连接或类似的东西)。在服务器关闭的情况下尝试 ping(以确保它没有被缓存)。然后打开 DNS 服务器并再次尝试 ping。

    请注意,无论哪种情况,都必须正确配置。因此,您的计算机需要配置为使用本地 DNS 服务器,并且本地 DNS 服务器必须配置为响应请求。如果它不起作用,那么这些东西中的任何一个都可能被破坏。这就是为什么切换到支持端口选择的不同 DNS 客户端可能会更好。然后,您可以针对已知良好的服务器测试客户端,并针对您的服务器测试现在已验证的客户端。

    另一种选择是端口转发。nslookup 命令将使用端口 53。如果您进行配置,以便将 53 的请求转发到正确的端口,这也将允许请求通过。但是,它再次添​​加了无法正常工作的其他内容。DNS服务器是否损坏?还是端口转发配置错误?两者都可以给出相同的结果。

    • 2
  3. tuxErrante
    2021-10-24T02:36:27+08:002021-10-24T02:36:27+08:00

    我将尝试在这里放一个完整的示例,包括从本地 dns 服务器公开区域。

    我们将使用 bind9 作为 Ubuntu 21 机器上的名称服务器。

    首先在文件中定义您的区域,我使用 etc/bind/example.com.zone,修改此示例
    文档:https ://bind9.readthedocs.io/en/latest/reference.html#zone-file

    $ORIGIN example.com.
    $TTL 30
    @       SOA     localhost. admin.example.com.   (
                    2001062501 ; serial
                    21600      ; refresh after 6 hours
                    3600       ; retry after 1 hour
                    604800     ; expire after 1 week
                    86400 )    ; minimum TTL of 1 day
    ;
    ;
            NS      localhost. ;
            NS      dns1.example.com.
            NS      dns2.example.com.
    dns1    A       10.0.1.1
            AAAA    aaaa:bbbb::1
    dns2    A       10.0.1.2
            AAAA    aaaa:bbbb::2
    bar     CNAME   www.example.com
    

    现在你应该从绑定配置文件 /etc/bind/named.conf 加载这个区域,像这样

    zone "example.com." IN {
      type master;
      file "/etc/bind/example.com.zone";
      allow-update {none; };
    };
    

    我还为命名服务 /etc/bind/named.conf.options 添加了一些额外的选项

    options {
      ;---OTHER STUFF
      listen-on port 53 { any; };
      allow-query       { any; };
      recursion       yes;
    };
    

    然后就可以重启服务了 sudo systemctl restart named bind9

    最后测试您的区域,您可以在 dig、host、resolvectl 或 nslookup 之间使用您喜欢的。

    $ host -t A dns1.example.com localhost

    Using domain server:
    Name: localhost
    Address: 127.0.0.1#53
    Aliases: 
    
    dns1.example.com has address 10.0.1.1
    

    $ host -t AAAA dns1.example.com localhost

    Using domain server:
    Name: localhost
    Address: 127.0.0.1#53
    Aliases: 
    
    dns1.example.com has IPv6 address aaaa:bbbb::1
    

    $ host -t CNAME bar.example.com localhost

    Using domain server:
    Name: localhost
    Address: 127.0.0.1#53
    Aliases: 
    
    bar.example.com is an alias for www.example.com.example.com.
    

    从主机到来宾虚拟机的 bind9 测试

    • 1
  4. Tim_Stewart
    2021-05-08T04:33:11+08:002021-05-08T04:33:11+08:00

    视窗

    您可以使用 nslookup,因为 Grawity 提到您的语法错误。

    在此处输入图像描述

    您还可以在 Windows 上使用Bind9中的工具,您不再需要 Linux 的 Windows 子系统来使用它们。它不需要安装。只需将其解压缩到便于命令行使用的地方。(带有 dig、delv、host、nslookup 等)bind9-nslookup 似乎能够使用 Grawity 在他的回答中提到的隐藏端口参数。 nslookup-w-端口


    挖

    Debian 和 Ubuntu 安装:

    sudo apt-get install dnsutils
    

    CentOS 7 安装:

    yum install bind-utils
    

    dig 的典型用法如下所示:
    dig @server name type 
    

    挖

    在哪里:

    服务器

    is the name or IP address of the name server to query. This can be an IPv4 address in dotted-decimal notation or an IPv6 address in colon-delimited notation. When the supplied server argument is a hostname, dig resolves that name before querying that name server.
    
    If no server argument is provided, dig consults /etc/resolv.conf; if an address is found there, it queries the name server at that address. If either of the -4 or -6 options are in use, then only addresses for the corresponding transport will be tried. If no usable addresses are found, dig will send the query to the local host. The reply from the name server that responds is displayed.
    

    姓名

    is the name of the resource record that is to be looked up. 
    

    类型

    indicates what type of query is required — ANY, A, MX, SIG, etc. type can be any valid query type. If no type argument is supplied, dig will perform a lookup for an A record. 
    

    钻研

    delv 的典型用法如下所示:

            delv @server name type 
    

    钻研

    http://manpages.ubuntu.com/manpages/xenial/man1/delv.1.html


    或者您可以为此使用快速而肮脏的 ping。

    完全披露:如果您需要知道您的本地 LAN 私有服务器是否使用此方法响应,您只需在运行服务器应用程序的计算机上将 127.0.0.1 作为网络适配器配置中的第一个也是唯一一个 DNS 服务器.

    Ping mydomain.com并检查它是否显示正确的 IP 号码。

    127.0.0.1 是计算机的环回地址,只有您的本地操作系统才能与此 IP 号通信。

    如果您希望 LAN 上的其他计算机能够使用本地 DNS 服务,请确保该服务连接到本地 IP 地址。

    不要忘记将DNS服务的本地IP添加到局域网中其他计算机的适配器设置中。

    • -1

相关问题

  • 需要验证 firebaseapp.com 子域

  • NAT 后面的 NAT 如何工作(路由器的 NAT 和 ISP 的 NAT)?

  • Win10 1803:如何让移动热点成为专用网络?

  • 迁移 Windows Server 2008

  • nc如何识别服务名称

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve