When managing a website, migrating to a new web host, or troubleshooting network connectivity issues, one of the most fundamental tasks you will face is auditing and querying Domain Name System (DNS) records. Knowing how to get dns server for domain configurations allows you to map out exactly where your domain's traffic is being routed and check if updates have successfully registered globally.
However, the phrase "get DNS server for a domain" can mean a few different things depending on your current technical objective. Are you trying to identify the authoritative Name Servers (NS) where your domain's zone file is hosted? Are you attempting to query a specific DNS resolver directly to verify a newly updated record? Or are you looking to find out which local DNS server your own device is querying to resolve hostnames?
In this comprehensive guide, we will cover all of these angles. You will learn how to use command-line utilities (like dig, nslookup, and PowerShell's Resolve-DnsName), write programmatic scripts in Python and Node.js, and leverage specialized web-based tools to analyze, query, and troubleshoot your domain's DNS configuration.
1. Understanding DNS Hierarchy: Resolvers vs. Authoritative Name Servers
To successfully get dns domain configurations and interpret the results, you must first understand the structural hierarchy of the Domain Name System. When a user requests a website, the lookup process relies on two distinct types of DNS servers: recursive resolvers and authoritative name servers.
Recursive DNS Resolvers
A recursive resolver (also known as a DNS recursor) is the first stop for a DNS query outside your local network. These servers are typically operated by your Internet Service Provider (ISP) or public DNS providers like Cloudflare (1.1.1.1), Google Public DNS (8.8.8.8), or Quad9 (9.9.9.9).
The resolver's job is to hunt down the requested DNS records on behalf of your client machine. It does this by recursively querying the DNS hierarchy—starting at the Root servers, moving to Top-Level Domain (TLD) servers (like .com or .org), and finally reaching the authoritative name server.
Authoritative Name Servers
An authoritative name server is the ultimate source of truth for a domain name. It holds the actual DNS zone file containing the definitive records (such as A, AAAA, MX, CNAME, and TXT records) configured by the domain owner.
When you register a domain at a registrar (like GoDaddy, Namecheap, or Google Domains) or set up hosting (like AWS Route 53, Cloudflare, or DigitalOcean), you specify which authoritative name servers will manage your domain's records. These are represented as NS (Name Server) records in the domain's registry.
Why the Distinction Matters
If you want to get domain dns records, you need to understand which server is answering your query. If you query a recursive resolver, you might receive a cached, older version of the record. If you query the authoritative server directly, you will get the absolute newest, live configuration. This guide will show you how to do both.
2. How to Get the Authoritative DNS Servers for a Domain
The easiest way to get dns from domain records is by using standard command-line utilities built directly into your operating system. These tools let you query the global DNS directory and find out which authoritative servers are responsible for hosting a given domain's zone files.
Method A: Using dig (Domain Information Groper)
Available by default on macOS, Linux, and Unix-like operating systems, dig is widely considered the gold standard for DNS diagnostics due to its detailed output and flexibility.
To find a domain's authoritative name servers using dig, use the following syntax, specifying the NS record type:
dig example.com NS
Understanding the Output
When you run this command, dig returns a verbose response structured into several key sections:
; <<>> DiG 9.10.6 <<>> example.com NS
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48921
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;example.com. IN NS
;; ANSWER SECTION:
example.com. 86400 IN NS a.iana-servers.net.
example.com. 86400 IN NS b.iana-servers.net.
;; Query time: 14 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Sun May 24 09:45:00 UTC 2026
;; MSG SIZE rcvd: 85
- Header Section: Shows the status of your query.
status: NOERRORmeans the lookup was completely successful. - Question Section: Shows the query you sent—in this case, requesting the
NSrecord ofexample.comunder theIN(Internet) class. - Answer Section: The core result. It lists the domain name, the Time-to-Live (TTL) value in seconds (e.g.,
86400), the record class (IN), the record type (NS), and the hostnames of the authoritative name servers (a.iana-servers.netandb.iana-servers.net). - Metadata Section: Tells you how long the query took, which local DNS resolver answered it (in this case, your router's IP
192.168.1.1on port 53), and when the lookup was performed.
Getting a Clean, Concise Output
If you only want the raw name server addresses without the verbose headers and metadata, you can use the +short flag:
dig +short example.com NS
This will yield a clean, simple list of the name servers:
a.iana-servers.net.
b.iana-servers.net.
Method B: Using nslookup (Name Server Lookup)
If you are on Windows, or if you prefer a tool that works identically across Windows, macOS, and Linux, nslookup is a highly reliable legacy utility.
To retrieve a domain's authoritative DNS servers using nslookup, specify the query type before executing your lookup:
nslookup -type=ns example.com
This command outputs information split into two main sections:
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
example.com nameserver = a.iana-servers.net.
example.com nameserver = b.iana-servers.net.
- Server / Address: Displays the IP address of the local DNS resolver that answered your query.
- Non-authoritative answer: This indicates that the local recursive resolver answered the query out of its own local cache rather than contacting the authoritative servers live. It still returns the correct authoritative server hostnames for the domain.
Method C: Using PowerShell (Resolve-DnsName)
For Windows system administrators, modern PowerShell commands offer a massive advantage over nslookup because they return structured object data that can be filtered, passed through pipelines, or exported to other systems.
To get dns server of domain zones inside PowerShell, use the Resolve-DnsName cmdlet:
Resolve-DnsName -Name example.com -Type NS
This returns a beautifully formatted table representing the records:
Name Type TTL Section NameHost
---- ---- --- ------- --------
example.com NS 86400 Answer a.iana-servers.net
example.com NS 86400 Answer b.iana-servers.net
If you only want the string representations of the name servers to use inside an automated script, you can pipe the output and select the NameHost property:
(Resolve-DnsName -Name example.com -Type NS).NameHost
Method D: Programmatic Lookups (For Developers)
If you are writing software, an internal tool, or an API, you can easily query a domain's authoritative name servers programmatically.
Python Implementation (dnspython)
To query DNS in Python, the third-party dnspython library is highly recommended over the built-in socket module, as it provides native support for multiple record types.
import dns.resolver
def get_domain_nameservers(domain):
try:
# Query the Name Server (NS) records
answers = dns.resolver.resolve(domain, 'NS')
print(f"Authoritative Name Servers for {domain}:")
for server in answers:
print(f" - {server.target}")
except dns.resolver.NoAnswer:
print(f"No NS records found for {domain}.")
except Exception as e:
print(f"An error occurred: {e}")
get_domain_nameservers('example.com')
Node.js Implementation (dns Module)
Node.js has a built-in dns core module that lets you resolve name servers in just a few lines of asynchronous code:
const dns = require('dns');
const domain = 'example.com';
dns.resolveNs(domain, (err, addresses) => {
if (err) {
console.error(`Error fetching DNS servers: ${err.message}`);
return;
}
console.log(`Authoritative Name Servers for ${domain}:`);
addresses.forEach(ns => console.log(` - ${ns}`));
});
3. How to Query a Specific DNS Server for Domain Records
When you buy a domain, change hosting providers, or modify email routing settings (such as setting up MX or SPF records), you are required to modify records on your authoritative DNS servers. Once saved, these modifications must propagate across the internet.
However, because recursive resolvers cache DNS records to improve loading times, your local internet connection might show old cached values. To bypass this, you need to query an authoritative DNS server or public DNS resolver directly instead of relying on your machine's default system DNS resolver.
By executing a direct lookup, you can verify whether your record updates are live at the source before waiting for global ISP propagation.
Step-by-Step CLI Commands to Query a Specific Server
To check your changes, choose a specific DNS server to query. Common public DNS servers include Google (8.8.8.8), Cloudflare (1.1.1.1), or your domain's own authoritative name server hostnames.
1. Querying a Specific DNS Server with dig
To direct your lookup to a specific server using dig, append the @ symbol followed by the server's IP address or hostname:
dig @8.8.8.8 example.com A
This instructs your terminal to route the query directly to Google Public DNS, ignoring your local system settings. If you want to query the domain's authoritative server directly (for instance, Cloudflare's name server ns1.cloudflare.com for a cloudflare-managed domain), you can run:
dig @ns1.cloudflare.com example.com A
2. Querying a Specific DNS Server with nslookup
To query a target server using nslookup, pass the server's IP address or hostname as the final argument in the command:
nslookup example.com 1.1.1.1
Alternatively, you can switch nslookup into interactive mode, point to your preferred server, and run consecutive lookups:
nslookup
> server 1.1.1.1
Default Server: [1.1.1.1]
Address: 1.1.1.1
> example.com
Server: 1.1.1.1
Address: 1.1.1.1#53
Non-authoritative answer:
Name: example.com
Address: 93.184.215.14
3. Querying a Specific DNS Server with PowerShell
To bypass local lookup caches and query a specific IP address inside PowerShell, append the -Server parameter to the Resolve-DnsName cmdlet:
Resolve-DnsName -Name example.com -Type A -Server 8.8.8.8
Comparing Command-Line Options
Here is a quick-reference table outlining the differences between the core command-line tools for checking DNS records:
| Tool | Default Operating System | Key Benefit | Target Query Syntax |
|---|---|---|---|
dig |
macOS / Linux (Optional on Windows) | Most detailed output; highly customizable flags | dig @[ServerIP] [Domain] [Type] |
nslookup |
Windows / macOS / Linux | Universally available; interactive mode | nslookup [Domain] [ServerIP] |
Resolve-DnsName |
Windows (PowerShell) | Returns structured objects; ideal for scripting | Resolve-DnsName -Name [Domain] -Server [ServerIP] |
host |
macOS / Linux | Ultra-simplified, human-readable layout | host [Domain] [ServerIP] |
4. How to Identify Your Current Local DNS Resolver
Sometimes, your objective is not to find where a domain's website records are pointing globally, but rather to diagnose why your own local machine cannot connect to the internet. If you cannot reach web addresses, your device might be pointing to an inactive, misconfigured, or hijacked DNS server.
To see which recursive resolver your operating system is currently using to lookup domains, use the instructions below.
On Windows
To find your current DNS settings on Windows, you can query your active network adapters.
Using Command Prompt
Open Command Prompt (cmd) and execute:
ipconfig /all
Scroll down until you locate your active network connection (usually labeled "Ethernet adapter" or "Wireless LAN adapter Wi-Fi"). Look for the line labeled DNS Servers. This lists the IP addresses of the DNS resolvers assigned by your local router via DHCP, or manually configured in your network adapter settings.
Using PowerShell
For a faster, cleaner output, open PowerShell and execute:
Get-DnsClientServerAddress -AddressFamily IPv4
This returns a streamlined list showing which interface is mapped to which DNS server:
InterfaceAlias InterfaceIndex AddressFamily ServerAddresses
-------------- -------------- ------------- ---------------
Wi-Fi 12 IPv4 {192.168.1.1, 8.8.8.8}
On macOS
On macOS, you can quickly inspect network configurations via the Terminal.
While you can read the historical resolv configuration file using cat /etc/resolv.conf, modern macOS versions manage DNS dynamic routing through a background system configuration daemon. Reading /etc/resolv.conf might give you incomplete details.
Instead, use the scutil utility to get the absolute source of truth regarding active DNS configurations:
scutil --dns
Look under resolver #1 in the output. You will find the active IP address lists in a format like this:
resolver #1
nameserver[0] : 192.168.1.1
nameserver[1] : 1.1.1.1
flags : RequestARecAndAAAA
reach : 0x00020002 (Reachable,Directly Reachable Address)
On Linux
Most modern Linux distributions (such as Ubuntu, Debian, Red Hat, and Fedora) manage DNS routing using the systemd-resolved system service.
To query the active systemd DNS resolver configuration, run the following command:
resolvectl status
If you are on an older Linux distribution that does not use systemd-resolved, you can check the standard configuration file directly:
cat /etc/resolv.conf
Look for lines prefixed with nameserver. For example:
nameserver 127.0.0.53
(Note: 127.0.0.53 is a local loopback address indicating that a local service, like systemd-resolved, is acting as a proxy resolver on your computer).
5. Troubleshooting DNS Resolution and Caching Issues
When you query dns server for domain records or update your settings, things do not always go smoothly. Here are the three most common problems webmasters encounter, along with actionable troubleshooting fixes.
1. The Stale Cache Dilemma (Why You Don't See Changes)
Even if you verify that your authoritative name servers are outputting the brand-new, corrected IP addresses, your system or web browser might still load the old web server. This happens because DNS records are heavily cached at three separate levels:
- Your Web Browser: Browsers like Chrome, Firefox, and Edge maintain internal DNS caches.
- Your Operating System: The OS caches records locally to save bandwidth.
- Your Router/ISP: Your home router and internet provider keep their own lookup tables.
How to Flush Your Local DNS Cache
To clear your computer's local memory and force it to request the newest IP address from public DNS networks, flush your cache using the command matching your operating system:
- Windows: Open Command Prompt as Administrator and run:
ipconfig /flushdns - macOS: Open Terminal and run:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder - Linux (Systemd): Open Terminal and run:
sudo resolvectl flush-caches
2. DNS Propagation Delays (Understanding TTL)
Every DNS record has a value called TTL (Time to Live), measured in seconds. This value represents how long recursive resolvers are allowed to cache that specific record before they must ask the authoritative server for a fresh copy.
If your domain's TTL is set to 86400 (24 hours), and you make a record change, some users around the world may still be directed to your old server for up to a full day.
Pro-Tip: If you are planning a website migration, lower your DNS records' TTL values to
300(5 minutes) at least 24 to 48 hours before your move. This ensures your record updates propagate almost instantly when you perform the actual transition. Once the migration is successfully complete, you can safely raise the TTL back to its original value.
3. Deciphering DNS Status Errors
If you execute a search and receive an error instead of an IP address, the status code in the command's header section will tell you exactly what went wrong:
NXDOMAIN(Non-Existent Domain): The domain name does not exist globally, or there is a typo in your search command. If you recently registered the domain, the registrar may not have pushed it to the root TLD registry yet.SERVFAIL(Server Failure): The recursive resolver was unable to retrieve a response from the domain's authoritative name server. This usually means the authoritative name servers are offline, misconfigured, or experiencing a DDoS attack.REFUSED: The authoritative DNS server refused to answer your query. This is common if you are trying to query a private corporate DNS server from an unauthorized public network.
6. Frequently Asked Questions (FAQ)
How do I find the DNS provider hosting a domain?
To find out who actually hosts a domain's DNS zone files, find the domain's authoritative name servers (NS records) using dig example.com NS or nslookup -type=ns example.com. The domain names of those servers will point you to the provider. For example, if the name servers are ns-112.awsdns-14.com, the domain's DNS is hosted on Amazon Route 53. If they are dan.ns.cloudflare.com, the DNS is managed by Cloudflare.
What is the difference between an NS record and a DNS server?
An NS (Name Server) record is a specific setting inside a domain's DNS configuration that specifies which servers are authoritative for that domain. A DNS server is the physical or virtual server machine running DNS software that responds to queries. In short, NS records point to the authoritative DNS servers responsible for a domain.
Why does nslookup output say "Non-authoritative answer"?
A "Non-authoritative answer" simply means that the response was served from the local cache of your ISP's recursive DNS resolver rather than directly from the domain's authoritative name servers. This is standard behavior and does not mean the information is incorrect, though it could potentially be slightly outdated if the domain's records were recently updated.
Can I force a public DNS resolver to update its cache?
Yes. Many popular public DNS providers offer web tools that allow you to manually clear or "flush" their cached records for a specific domain name.
- To clear Google's DNS cache, use the Google Public DNS Flush Cache tool.
- To clear Cloudflare's cache, use the Cloudflare Purge Cache tool.
How can I test if a DNS change is visible globally?
Because propagation can take time depending on geographic locations, you can use global DNS checking web tools like DNSChecker.org, whatsmydns.net, or NsLookup.io. These websites query dozens of recursive DNS servers in various countries simultaneously, displaying a map and a checklist of how your domain resolves around the globe.
Conclusion
Learning how to get, analyze, and query the DNS configuration for a domain is a critical skill for developers, webmasters, and system administrators alike. Whether you are extracting authoritative name servers using dig +short, inspecting connection speeds using cross-platform nslookup, or using PowerShell's structured object output inside automation scripts, you now have the tools required to dissect and troubleshoot any domain configuration.
By understanding the critical distinction between recursive resolvers and authoritative servers—and knowing how to bypass local caches to verify records directly at the source—you can eliminate the guesswork from website migrations, domain transfers, and network troubleshooting. Save these command-line combinations in your cheat sheet so you are fully prepared the next time your DNS configuration requires a deep dive.





