There are so many different ways and articles out there on how to configure NTP in Windows and every time I had to look it up. So i decided to write my own article for my own reference for the setup in my lab so I don’t have to Google it myself next time
This article is for Windows 2008 R2 and that’s all I’ve tested it on so far…
First, the basics. This is all you need if you want to keep it simple.
w32tm /config /manualpeerlist:pool.ntp.org,0x8 /syncfromflags:MANUAL
net stop w32time
net start w32timeIf the machine is a VM inside Hyper-V, you have to disable time sync. Open VM settings -> Management -> Integration Services and uncheck Time Synchronization. [Thanks Todd].
That should be it! Want to know more? Doesn’t work? Have you screwed up the config and want to start from the beginning? Keep on reading…
W32tm is the command to use. Sure, there are articles out there mentioning “net time”, but you should not use that. Some other also mentions editing the registry directly, but as Microsoft mentions in the article: It is recommended that you do not directly edit the registry unless there is no other alternative.
Which NTP-server to use? Or several?
The pool.ntp.org is a round-robin of random selected NTP servers. As they say “This is usually good enough for end-users”. But you might want to add several NTP-servers yourself for redundancy?
w32tm /config /manualpeerlist:”ntp1.sp.se ntp2.sp.se”,0x8 /syncfromflags:MANUALJust keep adding them with a space in between them.
Don’t forget your firewall
If you got a firewall between your host and the Internet, it might drop udp/123 which is the NTP protocol. This is how it looked in my Cisco ASA FW:
So I created a rule to allow it and after that it worked.
More info and debug logging
The following commands are quite useful which lists the current source, when it last sync’ed etc.
w32tm /query /statusEventually, when the server can’t get time from the NTP server it will add an event tto the event log:
Log Name: System
Event ID: 47
Description: Time Provider NtpClient: No valid response has been received from manually configured peer pool.ntp.org after 8 attempts to contact it. This peer will be discarded as a time source and NtpClient will attempt to discover a new peer with this DNS name. The error was: The peer is unreachable.
Otherwise, when it’s working, you will get:
Log Name: System
Event ID: 35
Description: The time service is now synchronizing the system time with the time source pool.ntp.org,0x8 (ntp.m|0x8|0.0.0.0:123->184.108.40.206:123).
You still getting problems? You can easily turn on debugging to a logfile which in this case is limited t0 10 MB and include ALL debug entries.
w32tm /debug /enable /file:C:\Temp\w32tmdebug.log /size:10485760 /entries:0-300Turn it off again with:
w32tm /debug /disableExpect a lot of info in this debug log. For me, when it worked, the following entries showed it was working:
– Reachability: peer pool.ntp.org,0x8 (ntp.m|0x8|0.0.0.0:123->220.127.116.11:123) is reachable.
– Logging information: NtpClient is currently receiving valid time data from pool.ntp.org,0x8 (ntp.m|0x8|0.0.0.0:123->18.104.22.168:123).
But when I had my firewall blocking the packets, I would get the following. Don’t trust this too much though, since I did get this when I allowed it in the firewall also, but when it was blocked, I did not get the entries above.
– Logging error: NtpClient has been configured to acquire time from one or more time sources, however none of the sources are currently accessible and no attempt to contact a source will be made for 1 minutes. NTPCLIENT HAS NO SOURCE OF ACCURATE TIME.
Force a resync
If you want to force the client to resync, run:
Sending resync command to local computer
The command completed successfully.If you get the following error, the computer can’t reach the NTP-server(s).
The computer did not resync because no time data was available.
Start from scratch
If you completely screwed up the config, you can always do the following command and it will completely erase and add a default W32time configuration:
net stop w32time
w32tm /registerWhen doing the unregister I got the following error for some reason, but it seems like it worked anyway.
The following error occurred: Access is denied. (0x80070005)
Sometimes when doing the /register, I would get. This usually solved by waiting for a while. I would suggest you stop the service before doing /unregister. Otherwise, a reboot would probably solve most problems.
The following error occurred: The specified service has been marked for deletion. (0x80070430)
If you miss any important information, let me know and I’ll add it.
0x8 say what?
You might have noticed the 0x8 flag above. What does it mean? KB875424 mention:
0x01 – use special poll interval SpecialInterval
0x02 – UseAsFallbackOnly
0x04 – send request as SymmetricActive mode
0x08 – send request as Client modeAnd the Directory Services Team mention some more reading here.