Setting up NTP (Linux, Mac OS X, Win2K)
Submitted by charlie.collins on Sun, 08/17/2003 - 21:08
Tagged:
I finally decided to setup NTP (Network Time Protocol) the other day after years of simply adjusting system clocks and not getting around to using something to automatically keep them synchronized(Im rather slow, pun intended).
So I get the NTP rpms from rpmfind (I use rpms because I like to do that, they are easy to install and easy to update and keep track of versions and so on, so long as you dont need to get really specific, if you prefer just get the source from ntp.org and compile ).
I then look for and find a plethora of howto's on NTP that are far more complicated than I need. I keep looking and finally start to figure it out after a mixture of google and man page research.
Basically you setup a local NTP server that syncs itself with remote NTP servers (so yes, its technically also a client). The local server syncs with servers that are really really really damn accurate (these are called Stratum 1 servers, these usually involve some Cesium laying around and decaying or something like that) and servers that are only really really accurate (these are called Stratum 2 servers). Pick some servers that are geographically sensible and allow you access them from this list.
In order to tell your LOCAL NTP server what remote servers it should sync with you setup a config file, etc/ntp.conf. The ntp.conf file not only sets up the remote servers that your local server will use for sync but also defines some local server settings and sets up some security guidelines (who can query your server and so on). My ntp.conf looks like this:
# defaults # ###restrict default ignore restrict 127.0.0.1 restrict 10.0.0.0 mask 255.0.0.0 notrust nomodify notrap # servers # # terrapin.csc.ncsu.edu 152.1.58.124 - stratum 1 open # lerc-dns.lerc.nasa.gov (128.156.1.43) - stratum 1 open # now.okstate.edu (139.78.100.163) stratum 1 open # rolex.usg.edu - stratum 2 open send note (timekeeper@usg.edu) # timex.usg.edu - stratum 2 open send note (timekeeper@usg.edu) server rolex.usg.edu # stratum 2 server timex.usg.edu # stratum 2 # restrict servers # restrict 198.72.72.10 mask 255.255.255.255 nomodify notrap noquery restrict 131.144.4.9 mask 255.255.255.255 nomodify notrap noquery # local clock # server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10 # drift file # driftfile /etc/ntp/drift broadcastdelay 0.008As you can see I am using a couple of University of Georgia servers (yeah I know, lets hear the jokes, dawgs and math, maybe I will pick some Ga Tech servers on second thought). Anyway, you probably dont want to use these servers yourself because the may not make geographic sense (duh) and they are NOT totally public, so check the list. Once you have a conf file setup you of course start ntp. With Red Hat the init script is installed with the rpm and its located at /etc/init.d. SO start it with /etc/init.d/ntpd start. Then you use another program thats included to query the ntp server and see how its doing, ntpq. Run "ntpq -p" to see if things actually worked. Ntpq shows that offset of times between client and server, and what the adjustment was, and so on. You can also of course check the system time to see if its right on, I mean RIGHT on. Get some Cesium and then . . . . nevermind, check the USNO Master Time and compare. So thats the server. Then other machines can fairly easily be clients. In my case I used Linux clients, Mac OS X clients and even a few Windows 2000 clients. Guess which one was the hardest to setup? In linux you just run "ntpdate -s serverip". And in every case I used it (about 12 machines( it worked flawlessly. It logs in messages that its changing things and the clocks are all spot on. Of course you then setup a small cron script to run every hour or so and re-check. In Mac OS X you go to System Preferences --> Date & Time and then you click the "Network Time" tab, then enter the IP of the server and bam, its done, and it works. In Windows you go to the control panel and click the network time icon, oh wait, thats what you SHOULD DO, in reality that doesnt exist. Go to command prompt and use:
NET TIME /SetSNTP:192.168.200.10 NET TIME /QuerySNTP w32tm -v -once -period 65532NET TIME obviously starts the time service (which I could not get to start from control panel --> services, I tried). The "w32tm" program is really for debugging time but can be used to tell Windows 2000 to sync (doesnt make sense to me either). For more on the windows matters see this MS knowledge base article Once I did this Windows did sync the time, it didnt seem to log anything in event viewer though, and it also reset the time zone to Pacific (which none of the other OSes did). I reset the time zone myself and re-synched while watching the server log, and it all worked. The bottom line is that now all my machines have VERY accurate times and they are all in synch with each other and all the clocks are re-adjusted automatically as they drift. NTP is good, you need to use it (dont wait years like I did).







Comments
Re: Setting up NTP (Linux, Mac OS X, Win2K)
forgot this in my last post
Better way of passing on the time than ntpdate
Re: Better way of passing on the time than ntpdate
RE: Setting up NTP (Linux, Mac OS X, Win2K)
RE: Better way of passing on the time than ntpdate