为 Active Directory 域配置 NTP 时间源

Jacki

Active Directory 中的时间同步对于域服务和安全机制的正常运行至关重要。如果域中未配置正确且可靠的时间同步方案,则在与内部和外部系统交互时,可能会导致身份验证、加密协议的使用和证书验证出现问题。例如,Kerberos认证要求客户端和服务器之间的时间差小于5分钟。在本指南中,我们将探讨 Active Directory 中时间同步的工作原理以及如何配置域控制器以将其时间与外部准确的 NTP 时间源同步。

内容:

Active Directory 时间同步方案基于严格的域层次结构:

  • AD 中的主要时间源是域控制器PDC仿真器FSMO 角色。
  • 其他域控制器将他们的时间与 PDC 同步。
  • 会员服务器和工作站按照AD拓扑与最近的DC同步时间(默认情况下,Windows计算机与外部时间源同步时间)time.windows.com,但加入域后,按照AD域层次结构进行时间同步)。

来源:https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2003/cc773013(v=ws.10)?redirectedfrom=MSDN

为了确保所有域计算机上的时间准确,必须将 PDC 配置为使用 NTP 协议将其时间与可靠的外部时间源同步。

找出正在运行的域控制器的名称PDC仿真器FSMO角色,运行PowerShell命令

Get-ADDomain | Select-Object PDCEmulator

手动配置 PDC 与外部 NTP 服务器同步时间

默认情况下,主域控制器 (PDC) 仿真器将时间与主机上系统的本地 CMOS 硬件时钟同步。对其运行命令进行检查:

w32tm /query /source

本地 CMOS 时钟表示使用本地时钟作为时间源。在这种情况下,PDC 上的事件查看器日志包含事件 ID12来自授时服务:

Time Provider NtpClient: This machine is configured to use the domain hierarchy to determine its time source, but it is the AD PDC emulator for the domain at the root of the forest, so there is no machine above it in the domain hierarchy to use as a time source. It is recommended that you either configure a reliable time service in the root domain, or manually configure the AD PDC to synchronize with an external time source. Otherwise, this machine will function as the authoritative time source in the domain hierarchy. If an external time source is not configured or used for this computer, you may choose to disable the NtpClient.

如果 DC 运行在配置为与主机(虚拟机管理程序)同步时间的虚拟机上,则此命令将返回:

VM IC Time Synchronization Provider

因此,在所有域控制器上,您应该在虚拟机设置中禁用时间同步,或者通过配置适当的注册表选项来阻止 DC 与主机同步时间:

reg add HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesw32timeTimeProvidersVMICTimeProvider /v Enabled /t REG_DWORD /d 0 /f

让我们在 PDC 上重新配置 Windows 时间设置,以使用外部 NTP 服务器作为时间源。作为时间源,您可以使用距您所在位置最近的 NTP 服务器https://www.ntppool.org项目池。

对于英国,这可以是 NTP 服务器uk.pool.ntp.org:0.uk.pool.ntp.org,1.uk.pool.ntp.org, 和2.uk.pool.ntp.org

确保可以从 PDC 访问这些 NTP 服务器(并且端口 123/UDP 未被防火墙阻止)。

w32tm /stripchart /computer:1.uk.pool.ntp.org

如果您收到来自 NTP 服务器的响应,则可以使用这些外部主机作为主 DC 的时间源。运行命令:

net stop w32time
w32tm /config /syncfromflags:manual /manualpeerlist:"0.uk.pool.ntp.org,0x8 1.uk.pool.ntp.org,0x8 2.uk.pool.ntp.org,0x8"
w32tm /config /reliable:yes
net start w32time
w32tm /config /update

将主机时间与 NTP 同步:

建议阅读:如何重置 Active Directory 域管理员密码

w32tm /resync

检查外部 NTP 服务器时间现在是否用作 PDC 上的时间源(检查 TimeProviders 部分):

w32tm /query /configuration

使用组策略为 PDC 配置 NTP 时间源

由于 PDC 模拟器角色可以转移(占用)到另一个域控制器,因此您可以配置一个组策略,自动将外部 NTP 同步设置应用于当前拥有 PDC 角色的 DC。

为此,请打开组策略管理控制台 (GPMC.msc)并创建一个新的 WMI 组策略过滤器。导航至WMI 过滤器部分,创建一个名为的过滤器PDC仿真器使用 WMI 查询:

Select * from Win32_ComputerSystem where DomainRole = 5

创建一个新的 GPO,打开它,然后转到计算机配置 -> 管理模板 -> 系统 -> Windows 时间服务 -> 时间提供程序

配置以下三个 GPO 选项:

  • 配置 Windows NTP 客户端:Enabled (策略设置如下所述)
  • 启用 Windows NTP 客户端:Enabled
  • 启用 Windows NTP 服务器:Enabled

在中设置以下参数配置 Windows NTP 客户端政策设置:

  • NTP服务器:0.uk.pool.ntp.org,0x8 1.uk.pool.ntp.org,0x8 2.uk.pool.ntp.org,0x8 3.uk.pool.ntp.org,0x8
  • 类型:NTP
  • 跨站点同步标志:2
  • 解决对等退避分钟数:15
  • 解决PeerBackoffMaxTimes:7
  • 特殊池间隔:1024
  • 事件日志标志:0

分配PDC仿真器您之前为 GPO 创建的过滤器。

现在将此 GPO 链接到域控制器组织单位。

AD 中客户端计算机上的时间同步设置

在一个域中,您仅有的必须在具有 PDC 角色的域控制器上手动配置时间同步。它应该与外部 NTP 同步时间。其余域控制器或客户端计算机(工作站)上的时间同步不需要特殊的策略或设置。事实上,做出这样的改变可能会适得其反。根据 AD 层次结构 (NT5DS),域中的时间同步应该可以正常工作。

在剩余的(额外的)域控制器和其他客户端上,应根据域层次结构执行时间同步。验证这一点:

w32tm /query /configuration

如果配置正确,TimeProviders部分的时间源类型应该是NT5DS(Net Time 5 目录服务)。

客户端上的时间服务设置存储在HKLMSYSTEMCurrentControlSetServicesW32TimeParameters注册表项。

如果不是这种情况,您可以重置客户端的时间同步设置并强制其使用默认的域层次结构时间同步方案

net stop w32time
w32tm.exe /unregister
w32tm.exe /register
net start w32time
w32tm /config /syncfromflags:DOMHIER /update
w32tm /resync

验证最近的域控制器 (LogonServer) 现在是否用作客户端上的时间源:

w32tm /query /source

如何修复 Windows 客户端上的常见时间同步错误。