The Domain Name System (DNS) is “the phone book” of the Internet. It helps us connect to a computer or another network device by its name, instead of its IP address.
However, even though we specify human-friendly names in our queries, the underlying network protocols still use the IP addresses. The mappings between the two can be found in the so-called authoritative DNS servers. So, when we connect to a name via a browser, it automatically pings the servers for the corresponding address.
In this tutorial, we’ll show how to find the authoritative DNS server for a domain name.
2. Domain Name System (DNS)
DNS is the hierarchical and decentralized naming system for identifying a computer within a network (internet or intranet). The DNS resource records map easy-to-remember domain names (e.g., www.baeldung.com) to numeric IP addresses (for instance, 2606:4700:3108).
A domain namespace, also known as just a namespace, is a name service the Internet provides.
2.1. DNS Zones
A domain namespace is a hierarchical data structure. Each node in it has a label and zero or more resource records containing the information related to the node’s domain name. A domain namespace contains all possible top-level domain (TLD) names and is divided into logical parts we call zones.
A DNS zone may contain a single domain name or many domains and sub-domains. A zone has four levels:
- Root – The root of the DNS system, represented by a “.” at the end of the domain name.
- Top-Level Domain (TLD) – First level zone for each TLD, such as “.com”, “.org”, or “.edu”.
- Domain – Second-level domains like baeldung are separate zones, managed by individuals or organizations.
- Hostname – This is a freely selectable name for a host, “www“ is the conventional, but not a web server’s mandatory name.
If we combine the hierarchy levels from the hostname to the root, we’ll get a Fully Qualified Domain Name (FQDN). For instance:
The above example shows a zone with multiple domains.
2.2. Authoritative Name Servers
Each domain must have one authoritative DNS server that publishes the information about the domain. An authoritative server for a zone is the name server that stores the IP addresses for the zone and holds the information about the zone’s domains in the text file known as the primary zone file.
For instance, when a browser tries to access www.baeldung.com, it gets the site’s IP address from the authoritative server for the baeldung.com zone, which holds the zone’s primary file.
3. Start of Authority (SOA)
A start of authority (SOA) is a DNS record with information about a zone. For example, the SOA record for baeldung.com looks like this:
Let’s now analyze its structure.
3.1. Structure of SOA
A SOA record has the following fields:
3.2. How to Find an SOA Record?
To find the authoritative name-server for a domain name, we first need to access the corresponding SOA record. To do so, we can use nslookup. It’s a command-line tool for querying Internet domain name servers.
For instance, if we want to find the SOA for google.com, we use the -type=soa switch of nslookup:
nslookup -type=soa google.com
Then, we receive a response specifying the primary name server and associated information:
There, we see that the primary name server for google.com is ns1.google.com. The line Server: Unknown occurs when the reverse lookup zone is incorrectly configured for the DNS client.
The above result shows that the answer is non-authoritative, which means we received the response from a cache of a DNS server around the internet and not from the authoritative server of google.com.
To receive an authoritative answer, we need to send the query to the authoritative server of google.com.
4. Authoritative Answers
An authoritative answer is a response we get directly from the primary DNS server holding the master copy of the zone file.
To find the authoritative answer for google.com, we execute a new nslookup query in which we specify the primary name server as ns1.google.com:
nslookup google.com ns1.google.com
Upon executing the command, we’ll get the following response:
It gives us the addresses of the authoritative server for the specified domain. The server’s IPv6 address is 2a00:1450:4019:805::200e, and the IPv4 address is 184.108.40.206.
In this article, we talked about DNS, and SOA, and showed how to get the authoritative name server for a domain using the nslookup tool.
The procedure is as follows. First, we get the name of the primary name server. Afterward, we use the primary server’s name to get the authoritative answer containing the authoritative name server’s IP address.