Using the built-in Win2K/WinXP NTP client
Posted: 6/10/2003 11:20:19 AM
By: Comfortably Anonymous
Times Read: 15,324
0 Dislikes: 0
Topic: Windows Administration

How to synchronize Windows 2000/XP clocks with an NTP server

BACKGROUND

The Network Time Protocol (NTP) is a special protocol specifically designed for accurately setting the time on a computer, based on a standardized time source, such as the NIST atomic clock. NTP takes into account network propagation delays and other factors to ensure that time is accurate down to the millisecond range.

This document takes on the task of setting up an NTP synchronization client to set time based on the information obtained from an NTP server. Setting up an accurate NTP server involves obtaining time from multiple sources and algorithmically combine the information from the different sources to get the most accurate time. This document does not go into that. For normal computer operations where accuracy within a few millseconds is adequate, setting up a normal NTP client synching with a single NTP source is sufficient. For more information about NTP itself, see www.ntp.org.

HIDDEN TREASURE

To set the time on your Windows 2000/XP box, you will need to get an NTP client. There are many freeware, open source, and commercial packages available. However, you don't need any of them, just read on! Although finding information about it is next to impossible, Windows 2000 and XP have an NTP client built in! I was really surprised to find it, having obtained third-party NTP client software before I was digging around and found it on accident.

