How can I find out which server hosts LDAP on my windows domain?

bugfixr picture bugfixr · Apr 14, 2009 · Viewed 146.7k times · Source

I am trying develop an application (C#) to query an LDAP server. I don't know the actual server named to query - is there a way to find out using standard windows tools or something in .net?

I've also heard rumors that having the server name (ldap://server/) is not always needed as long as I've got dc=domain,dc=com in my query string, but I've so far been able to work with it this way.

Any tips?

Thanks

Answer

Stefan Gehrig picture Stefan Gehrig · Apr 15, 2009

AD registers Service Location (SRV) resource records in its DNS server which you can query to get the port and the hostname of the responsible LDAP server in your domain.

Just try this on the command-line:

C:\> nslookup 
> set types=all
> _ldap._tcp.<<your.AD.domain>>
_ldap._tcp.<<your.AD.domain>>  SRV service location:
      priority       = 0
      weight         = 100
      port           = 389
      svr hostname   = <<ldap.hostname>>.<<your.AD.domain>>

(provided that your nameserver is the AD nameserver which should be the case for the AD to function properly)

Please see Active Directory SRV Records and Windows 2000 DNS white paper for more information.