Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like to write script to allow a workstation to join a domain. I have the IP address of the primary DC of this domain. Are there any commands / scripts that I can use to retrieve the domain name of this AD domain such that the domain name can be retrieved for the join domain operation?

All workstations / DCs are Windows Server 2008.

There are two NICs on the workstations / DCs. One of them is used for network load balancing (NLB) and the other is used for management. The default gateway is only set on the NIC for NLB while the IP Address I have is the management one. No reverse DNS zones were setup in the primary DC and changing the settings of it is not preferred.

share|improve this question
    
It seems that I have mis-stated my question. I have revised it. Sorry for any inconvenience I caused. –  redcomethk Dec 2 '11 at 9:00
    
You are using NLB on a domain controller?... –  pauska Dec 2 '11 at 9:25
    
Yup. Does it violate some best practise for AD setting? –  redcomethk Dec 2 '11 at 10:08
2  
NLB (as in cluster) on domain controllers will break your replication, trash your dns registration entries etc. Don't do it. –  pauska Dec 2 '11 at 10:42
add comment

3 Answers

up vote 4 down vote accepted

Some ideas:

You could simply use nslookup to resolve the IP address to a DNS name like nslookup 192.168.1.2, but this obviously would not work if a reverse lookup zone has not been set up by the administrator.

Another way would be relying on the DNS suffix provided by the DHCP server - simply query ipconfig /all | find /I "suffix" to get to this information. This also would only work if the administrator has configured the DHCP scope correctly and the client is getting its address via DHCP.

If you can't rely on anything of the above to give correct information, consider using VBScript or PowerShell for binding to the AD LDAP service and querying the RootDSE object for properties to find out the domain name. This should work even using an anonymous bind - i.e. without providing credentials. From there, you should be able to query the _ldap._tcp.pdc._msdcs.yourdomain SRV record to find the name of the PDC.

share|improve this answer
    
I have stated my question wrongly but I find the latter part seems useful to solve my problem. I am going to test it. Thank you for your help. –  redcomethk Dec 2 '11 at 9:04
    
you are welcome –  syneticon-dj Dec 2 '11 at 10:02
    
In a Windows domain I don't think that you would typically set the DNS Domain Name option in DHCP, as the primary DNS suffix would come from the domain membership, so it's not likely that a non-domain joined workstation that's getting its ip address from DHCP is going to get the primary DNS suffix of the domain from DHCP. –  joeqwerty Dec 2 '11 at 13:45
    
Don't know - it's what I would do. Also helps to enable single-label name resolution for non-domain clients (like Linux machines). Also, I believe the dynamic DNS update feature of the DHCP server depends on the DNS domain name option to be correctly configured. –  syneticon-dj Dec 4 '11 at 17:09
    
I have used the VBScript approach to query the domain name. Thank you! –  redcomethk Jan 12 '12 at 9:30
add comment

You could always use the tool nbtstat -A a.b.c.d. Then figure out what the record is with the 00 netbios suffix. Netbios is less, and less common these days.

share|improve this answer
    
There are multiple NIC on the machines. Default gateway is only set on the NICs for NLB. However, the IP address I have on hand is the other one for management purpose. As a result, I cannot use this tool. Thx! –  redcomethk Dec 2 '11 at 8:45
add comment

There's a tool in Powershell that will join the local machine to a domain. There are two problems, though. The first is that you must be able to contact the domain from that machine. Is the machine set to use the DNS server for that domain?

Second, you can use nslookup on the IP of the domain controller to get the reverse DNS entry for it. Just parse the output for the line with the hostname in it. Again, your DNS must be set up correctly on the box for this to happen. This blog post details how to set the DNS server, again in Powershell.

Let us know if you get this working, this sounds like a neat little script.

share|improve this answer
    
For the first tool, I need to provide the DomainName right? But this is the information I need. I do not want to modify the DNS server settings and so the second tool may not be suitable for me too. Anyway thanks for your help. –  redcomethk Dec 2 '11 at 8:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.