Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to keep your clock on track.
View unanswered posts
View posts from last 24 hours

Goto page 1, 2, 3  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Stormy Eyes
Veteran
Veteran


Joined: 09 Apr 2003
Posts: 1064
Location: Watching God spit-shine my boots.

PostPosted: Wed Jan 14, 2004 12:06 pm    Post subject: How to keep your clock on track. Reply with quote

I bet I'm not the only one who sometimes finds his computer's internal clock drifting, but Gentoo does have tools to solve this problem: ntp. NTP is the "Network Time Protocol", which allows hosts to connect to time servers and sync their clocks to that of the server.

The NTP tools can be obtained using portage from the net-misc/ collection:
Code:
emerge ntp

Once the NTP tools have been installed, you will find two scripts in /etc/init.d: ntpd and ntp-client. ntpd is intended for use in the default run-level, and can be set up in the following manner:
Code:
/etc/init.d/ntpd start
rc-update add ntpd default

/etc/init.d/ntp-client, on the other hand, requires a little bit of configuration first. To configure the NTP client, you must edit /etc/conf.d/ntp-client.
Code:
nano -w /etc/conf.d/ntp-client

You have to pick from this list the name of the time server closest to your location and edit this part of /etc/conf.d/ntp-client:
Code:
# Options to pass to the above command
# Most people should just uncomment this variable and
# change 'someserver' to a valid hostname which you
# can aquire from the URL's below
NTPCLIENT_OPTS="-b timex.cs.columbia.edu"

Since I live in Connecticut, I chose a server located in New York. Once you've set your time server, save the file and close the editor. Then run /etc/init.d/ntp-client start to reset your clock.
Back to top
View user's profile Send private message
agent_jdh
Veteran
Veteran


Joined: 08 Aug 2002
Posts: 1779
Location: Scotland

PostPosted: Wed Jan 14, 2004 12:38 pm    Post subject: Reply with quote

If you choose to go with ntpd (which is arguably the better solution, as it keeps your clock synched silently, i.e. no user intervention required), you need to do a bit more to get it working. You have to edit the file /etc/ntp.conf and add in what timeservers you want to use (I would select stratum 2 - secondary - servers at the foot of the link you provided). Mine looks like this -
Code:
server ntp.cis.strath.ac.uk
server ntp2a.mcc.ac.uk
server time-server.ndo.com

Once you've added it to the default runlevel, you can just start it with
Code:
/etc/init.d/ntpd start
to save you rebooting.
_________________
Jingle Jangle Jewellery
Back to top
View user's profile Send private message
nevynxxx
Veteran
Veteran


Joined: 12 Nov 2003
Posts: 1123
Location: Manchester - UK

PostPosted: Wed Jan 14, 2004 12:44 pm    Post subject: Reply with quote

Nice tip(s), now the next step, how would I set my router machine to be an ntp server for the local network? (not much point on small networks I know but on say a corporate network this could be useful)

-Anthony
_________________
My Public Key

Wanted: Instructor in the art of Bowyery
Back to top
View user's profile Send private message
Stormy Eyes
Veteran
Veteran


Joined: 09 Apr 2003
Posts: 1064
Location: Watching God spit-shine my boots.

PostPosted: Wed Jan 14, 2004 12:49 pm    Post subject: Reply with quote

agent_jdh wrote:
You have to edit the file /etc/ntp.conf and add in what timeservers you want to use (I would select stratum 2 - secondary - servers at the foot of the link you provided). Mine looks like this


Thank you. I had forgotten about /etc/ntp.conf as ntpd didn't gripe about needing a tweak to its config file, unlike ntp-client. If you don't mind, I'll edit my original post to include your tip after work.
Back to top
View user's profile Send private message
Stormy Eyes
Veteran
Veteran


Joined: 09 Apr 2003
Posts: 1064
Location: Watching God spit-shine my boots.

PostPosted: Wed Jan 14, 2004 12:51 pm    Post subject: Reply with quote

nevynxxx wrote:
Nice tip(s), now the next step, how would I set my router machine to be an ntp server for the local network? (not much point on small networks I know but on say a corporate network this could be useful)