Note: As far as synchronizing time on machines that are a member of Active Directory, you only need to synchronize time on the domain controller. All machines which are members of that domain will automatically synch their time with the domain controller. (Sorry, I tend to mix Win2K and WinNT terminology pretty bad at times, so don't beat me up for it :) ) So no need to do this on every machine if it is a member of an AD Domain, just the DC.

However, you may have machines that are not part of a domain (Such a public web servers, etc, which are more secure if standing alone) that you need to keep accurate time on. In addition, you are going to need to keep the time on the domain controller synched with an NTP server so that all the machines synching against the domain controller have accurate time. This way allows you to keep your machines synched to a time source WITHOUT buying/obtaining additional software!

There are two pieces involved - the somewhat well-known NET TIME command (Which has a lot of additional functionality since the WinNT days), and the extremely obscure "w32tm.exe" command which comes with all versions of Win2K and WinXP. (It will probably come with Win2K3 as well, but I haven't played with any of the pre-release copies, so cannot say for sure.) You will also need to make sure the Windows Time service is set to Automatic.

The new, improved NET TIME included SNTP functionality. NTP is Network Time Protocol. SNTP is Simple Network Time Protocol, not to be confused with SMTP (Simple Mail Transport Protocol) or SNMP (Simple Network Management Protocol). What the difference is between NTP and SNTP I do not know, nor have a need to find out the differences. The important thing is that an SNTP client can synchronize just find with a 'normal' NTP server.

This is just going to take you through the basics of setting up automatic time synchronization to an NTP server, for additional information on the functionality of these two commands, see NET HELP TIME, and w32tm /?

SPECIFYING A TIME SERVER

Selection of which NTP server you wish to synchronize with is done with the NET TIME command. You will need to locate an NTP Source. If you are on a corporate network, most Cisco routers have NTP Server functionality built in. (As long as the router itself is set up to synch to an external NTP server somewhere.) Check with your networking guys to find out. In other situations, there are publically accessible NTP servers all over the internet. See http://www.cis.udel.edu/~mills/ntp/servers.html for a list of secondary (aka Stratum 2) public NTP servers. There is a list of Primary (Stratum 1) public NTP servers as well, but they should be reserved for synchronization of Stratum 2 servers. Stratum 2 servers are accurate within microseconds of Stratum 1 servers. If you are going to need Stratum 1 accuracy on your machines, you will need to go to the multiple-source analysis method described in paragraph two.

Pick a a Stratum 2 server and set it as the time source:

NET TIME /SetSNTP:clock.somewhere.edu

You can verify the setting with:

NET TIME /QuerySNTP

Your machine now knows where to obtain it's NTP information... Now to set your machine to automatically synchronize with the NTP server.

AUTOMATIC SYNCHRONIZATION

You use the w32tm.exe command to control the automatic time synchronization of the Windows Time service. (Once again, make sure that the Windows Time service is set to run automatically on your machine) It lives in your /winnt/system32 directory, so should already be in your PATH. You can get a quick synopsis on the command with w32tm /?

To set automatic synchronization, I usually use the following:

w32tm -v -once -period 65532

The '-v' runs w32tm in verbose mode so you can make sure that everything is working properly.
The '-once' makes it do only one manual synchronization, without it, the w32tm command keeps running and synchronizing until you hit ctrl-c.
The '-period 65532' is the most important part. It tells the Windows Time service to synch once every 45 minutes until there are 3 successful synchronizations, the fall back to once every 8 hours. Once every eight hours is sufficient to counteract the drift in the pathetically inaccurate clocks in an x86 type motherboard.

DEBUGGING

Be aware that if you manually set the time on your computer with the time command or by double-clicking on your taskbar clock, it will clear all the NTP information you have set up. If that it done, just repeat the above steps.

You can run 'w32tm -v -once' anytime without changing the automatic synchronization settings. Use this if you suspect problems. Look through the information displayed for a full trace of what the client is doing. It will show any problems in connecting to the time server, or if the server is returning gibberish, etc.

MORE INFORMATION

Further questions? Come to MessageBase for answers.

(c) 2003 Ben Kimball. Verbatim reproduction of this document is permitted as long as this notice and the above MessageBase link is preserved.

Rating: (You must be logged in to vote)
Discussion View:
Replies:

RE: Using the built-in Win2K/WinXP NTP client
Posted: 7/20/2003 10:26:41 AM
By: Comfortably Anonymous
Times Read: 4,561
0 Dislikes: 0
Topic: Windows Administration
Hi and thank You.

You saved my day. 8-)

I was trying half the day to get ntp going on a remote (!) "W2k prof" machine and found only the command.
But it did not work. "No timeserver" it said, but this was not true. 8-(

The did it perfectly with the server stated by . 8-)

Maybe now I can spend the rest of the sunday doing *real* work...


Yours

Pollyanna
Rating: (You must be logged in to vote)

RE: Using the built-in Win2K/WinXP NTP client
Posted: 1/20/2004 4:32:55 PM
By: Comfortably Anonymous
Times Read: 2,018
0 Dislikes: 0
Topic: Windows Administration
Hey, Ben, thanks!  I just fixed the NPT problem on the FTP server using this!

GRIZZ
Rating: (You must be logged in to vote)

RE: Using the built-in Win2K/WinXP NTP client
Posted: 1/20/2004 4:44:24 PM
By: Comfortably Anonymous
Times Read: 2,105
0 Dislikes: 0
Topic: Windows Administration
Oh and another thing.  Did you know, when I did a google search on these items, 'w32tm set ntp source' your page was the first hit!

GRIZZ
Rating: (You must be logged in to vote)

RE: Using the built-in Win2K/WinXP NTP client
Posted: 4/13/2004 6:53:05 AM
By: Comfortably Anonymous
Times Read: 2,713
0 Dislikes: 0
Topic: Windows Administration
Unfortuntaly this DOES NOT work with WinXP Service Pack 1 with all critical windows updates (April 13, 2004).  The problem is that w32tm does not recognize any of the command line parameters.  I looked to see if there were newer parameters that would match the ones given in the article and there does not seem to be.  This utility seems to be for a server, with functions for updating other computers.

W32tm.exe Info -
File Version: 5.1.2600.0 (xpclient.010817-1148)
File Date (Created): Wednesday, August 28, 2002, 9:00:00 PM
File Size: 49,664 bytes

w32tm /? output:

w32tm [/? | /register | /unregister ]
  ? - this help screen.
  register - register to run as a service and add default
    configuration to the registry.
  unregister - unregister service and remove all configuration
    information from the registry.

w32tm /monitor [/domain:]
               [/computers:[,[,...]]]
               [/threads:]
  domain - specifies which domain to monitor. If no domain name
    is given, or neither the domain nor computers option is
    specified, the default domain is used. This option may be
    used more than once.
  computers - monitors the given list of computers. Computer
    names are separated by commas, with no spaces. If a name is
    prefixed with a '*', it is treated as a PDC. This option
    may be used more than once.
  threads - how many computers to analyze simultaneously. The
    default value is 3. Allowed range is 1-50.

w32tm /ntte
  Convert a NT system time, in (10^-7)s intervals from 0h 1-Jan 1601,
  into a readable format.

w32tm /ntpte
  Convert an NTP time, in (2^-32)s intervals from 0h 1-Jan 1900, into
  a readable format.

w32tm /resync [/computer:] [/nowait] [/rediscover] [/soft]
  Tell a computer that it should resynchronize its clock as soon
  as possible, throwing out all accumulated error statistics.
  computer: - computer that should resync. If not
    specified, the local computer will resync.
  nowait - do not wait for the resync to occur;
    return immediately. Otherwise, wait for the resync to
    complete before returning.
  rediscover - redetect the network configuration and rediscover
    network sources, then resynchronize.
  soft - resync utilizing existing error statistics. Not useful,
    provided for compatibility.

w32tm /stripchart /computer: [/period:]
    [/dataonly] [/samples:]
  Display a strip chart of the offset between this computer and
  another computer.
  computer: - the computer to measure the offset against.
  period: - the time between samples, in seconds. The
    default is 2s
  dataonly - display only the data, no graphics.
  samples: - collect samples, then stop. If not
    specified, samples will be collected until Ctrl-C is pressed.

w32tm /config [/computer:] [/update]
    [/manualpeerlist:] [/syncfromflags:]
    [/LocalClockDispersion:]
  computer: - adjusts the configuration of . If not
    specified, the default is the local computer.
  update - notifies the time service that the configuration has
    changed, causing the changes to take effect.
  manualpeerlist: - sets the manual peer list to ,
    which is a space-delimited list of DNS and/or IP addresses.
    When specifying multiple peers, this switch must be enclosed in
    quotes.
  syncfromflags: - sets what sources the NTP client should
    sync from. should be a comma separated list of
    these keywords (not case sensitive):
      MANUAL - include peers from the manual peer list
      DOMHIER - sync from a DC in the domain hierarchy

w32tm /tz
  Display the current time zone settings.

w32tm /dumpreg [/subkey:] [/computer:]
  Display the values associated with a given registry key.
  The default key is HKLM\System\CurrentControlSet\Services\W32Time
    (the root key for the time service).
  subkey: - displays the values associated with subkey of the default key.
  computer: - queries registry settings for computer
Rating: (You must be logged in to vote)

Re: Using the built-in Win2K/WinXP NTP client
Posted: 12/1/2005 4:39:17 AM
By: Comfortably Anonymous
Times Read: 3,230
0 Dislikes: 0
Topic: Windows Administration
Hi,

i'm working several Hours on this Topic in the Past, because it's a Part of my Job. So i find out, that W32time is able to be a good to configure SNTPServer and a NTPClient and it can provide (S)NTP-Service (TCP-Port123) for other NTP-Clients such as Unix Boxes, Cisco Equipment. Also your primary windows domain controller(s) in your LAN can be synced via such konfigured W32time(Source). Member Computer in your Windows Domain(s) are automatically synced via the Domain Controller per default. Also an additional setting as Broadcast NTP Server is possible with W32time.
If you have a (cheap) DCF77 Receiver with any working Windows Driver, you can build your own "Stratum 1" ;-) Timesource with W32time on any Windows2K/XP Workstation in your LAN and you don't need Internet Access for syncing your Network time.
All you need to do is editing your Registry:
Start "regedit", and follow the Tree to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time
Save/export this Key (w32time) for your Backup in a *.reg File.
You can find a detailed Description of the affected Registry Keys here:

