Everyone has has problems from time to time where their computer's (or server's) time runs too slow or too fast. There is a very simple method to keep your PC 100% accurate, provided it has a fixed internet connection, or at least a daily connection (beyond that I cannot say how accurate this will keep it). For this we use the Network Time Protocol (a.k.a. NTP), and the ntpd daemon.
In my current situation, I have:
* 1 server with a constant connection to the internet
* 1 workstation (used daily for all personal work)
* 1 laptop, used "every other day"
Now all my PC's clocks drift off from time to time, sometimes a matter of a few seconds, other times several minutes, depending on when it was last synced, and of course which machine. Normally a few minutes difference in the clocks should not matter too much, however it can be a pain in the ass regarding mailservers etc.
The ideal situation would be that my my server would be constantly synced (100% accurate constantly), and that my other 2 computers would use this same server (mine) for syncing when in use. This would mean less strain for the "outside" (public) NTP servers, less network traffic (not that I'm worried about that little bit of info that gets sent from time to time back and forth), and more importantly, less headaches ;-)
What I wanted was simple, and it is easy to install. I will explain.
NTP is a small package, consisting (still) of 2 main
programs, ntpd and ntpdate (there are others, but I won't go into them).
ntpdate is used to sync your clock in one step, meaning your PC clock gets set in one go. This can
(if you let's say 30 minutes difference to the correct time) have drastic effects, and lots of warnings (possibly errors) for running servers/services. This is also the reason why this program (ntpdate) will be removed in the future.
ntpd on the other hand is a time daemon, which gradually synchronizes your clock, calculates your computers "natural drift", and counteracts it, keeping your clock on track. This is of course the preferred method, and in future versions of ntp will become the only method.
To install ntp on Gentoo Linux :
$ emerge ntp
On other systems, install the RPM, deb, or download and compile the source from http://www.ntp.org/
This is the method I used to sync my server. Most ISP's (Internet Service Providers) provide their customers with such a server (refer to your ISP's website / helpdesk) which you can use, else you can use many public ones.
The main points to note are listen below:
logfile /var/log/ntpd.log
server ntp.your_ISPs_server.com
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
driftfile /var/lib/ntp/ntp.drift
restrict default nomodify nopeer
restrict 127.0.0.1
restrict 192.168.0.0 mask 255.255.255.0 nomodify nopeer notrap
restrict 10.0.0.0 mask 255.255.255.0 nomodify nopeer notrap
* logfile, although not necessary, if definitely handy to have when testing.
* server is used to define which servers you want to use to sync with. On your server (or PC is you only have one) you should specify one that is close to you (your ISP's public one possible), and preferably followed by another public one, like I used ("pool.ntp.org"). Make sure you have at least 4(!) servers selected. Because with 3 the ntp-daemon can detect that a timeserver became a falseticker, with 4 it can detect this and continue to function.
* driftfile is the file used to calculate your PC's drift, and how it should correct it gradually.
* restrict is used to define who can connect to your NTP server, and what permissions they have. You don't want other PC's in your network to accidentally sync yours, so we define that (in my case) 3 ranges of IP's (127.0.0.1, 192.168.0.*, and 10.0.0.*) that may connect and read, but not write.
I am not sure how all other distros run this with either their init.d or rc.d, but on Gentoo
/etc/init.d/ntpd start
Right, this will start the daemon. Now you simply have to wait ;-) It might take as long as 15 minutes to change to the correct time (if you started with a lot of drift), and it will not be connectible by other computers in your network until it does have the correct time. In your log file (if you specified to use one) you should get lines similar to:
10 Mar 15:16:30 ntpd[18474]: frequency initialized -11.458 PPM from /var/lib/ntp/ntp.drift
10 Mar 15:20:50 ntpd[18474]: synchronized to 194.109.22.18, stratum=2
10 Mar 15:20:50 ntpd[18474]: time reset -0.228187 s
10 Mar 15:20:50 ntpd[18474]: kernel time sync disabled 0041
10 Mar 15:26:14 ntpd[18474]: synchronized to 194.109.22.18, stratum=2
10 Mar 15:35:55 ntpd[18474]: kernel time sync enabled 0001
You don't need to be a rocket scientist to work this part out. Basically you do the same steps as above, except you use the IP or hostname (in your own network) of your server instead of the internet servers to sync to. Extra lines regarding restrict (other than 127.0.0.1) are not necessary, as you should configure all your PC's to use the one server.
logfile /var/log/ntpd.log
server my_server
driftfile /var/lib/ntp/ntp.drift
restrict default nomodify nopeer
restrict 127.0.0.1
If your client machines are Windows machines, look at http://nettime.sourceforge.net/ for a neat little graphical tool that remains docked near the clock. It can be easily configured to use your internal personal NTP server.
I have set this system up at home, where 3 PC's clocks are accurate (never needing changes), and at work with 6 clients and one other server connecting to the main "time server". Although it does take a while to synchronize itself, once it is running you can just forget about it, and hopefully never have to worry about it again. It works superbly.
Enjoy.