-Anthony


The first thing I'd try is to configure the router as I outlined above, with agent_jdh's addition to /etc/ntp.conf, and then configure the ntpd on all the machines that talk to the router to use the router as a time server.

[edit: I'm a home Linux user who just runs a couple of X terminals off his desktop, so my suggestion could be wrong. You'll have to try it yourself. ]
Back to top
View user's profile Send private message
ILikePi
n00b
n00b


Joined: 29 Nov 2003
Posts: 22
Location: Rhode Island, USA

PostPosted: Wed Jan 14, 2004 1:08 pm    Post subject: Reply with quote

David Mills, who is one of the primary maintainers of the software, maintains a nice list of public NTP servers. Home users should try to limit themselves to servers on the "stratum 2" list.

I setup xntpd on a university department subnet a few years ago. It basically involved choosing the servers and configuring the daemons on the three machines. xntpd had some security features in it that allowed you to say things like "allow clock updates only from these addresses" or "allow clock queries from etc..." it also had some sort of key exchange type thing that went on between the 3 local servers. i'm not sure if the particular ntp daemon you all are referencing has that sort of thing though. also, can't remember for sure...but the hardware clock may need to be in GMT. but once it's configured and running, it's all hands-off.
_________________
Keyboard not found.
Press F1 to continue.
Back to top
View user's profile Send private message
Stormy Eyes
Veteran
Veteran


Joined: 09 Apr 2003
Posts: 1064
Location: Watching God spit-shine my boots.

PostPosted: Wed Jan 14, 2004 1:13 pm    Post subject: Reply with quote

ILikePi wrote:
David Mills, who is one of the primary maintainers of the software, maintains a nice list of public NTP servers. Home users should try to limit themselves to servers on the "stratum 2" list.


Thanks, but I linked to Mr. Mills' stratum 2 list in my original post. No point in being rude and tying up the the primary servers, right? >^..^< I'm using the NTP from http://www.ntp.org/, by the way.
Back to top
View user's profile Send private message
agent_jdh
Veteran
Veteran


Joined: 08 Aug 2002
Posts: 1779
Location: Scotland

PostPosted: Wed Jan 14, 2004 1:19 pm    Post subject: Reply with quote

nevynxxx wrote:
Nice tip(s), now the next step, how would I set my router machine to be an ntp server for the local network? (not much point on small networks I know but on say a corporate network this could be useful)

-Anthony


As Stormy Eyes says, you should be able to just set up ntpd on your router and then point your /etc/ntp.conf file to that (just use the router's IP address in the server line, e.g. server 192.168.1.1)

I've checked it by pointing my /etc/ntp.conf server setting to another (Debian) machine on my network (not the router, it doesn't have enough space to run ntpd as it boots off a floppy), and restarted the ntpd daemon on my Gentoo box, ntpd stopped and started with no arguments and there was nothing in /var/log/messages either. Whether or not it keeps time is another question....

EDIT - Actually I'm not sure about this .... I've just had lunch and come back, and now /var/log/messages has an entry from ntpd saying synchronisation lost. I'm not 100% sure on this, because looking back through the /var/log/messages file this happens a fair bit.

One thing I have noticed, I've added another option to /etc/ntp.conf
Code:
driftfile /var/lib/ntp/ntp.drift
which seems popular, but /var/log/messages shows "Un-parsable frequency in /var/lib/ntp/ntp.drift" when ntpd starts. /var/lib/ntp/ntp.drift is an empty file, but on my Debian box which also runs ntpd it contains a value. Anyone know how this file gets populated?

EDIT again - Ignore that last bit, the ntp.drift file gets automagically created after a period (presumably to measure my systems drift).
_________________
Jingle Jangle Jewellery


Last edited by agent_jdh on Wed Jan 14, 2004 9:42 pm; edited 2 times in total
Back to top
View user's profile Send private message
nevynxxx
Veteran
Veteran


Joined: 12 Nov 2003
Posts: 1123
Location: Manchester - UK

PostPosted: Wed Jan 14, 2004 1:33 pm    Post subject: Reply with quote