http://www.microsoft.com/technet/prodtechnol/windowsserver2003/library/DepKit/60b22065-a3c9-42e2-8594-21d766e73339.mspx

Here comes my own config for W32time (WinXP-pro) to set up a DCF77 synced local NTP Server for my Network:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time]
"ErrorControl"=dword:00000001
"Group"=""
"Objectname"="LocalSystem"
"Start"=dword:00000002
"Type"=dword:00000020
"LocalNTP"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config]
"LastClockRate"=dword:0002625a
"MinClockRate"=dword:000260d4
"MaxClockRate"=dword:000263e0
"FrequencyCorrectRate"=dword:00000004
"PollAdjustFactor"=dword:00000005
"LargePhaseOffset"=dword:00138800
"SpikeWatchPeriod"=dword:0000005a
"HoldPeriod"=dword:00000005
"MaxPollInterval"=dword:0000000f
"LocalClockDispersion"=dword:0000000a
"EventLogFlags"=dword:00000002
"PhaseCorrectRate"=dword:00000001
"MinPollInterval"=dword:0000000a
"UpdateInterval"=dword:00007530
"MaxNegPhaseCorrection"=dword:ffffffff
"MaxPosPhaseCorrection"=dword:ffffffff
"AnnounceFlags"=dword:00000005
"MaxAllowedPhaseOffset"=dword:0000012c

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters]
"ServiceMain"="SvchostEntry_W32Time"
"NtpServer"="127.127.1.0"
"Type"="NTP"
"LocalNTP"=dword:00000001
"Period"="SpecialSkew"
"Adj"=dword:0002626b
"msSkewPerDay"="-9200,0000"
"AviodTimeSyncOnWan"=dword:00000001
"ReliableTimeSource"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient]
"Enabled"=dword:00000001
"InputProvider"=dword:00000001
"AllowNonstandardModeCombinations"=dword:00000001
"CrossSiteSyncFlags"=dword:00000002
"ResolvePeerBackoffMinutes"=dword:0000000f
"ResolvePeerBackoffMaxTimes"=dword:00000007
"CompatibilityFlags"=dword:80000000
"EventLogFlags"=dword:00000000
"DllName"="C:\\WINDOWS\\System32\\w32time.dll"
"SpecialPollTimeRemaining"=hex(7):00,00
"SpecialPollInterval"=dword:00000e10

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer]
"Enabled"=dword:00000001
"InputProvider"=dword:00000000
"AllowNonstandardModeCombinations"=dword:00000001
"DllName"="C:\\WINDOWS\\System32\\w32time.dll"

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Enum]
"0"="Root\\LEGACY_W32TIME\\0000"
"Count"=dword:00000001
"NextInstance"=dword:00000001

