Determine if DNS server is master or slave with DiG
Is there a way to use DiG or nslookup to determine if a server is set to Master or Slave? And if a server is slave, return the Master's IP address?
No, there is no way. The DNS protocol provides nothing to learn the master/slave relationship from the outside.
Also, this distinction is often gone today. Many domains have only masters, synchronized on a common database.
You can use heuristics (see Maas' suggestions or use the increase of serial numbers, the first name server to increase will be the master) but they are clearly not reliable.
First, technically a DNS server is not necessarily exclusively a master or a slave. This can be different on a domain by domain basis. It might be master for some domains and slave for others.
If the domain name's DNS zone is configured correctly - then you can request the zone's SOA-record which (amongst other things) contains the host name of the primary DNS server (the master).
For example:
C:\>nslookup
Default Server: UnKnown
Address: 192.168.1.1
> set type=SOA
> google.com.
Server: UnKnown
Address: 192.168.1.1
Non-authoritative answer:
google.com
primary name server = ns1.google.com
responsible mail addr = dns-admin.google.com
serial = 1396486
refresh = 7200 (2 hours)
retry = 1800 (30 mins)
expire = 1209600 (14 days)
default TTL = 300 (5 mins)
You can now do another lookup on the primary server name (from the SOA-record - in this case "ns1.google.com"), to get the master's IP address:
C:\nslookup ns1.google.com.
Server: UnKnown
Address: 192.168.1.1
Non-authoritative answer:
Name: ns1.google.com
Address: 216.239.32.10
The answer in this case is 216.239.32.10