Thanks all, can't test if my box is being a server, but from what you said it should be. When I edited my /etc/ntp.conf it had a line

restrict <my routers external address> mask 255.255.255.0

I chancged it to my internal network so my conf now looks like;


Code:

restrict default noquery notrust nomodify
restrict 160.220.48.0 mask 255.255.255.0
fudge 127.127.1.0 stratum 3
eerver 127.127.1.0
driftfile /var/lib/ntp/ntp.drift
logfile /var/log/ntp.log
server ntp2a.mcc.ac.uk
server ntp.cis.strath.ac.uk
server time-server.ndo.com

that seem ok? (yes I did copy and past the server lines from a previous post and then rearrange them as I live in manchester...hehehe)
_________________
My Public Key

Wanted: Instructor in the art of Bowyery
Back to top
View user's profile Send private message
keschrich
n00b
n00b


Joined: 09 Apr 2002
Posts: 69
Location: Branford, CT

PostPosted: Wed Jan 14, 2004 1:59 pm    Post subject: Reply with quote

I've got my ntpd.conf all set up, and when I run '/etc/init.d/ntpd start' everything seems to work great. I have noticed one problem though: whenever I reboot my computer, ntpd.conf seems to be replaced with this:

Quote:

restrict default noquery notrust nomodify
restrict 127.0.0.1
restrict 192.168.1.0 mask 255.255.255.0
fudge 127.127.1.0 stratum 3
server 127.127.1.0
driftfile /var/lib/ntp/ntp.drift
logfile /var/log/ntp.log


which obviously does not suit my needs at all.. any idea why this would be happening?
Back to top
View user's profile Send private message
agent_jdh
Veteran
Veteran


Joined: 08 Aug 2002
Posts: 1779
Location: Scotland

PostPosted: Wed Jan 14, 2004 2:40 pm    Post subject: Reply with quote

keschrich wrote:
I've got my ntpd.conf all set up, and when I run '/etc/init.d/ntpd start' everything seems to work great. I have noticed one problem though: whenever I reboot my computer, ntpd.conf seems to be replaced with this:

Quote:

restrict default noquery notrust nomodify
restrict 127.0.0.1
restrict 192.168.1.0 mask 255.255.255.0
fudge 127.127.1.0 stratum 3
server 127.127.1.0
driftfile /var/lib/ntp/ntp.drift
logfile /var/log/ntp.log


which obviously does not suit my needs at all.. any idea why this would be happening?


I take it you mean /etc/ntp.conf and not ntpd.conf? Just a starter for 10...
_________________
Jingle Jangle Jewellery
Back to top
View user's profile Send private message
jetblack
Guru
Guru


Joined: 15 Jan 2003
Posts: 340
Location: Evanston, IL, USA

PostPosted: Wed Jan 14, 2004 2:50 pm    Post subject: Reply with quote

keschrich wrote:
I've got my ntpd.conf all set up, and when I run '/etc/init.d/ntpd start' everything seems to work great. I have noticed one problem though: whenever I reboot my computer, ntpd.conf seems to be replaced with this:

Quote:

restrict default noquery notrust nomodify
restrict 127.0.0.1
restrict 192.168.1.0 mask 255.255.255.0
fudge 127.127.1.0 stratum 3
server 127.127.1.0
driftfile /var/lib/ntp/ntp.drift
logfile /var/log/ntp.log


which obviously does not suit my needs at all.. any idea why this would be happening?


Are you using dhcp? I seem to recall reading somewhere that a DHCP server can override your /etc/ntp.conf settings.

This isn't exactly what I recall reading, but it's close enough...
Back to top
View user's profile Send private message
ILikePi
n00b
n00b


Joined: 29 Nov 2003
Posts: 22
Location: Rhode Island, USA

PostPosted: Wed Jan 14, 2004 10:53 pm    Post subject: Reply with quote

Stormy Eyes wrote:
Thanks, but I linked to Mr. Mills' stratum 2 list in my original post. No point in being rude and tying up the the primary servers, right? >^..^< I'm using the NTP from http://www.ntp.org/, by the way.


