You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Linux中批量查询多个网站的NS记录

批量获取多个域名的DNS服务器(NS记录)方法

在Linux下不用手动逐个输入域名,有几种简单的批量处理方式:

方法一:用nslookup结合shell循环

  1. 先创建一个包含所有要查询域名的文本文件,比如domains.txt,每行一个域名:
    echo -e "facebook.com\ngoogle.com\ntwitter.com" > domains.txt
    
  2. 用while循环读取文件里的域名,逐个查询NS记录:
    while read domain; do
      echo "=== $domain 的NS服务器 ==="
      nslookup -type=ns "$domain" | grep -E "nameserver|Non-Authoritative answer"
    done < domains.txt
    
    这样会清晰展示每个域名对应的NS服务器,grep用来过滤出关键结果,避免冗余输出。

方法二:用dig命令批量查询(推荐,输出更简洁)

dig是更强大的DNS查询工具,多数Linux发行版默认自带,适合批量处理:

  1. 同样准备好domains.txt文件
  2. 用xargs配合dig批量查询,只输出NS服务器地址:
    xargs -I {} dig +short NS {} < domains.txt
    
    • +short参数会让输出只保留NS服务器的域名,非常简洁
    • 如果需要获取权威回答而非非权威结果,可以加上+authoritative参数:
      xargs -I {} dig +short +authoritative NS {} < domains.txt
      
  3. 若要把结果保存到文件,直接重定向输出即可:
    xargs -I {} dig +short NS {} < domains.txt > ns_records.txt
    

示例输出(dig +short)

运行命令后会得到类似这样的结果:

ns1.facebook.com.
ns2.facebook.com.
ns3.facebook.com.
ns4.facebook.com.
ns1.google.com.
ns2.google.com.
ns3.google.com.
ns4.google.com.
ns1.p34.dynect.net.
ns2.p34.dynect.net.
ns3.p34.dynect.net.
ns4.p34.dynect.net.
d01-01.ns.twtrdns.net.
d01-02.ns.twtrdns.net.

内容的提问来源于stack exchange,提问作者Jet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 06:36:21