If you query this Time source via "ntpq" (Unix) or net time... you will see this is a Stratum1 and your NTP-Clients will always prefer this as its Time Source, also if more than this NTP Server are configured in your NTP Client for redundancy.
The Diffrence between NTP and SNTP is a reduced command set in SNTP.

If you have additional Questions about this, email me.

mario_benndorf(at)hotmail.com
Rating: (You must be logged in to vote)

New location for Public NTP Server List
Posted: 5/31/2007 10:51:18 PM
By: Comfortably Anonymous
Times Read: 1,509
0 Dislikes: 0
Topic: Windows Administration
The old site listed in the NTP document now says to go to http://support.ntp.org/bin/view/Servers/WebHome instead.
Rating: (You must be logged in to vote)

Re: NTP Binding fails on Win2K domain controller
Posted: 6/6/2007 11:40:57 PM
By: Comfortably Anonymous
Times Read: 1,698
0 Dislikes: 0
Topic: Windows Administration

If you are seeing the following messages when you run "w32tm -v -once" on a Win2K Domain Controller, see the following knowledgebase article:

 ==============================
(previous lines removed)
W32Time: Server: Binding to 1 NIC.
W32Time: bind failed: 0x80072740
W32Time: 0xC0000031 reported to System Log in Event Viewer
W32Time: BEGIN:FinishCleanup
W32Time: BEGIN:TsUpTheThread
W32Time: END Line 1384
W32Time: BEGIN:UnInitializeDC
W32Time: Ptrs 0 - 0
W32Time: END:Line 725
W32Time: Time service stopped.
W32Time: END:Line 383

http://support.microsoft.com/kb/247321

Rating: (You must be logged in to vote)