ermmm......woops :oops:
:D
_________________
Keyboard not found.
Press F1 to continue.
Back to top
View user's profile Send private message
NME
Apprentice
Apprentice


Joined: 18 Nov 2003
Posts: 168
Location: The Netherlands

PostPosted: Wed Jan 14, 2004 11:05 pm    Post subject: Reply with quote

nice howto, thanks a lot :)
_________________
f# that.
Back to top
View user's profile Send private message
k12linux
n00b
n00b


Joined: 17 Oct 2003
Posts: 18

PostPosted: Sat Jan 17, 2004 2:29 am    Post subject: Reply with quote

nevynxxx wrote:
Thanks all, can't test if my box is being a server, but from what you said it should be.


run: netstat -lu
and look for a line like: udp 0 0 *:ntp *:*
Back to top
View user's profile Send private message
k12linux
n00b
n00b


Joined: 17 Oct 2003
Posts: 18

PostPosted: Sat Jan 17, 2004 3:41 am    Post subject: Reply with quote

jetblack wrote:
keschrich wrote:
I've got my ntpd.conf all set up, and when I run '/etc/init.d/ntpd start' everything seems to work great. I have noticed one problem though: whenever I reboot my computer, ntpd.conf seems to be replaced


Are you using dhcp? I seem to recall reading somewhere that a DHCP server can override your /etc/ntp.conf settings.


Bingo. DHCP is the culprit. It replaces your ntp.conf file each time. I looked it over and there IS a fix. If you don't want this to happen, just edit /etc/conf.d/net and set
Code:
dhcpcd_eth0="-N"

(or dhcpcd_eth1="-N" if it's eth1 getting an address via DHCP)

Doing that will keep DHCP from replacing your ntp.conf. :D

OR.. you could always add the "option ntp-server" setting in your DHCP server's /etc/dhcp/dhcpd.conf and auto-config ntp on all your clients from now on.
Back to top
View user's profile Send private message
Cid
Apprentice
Apprentice


Joined: 19 Dec 2003
Posts: 155
Location: New York

PostPosted: Thu Mar 25, 2004 2:43 pm    Post subject: Reply with quote

i'm having a little trouble getting this to work...here's the error:

# /etc/init.d/ntp-client start
* Setting clock via the ntp client 'ntpdate'...
25 Mar 09:31:38 ntpdate[4695]: the NTP socket is in use, exiting
* Failed to set clock [ !! ]


any suggestions?
_________________
Spiral out. Keep going...
Back to top
View user's profile Send private message
k12linux
n00b
n00b


Joined: 17 Oct 2003
Posts: 18

PostPosted: Thu Mar 25, 2004 3:14 pm    Post subject: Reply with quote

Cid wrote:
i'm having a little trouble getting this to work...here's the error:

# /etc/init.d/ntp-client start
* Setting clock via the ntp client 'ntpdate'...
25 Mar 09:31:38 ntpdate[4695]: the NTP socket is in use, exiting
* Failed to set clock [ !! ]

any suggestions?


Stop ntpd first, start ntp-client, then you can start ntpd again. ntp-client just runst the ntpdate command to set your clock. It won't run if ntpd is running.

On boot, it's normally auto-run just before ntpd.
Back to top
View user's profile Send private message
neenee
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1786

PostPosted: Thu Mar 25, 2004 3:19 pm    Post subject: Reply with quote

hm.. what about a cronjob calling rdate?
Back to top
View user's profile Send private message
k12linux
n00b
n00b


Joined: 17 Oct 2003
Posts: 18

PostPosted: Thu Mar 25, 2004 5:44 pm    Post subject: Reply with quote

neenee wrote:
hm.. what about a cronjob calling rdate?


If you are only syncing to a single time source, then that'd probably suffice. Or even a cron job that runs ntpdate occasionaly (ntpdate doesn't act as a daemon.. justs sets the time and exits.) Once you want other systems to sync to your box's time, then you should look at ntp.

If you want to be as accurate as possible, use ntpd on 3+ systems and have each get it's time from 3-5 strata 2 timeservers. (Don't do strata one unless you have litterally thousands of systems which will get their time from your ntp servers.) Configure your 3 (or more) ntp servers to talk to each other as peers.

