Monday, January 30, 2012

Windows not syncing with NTP server

NTP (Network Time Protocol) is widely used for computer clock synchronization in  internet. There are various versions of NTP. Latest version as of Jun 2010 is NTPv4 and is well described in RFC5905. NTP4 is modified to accommodate IPv6 and other improvement has been done over NTPv4.

Are you getting 'Peer Unreachable' when you try to syc with NTP server?
Usually there are various reasons behind the problem.

1. Firewall or port filter : Make sure that default UDP port 123 is open. You can test this real quick just by turning off Firewall.

2. Windows Time Service (w32time) not running on the appropriate mode
There are various modes of operation for Windows Time Service as NTP supports several different packet types.
Normally NTP client sends 'client' mode request packets to a NTP server
NTP server responds back with 'server' mode packet with timing information

By default some windows (esp. XP and earlier) sends 'symmetric active' mode packet instead of 'client' mode request packets. 'symmetric active' mode packets is for NTP's peering feature where a pool of computers(peers) are configured to sync their clocks among each others to agree upon a common 'network time', which then can be supplied to the client.

Usually NTP server drops 'symmetric active' mode packets, unless it is told to do so.

Q: How can I switch to 'client' mode of Windows Time Service?

Ans: You have to change the Windows registry and it can be done easily via command line

 w32tm  /config  /manualpeerlist:ntp.myserver.com,0x8  /syncfromflags:MANUAL

Here, ntp.myserver.com is my NTP server

The valid settings for the mode used with the /manualpeerlist switch include the following:
  • 0x01 - use special poll interval SpecialInterval
  • 0x02 - UseAsFallbackOnly
  • 0x04 - send request as SymmetricActive mode
  • 0x08 - send request as Client mode
The mode that Windows Time uses to send requests is set by the following registry subkey:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer

0x8  enables 'client' mode for Windows Time Service
syncfromflags:MANUAL  forces Windows Time Service to use manualpeerlist for the time query. 

Make changes effective immediately
w32tm  /config  /update

To resync manually
w32tm /resync


Additional Tips: 
If you want to sync with time server everyday, you can create a new 'Scheduled Task' under Control Panel --> Scheduled Task to run  'w32tm  /resync' everyday at your specified time.

Good Luck!

No comments: