To get the nameservers of a domain, you can use the nslookup or dig command-line tools. Both are available on most Unix-like operating systems, including Linux and macOS. On Windows, nslookup is available by default.
Using nslookup
nslookup -type=ns example.com
Using dig
dig ns example.com
Using host
host -t ns example.com
Explanation
- 
    
nslookup -type=ns example.com: This command usesnslookupto query the DNS records for the specified domain (example.com) and returns the nameserver (NS) records. - 
    
dig ns example.com: This command usesdigto perform a DNS lookup for the nameserver records of the specified domain. - 
    
host -t ns example.com: This command useshostto query the nameserver records for the specified domain. 
Example Output
Here’s an example output using dig:
; <<>> DiG 9.10.6 <<>> ns example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18303
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;example.com.			IN	NS
;; ANSWER SECTION:
example.com.		86400	IN	NS	ns1.example.com.
example.com.		86400	IN	NS	ns2.example.com.
example.com.		86400	IN	NS	ns3.example.com.
example.com.		86400	IN	NS	ns4.example.com.
;; ADDITIONAL SECTION:
ns1.example.com.	172800	IN	A	192.0.2.1
;; Query time: 38 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Jul 18 14:55:15 EDT 2024
;; MSG SIZE  rcvd: 118
This output shows the nameservers (ns1.example.com, ns2.example.com, etc.) for the domain example.com.