ntp will calculate accuracy between the strata2 servers and compare time to your other ntp servers. When all is said and done, your time should be within a couple thousands of a second of "official" UTC time.
Back to top
View user's profile Send private message
neenee
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1786

PostPosted: Thu Mar 25, 2004 7:07 pm    Post subject: Reply with quote

okidoki. i just thought ntp for a normal
user system to be a bit overkill :wink:
Back to top
View user's profile Send private message
k12linux
n00b
n00b


Joined: 17 Oct 2003
Posts: 18

PostPosted: Thu Mar 25, 2004 7:26 pm    Post subject: Reply with quote

Yeah, really it is overkill if all you want to do is keep your time from being way off "real" time. I run NTP on my home network because I want several systems to sync to it. If I only had a single (or a couple) PCs I'd probably just use ntpdate by itself.

And of course at work I use it because there it actually matters that I have a local accurate time source.
Back to top
View user's profile Send private message
szaman
n00b
n00b


Joined: 20 Jan 2004
Posts: 71
Location: Poland, Siemianowice

PostPosted: Thu Mar 25, 2004 9:21 pm    Post subject: Reply with quote

is it possible to sync wind*ws systems to my ntp servers?
Back to top
View user's profile Send private message
BlauwVoet
n00b
n00b


Joined: 11 Feb 2004
Posts: 30

PostPosted: Thu Mar 25, 2004 9:53 pm    Post subject: Reply with quote

ntp seemed to complicated and too big (small HD) for me.
besides, I'm not interested knowing the time with a precision of nanoseconds.
something small, simple and fast is what I need

my linux-clock seems to work fine, so as long as my pc is switched on, everything runs smoothly.
my hardware-clock on the contrary is waaaaaaaaaaaay off; so every time I boot I have to adjust the time. (afraid the MoBo battery might fail pretty soon?) So I wanted to have something to do that automatically.

the ntp-ebuild is quite big, has several dependencies, seems to be quite complicated and to heavy for this simple task. So I tried clockspeed, only 25 kB.

Code:
# emerge clockspeed


This installs some tiny commands, such as
sntpclock : takes the IP-number of a NTP-host as parameter, and prints out the time in TAI-format
clockadd : reads a TAI-time adjustment from Stdin, and adds it to the local clock (no matter the time difference)

IP-numbers of NTP-hosts can be found on http://www.eecis.udel.edu/~mills/ntp/servers.html. In my example I will use ntp.telenet.be with IP 195.130.132.18 as this is an ntp-host close to me; this corrects the time (as root):

Code:
# sntpclock 195.130.132.18 | clockadd


To have the time adjusted each time I boot up, I've added this line to /etc/conf.d/local.start

Code:
# echo " --> syncing time with ntp.telenet.be" >>/etc/conf.d/local.start
# echo "sntpclock 195.130.132.18 | clockadd" >> /etc/conf.d/local.start


Now I have allways the right time :D

******
you could also add this to cron

******
the clockspeed command in the same ebuild resets the local clock each 3 seconds, it reads the real time measurements from /var/lib/clockspeed/adjust in TAI-format.
I haven't figured out (yet) how it works (because I'm quite satisfied with sntpclock/clockadd); feel free to experiment
Back to top
View user's profile Send private message
Andersson
Guru
Guru


Joined: 12 Jul 2003
Posts: 525
Location: Göteborg, Sweden

PostPosted: Thu Mar 25, 2004 10:04 pm    Post subject: Reply with quote

neenee wrote:
hm.. what about a cronjob calling rdate?

From what I've heard, the problem with this solution is that if your computer is running a little fast, rdate/ntpdate will set the new time a few seconds earlier. This may confuse some programs (you know, time travel and stuff ;)). Ntpd will instead slow the clock down a little until it's correct.
szaman wrote:
is it possible to sync wind*ws systems to my ntp servers?

Yes, as long as your computer is a correctly configured ntp server. There are programs for this in windows. I used one called... netsync, timesync, datesync or similar.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum