When a Windows client boots in an Active Directory environment, it follows a deterministic process to identify its AD site location. The key components involved are:
1. Client IP address detection
2. AD site topology stored in the Configuration partition
3. Subnet objects linked to site objects
4. DNS-based service discovery (_msdcs records)
Here's what happens under the hood when a client joins the network:
- The client obtains its IP address (via DHCP or static assignment)
- It queries the registry for cached site information (HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\DynamicSiteName)
- If no cache exists, it performs a subnet-to-site lookup against domain controllers
The Netlogon service handles the actual site determination. Here's a PowerShell snippet that demonstrates the process:
# View client's current AD site
Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters" -Name DynamicSiteName
# Force site rediscovery
nltest /dsgetsite
# View subnet-to-site mappings (requires AD module)
Get-ADReplicationSubnet -Filter * | Select Name, Site
While clients don't directly use _msdcs records for site determination, these records become crucial for locating site-specific services:
# Sample DNS query for site-specific DCs
nslookup -type=SRV _ldap._tcp.sitename._sites.dc._msdcs.domain.com
When clients end up in wrong sites, check these elements:
- Subnet definitions in AD Sites and Services
- IP address assignment consistency
- DNS resolution and replication status
- Site link costs and bridgehead servers
# Verify DC site registration
repadmin /siteoptions /IS_AUTO_TOPOLOGY_DISABLED
# Check intersite topology generation
repadmin /istg /verbose
For systems with multiple network interfaces, Windows uses the following precedence:
- Highest priority goes to the interface with a defined subnet in AD
- If multiple defined subnets exist, the first one alphabetically wins
- Undefined subnets trigger fallback to Default-First-Site-Name
When a Windows client boots in an Active Directory environment, it performs the following steps to determine its site location:
- Queries its IP address and subnet mask
- Compares this against the AD site/subnet mapping stored in the configuration partition
- Uses the result to query site-specific DNS records
The critical DNS records involved are stored in the _msdcs zone:
_ldap._tcp.SiteName._sites.dc._msdcs.DomainName
_kerberos._tcp.SiteName._sites.dc._msdcs.DomainName
Here's a PowerShell snippet to view site-specific records:
Resolve-DnsName "_ldap._tcp.Default-First-Site-Name._sites.dc._msdcs.contoso.com" -Type SRV
AD administrators define site associations using the Active Directory Sites and Services console. The mapping is stored in the configuration partition and replicated to all DCs.
Example subnet objects in ADSI Edit:
CN=192.168.1.0/24,CN=Subnets,CN=Sites,CN=Configuration,DC=contoso,DC=com
The client's algorithm works as follows:
- On startup, the client checks its registry cache at
HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\DynamicSiteName
- If no cached value exists, it queries a DC for site information
- The DC compares the client's IP against its subnet-to-site mapping
- The result is cached by the client for future use
Use these commands to verify client site membership:
nltest /dsgetsite
nltest /dsgetsite:corp-dc01.contoso.com
For DNS verification:
nslookup -type=SRV _ldap._tcp.dc._msdcs.contoso.com
Here's a C# example to programmatically determine site location:
using System.DirectoryServices.ActiveDirectory;
public string GetCurrentSite()
{
try {
return ActiveDirectorySite.GetComputerSite().Name;
}
catch (ActiveDirectoryOperationException e) {
// Handle errors
return "Unknown";
}
}