Monday, November 26, 2012

Setting up Windows XP to use a time server

I needed to set up my Windows and Linux systems to all use time servers so that the times in the error logs on all systems would match. This does not seem to be as easy as I remembered it being for XP systems, and super easy for the Linux systems except that we've lobotomized their ethernet interfaces so that the whole LAN can be taken off of the WAN whenever we need. Consequently, I never got to a working answer with either system. (Update: See final solution at the end of the post.) Here is what I've learned so far:

Network Time Protocol (NTP) works by having branch systems poll systems higher up the tree rather than going to a central hub. Presumably, the base of the tree is a reliable server. Reliability at the branch level is increased by having them poll more than one other system, in fact any number which are then voted against each other. The branching levels are called STRATUMs, and it's bad form to connect to a STRATUM1 system but STRATUM2 or lower is fine.

Astonishingly, in Windows it seems to be set up to use an NTP time server, but to configure it oddly requires nightmarish direct registry modification. Per the following links:

http://www.atomic-clock.galleon.eu.com/support/windows-xp-ntp-time-server.html
http://support.microsoft.com/kb/314054

This set of slides from NIST hints that is could be possible to set everything up by using net time, and then stopping and starting w32time, but that can't be true otherwise M$ and others would have that instead of the registry modifications in their hints.

http://tf.nist.gov/service/pdf/win2000xp.pdf


After reading these links, my thoughts were more along the lines of "maybe the laptops are already set up to time servers and I just need to prove it to myself.". So the question of how to check if a server has been set up led to further dead ends until I decided to give that up too. Apparently, net time and w32tm can be used to find this out, except that not so much on XP. Apparently the /querysntp option doesn't exist for net time on XP, and w32tm fails if the local domain, protocols, or firewall aren't set up right.

http://superuser.com/questions/425233/how-can-i-check-a-systems-current-ntp-configuration

When I tried net time on the laptops I got "System error 5 has occurred. Access is denied." (It worked fine on my own laptop.) This apparently means access to the remote system, apparently if any systems in the local domain are mismatched this will fail, or if there's a firewall issue, or oddly if the computer times are mismatched (hope this isn't it):

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

From a rootkit vendor:

http://www.personalcomputerfixes.com/general-errors/how-to-fix-system-error-5-%E2%80%93-%E2%80%9Caccess-is-denied%E2%80%9D/

And w32tm was full of options, none of which included a simple query as to the setup, as far as I could tell.

So eventually, I decided that the PC times seem really close to my own which I know is on a server, so they must be getting time from a server. How about the linux box?

Finally, something easy:

https://help.ubuntu.com/8.04/serverguide/NTP.html

Getting less eay:

http://www.ntp.org/ntpfaq/NTP-a-faq.htm

Too bad we turned off both the nameservice and even the gateways for these machines because we couldn't be bothered with any sort of sophistication when setting them up to run off of the network. Ah well.

Update: From the first link just above, I learned that it is possible for a sysadmin to run ntpdate directly to do a one-shot clock setup from another server. Presumably I wasn't able to use the gateways on my linux box to get to any other servers, but here's where it all comes together: what about polling the other systems on my LAN that are in the /etc/hosts table? Yes, I was able to reset the time on the linux box by using the windows laptop as my NTP host. Using:

sudo ntpdate [ip of the windows XP system]

and boom the ubuntu time now matches the time on my Windows laptop. Crude but effective, and it wouldn't have worked if my XP firewall had been better set up).

Furthermore, I added an entry in /etc/cron.daily to run ntpdate every day since the unix boxes seem to have an impressive amount of clock drift (a couple of minutes over the course of a month). This required that I add an executable script (named ntpdate per the examples but I think that the name is unimportant) to this directory which contained my ntpdate command. This was covered in the first ubuntu link above, however I also had to do some reading up on cron and found some very nice links for that:

http://www.unixgeeks.org/security/newbie/unix/cron-1.html

http://www.unix.com/unix-dummies-questions-answers/5695-cron-how-tell-s-working.html

http://www.softpanorama.info/Utilities/cron.shtml

The last link above is the one that confirmed that these are indeed just shell scripts in this directory, and ignore lines that begin with the standard shell script comment character #. On a side note, apparently the version of cron that I'm running in ubuntu is called "Nixie cron".

Then I had to correct the timezone. I did this by doing:

sudo dpkg-reconfigure tzdata

Which launches a hilarious terminal server that offers bios-like choices for location that allowed me to pick "New York" and set the time to the correct time zone. I got this from the following link, which is very nice and also reiterates everything that my previous ntp references told me, but in a much prettier way:

https://help.ubuntu.com/community/UbuntuTime