join
donate
Network Time Foundation:
NTP
•
Ntimed
•
PTPd
•
Linux PTP
•
RADclock
•
GTSAPI
•
More
%DISCUSS% %SECTION0% Getting Started With NTP %CONTENTS{topic="GettingStarted"}% <!-- %IF{ _%URLPARAM{"skin"}% ne _print }% __Notes:__ 1. If you are _really_ impatient, try the [[QuickStartPage][NTP Quick Start Page]]. It's even shorter than this one. 1. If you wish to print %TOPIC% please click the <img border=0 src="/pub/TWiki/GnuSkin/print.png" align=middle width=16 height=16 alt="#"> [[%SCRIPTURL%/view/%WEB%/%TOPIC%?skin=print][Printable]] link in the link-bar for a _printer friendly_ version of this topic. %ENDIF% %IF{ _%URLPARAM{"skin"}% eq _print }% __Note:__ If you are _really_ impatient, there is an even shorter quick start guide at http://www.eecis.udel.edu/~mills/ntp/html/quick.html. The current contents of quick.html are included in the [[QuickStartPage][NTP Quick Start Page]]. %ENDIF% --> __Note:__ If you are _really_ impatient, the [[QuickStartPage][NTP Quick Start Page]] (or http://www.eecis.udel.edu/~mills/ntp/html/quick.html) is an even shorter quick start. %SECTION1{name=WHAT}% What NTP is and what it does The internal clocks of most computers are rather inaccurate. You can correct the clock by hand on occasion, or you can use NTP to regulate your clock to be much more accurate. NTP stands for "Network Time Protocol". It is a way for computers to exchange information about the exact time, so that they can regulate their clocks. NTP also stands for a particular daemon (continuously running program) that uses the Network Time Protocol to determine the correct time and regulate your computer's clock to show the correct time. The NTP daemon software can be obtained from http://www.ntp.org. It runs on Unix and Windows/NT systems. (There are other programs that use the Network Time Protocol for setting your computer's clock as well -- see %REF{type="Section" name="RESOURCES"}% for information.) NTP can regulate your clock using a "reference clock", a device that obtains accurate time information from an outside source and delivers it to your computer. More commonly, NTP can regulate your clock by obtaining time information from another NTP daemon. NTP can also provide time information to other NTP daemons. Once you install the NTP software and start it running, you must provide it with a source of time information, either a reference clock, or with the addresses of other NTP daemons. This document describes the critical steps of installing the software and configuring NTP to obtain time from other NTP daemons. Information about using a reference clock with NTP is at http://www.eecis.udel.edu/~mills/ntp/html/refclock.html. %SECTION1{name=PROGRAMS}% The names of the programs: Is it =ntpd= or =xntpd=? Some operating systems supply the NTP programs (=ntpd=, =ntpdate=, =ntpdc=, =ntpdq=, etc.) with filenames starting with "x" (=xntpd=, =xntpdate=, etc.). Others use filenames without the "x". This document uses the names without the "x". Try to run the program using the name without the "x" first. If you receive a "command not found" error, try the name with an "x". The "x" versions of the programs are from version 3 of NTP. They are old, but some OS vendors still distribute these versions of NTP. The versions without the "x" are from version 4. The commands and options used in this document should work for either version. %SECTION1{name=SERVERS}% Pick your servers Find some public servers that you can sync with. Use either just one, or at least four. The logic is complex, but if you want to read more about it, see [[https://support.ntp.org/bin/view/Support/SelectingOffsiteNTPServers#Section_5.3.3.]]. [[http://support.ntp.org/Servers/][Here is a list of public NTP servers]]. These sites are kind enough to perform this service for you, you should follow any guidelines they request (asking permission first, donations, thank-you notes, whatever.) Let's suppose you've picked =clock.example.org=, =timekeeper.sample.com=, =ntp1.example.co.uk=, and =tick.anotherexample.net=. Those aren't real sites, but I'll use them as examples in the rest of this document. %SECTION1{name=MANUAL}% "Manually" set the clock correctly just once HMS: This section is best for xntp (V3). =ntpdate= is deprecated in ntp4, see StartingNTP for more information. Let's "manually" set the clock to the correct time just to start things off. When ntpd is running and finds your clock is wrong, it makes tiny little changes until the clock is right. This way applications don't get confused. However, on reboot, the clock may have lost a lot of time and since no applications are running yet, we can make a big timeleap to correct the clock without risk of confusing them. To do this, we use a different utility called =ntpdate=. It can't run at the same time as ntpd. We even give it the "-b" option so that it knows to leap forward or backwards in time to set the clock correctly. Here's the command that does this: <verbatim> ntpdate -b clock.example.org timekeeper.sample.com ntp1.example.co.uk tick.anotherexample.net </verbatim> (NOTE: Substitute the four NTP servers that you'd like to sync with. Those aren't real.) Try this once from the command line (as "root") to make sure you're got it right. <verbatim> # ntpdate -b clock.example.org timekeeper.sample.com ntp1.example.co.uk tick.anotherexample.net 5 Jun 08:50:18 ntpdate[23777]: step time server 10.10.10.10 offset -111.106949 sec </verbatim> This means that your clock was off by -111.106949 seconds, but now it's been brought up to date. The good news is that for an instant you were in sync. The bad news is that by the time you read this, your clock has drifted. Darn computers! %SECTION1{name=BOOT}% Set the clock correctly on every boot up On reboot, you want to tell the system to sync up quickly. While your machine was down the CPU gets bored and plays with the clock. Haven't you ever been in a clock store waiting for your mother to make her purchase and started setting the clocks to funny times? It's like that, only your mother has nothing to do with this (I'm sure she's a very nice person, you just don't appreciate her enough). Let's configure your system to run this command on boot up. Here's how to do this on various operating systems: | *Debian* | This is done automatically if the =ntpdate= package has been installed and configured. | *<nop>FreeBSD* | Simply add this line to the end of =/etc/rc.conf= (if not running ntpd): <verbatim> ntpdate_enable="YES" </verbatim> (If you are running ntpd, =-g= option specified below means we don't need to run =ntpdate=, and do NOT add the line above.) | *Red Hat* | (Release 8.0) This is done automatically if the =ntp= package has been installed and configured. | *Solaris 9* | This is done automatically if a properly configured =/etc/inet/ntp.conf= exists. | *End of OS-specific items* | (people can volunteer the easiest way to do this on their favorite OS) %SECTION1{name=KEEP}% Keep the clock in sync permanently and continuously. Having your clock set properly every time you boot is nice, if you reboot constantly. Of course, you could put that command in =cron= but we have a solution that is so much better you'll thank me in the morning. We'll run =ntpd= which will constantly keep your clock correct by making micro-adjustments all day long. Heck, =ntpd= is so smart that if you lose contact with all your NTP servers it will remember how bad your clock was and keep making adjustments based on past bad performance. Pretty cool, eh? The NTP documentation has volumes about the various features and entire books can be written about the theory of operation of NTP. It's really quite amazing how the system works so precisely, so accurately, does the right thing through outages, detects and avoids misconfigured servers, conserves bandwidth, and as Jim Trocki once said, "fixes problems that you don't yet realize you have". However, you don't care about that, you just want a simple configuration that works. Here's one. =ntpd= 's configuration file is different on different systems. | *Debian*, *FreeBSD 4.x*, *Red Hat* | =/etc/ntp.conf= | *Solaris 9* | =/etc/inet/ntp.conf= | *End of OS-specific items* | Put these 3 lines in your configuration file: <verbatim> driftfile /etc/ntp.drift server clock.example.org iburst server timekeeper.sample.com iburst server ntp1.example.co.uk iburst server tick.anotherexample.net iburst </verbatim> Now start =ntpd=: | *Debian* | =ntpd= is automatically started after package installation or reconfiguration. %BR% =ntpd= may be started manually with =/etc/init.d/ntp start= | *<nop>FreeBSD 4.x* | =ntpd= is started automatically by adding the =xntpd_enable= and =xntpd_flags= described below. | *Red Hat* | (Release 8.0) =/sbin/service ntpd start= | *Solaris 9* | =/etc/rc2.d/S74xntpd start= | *End of OS-specific items* | It will now sync with the 'servers' in =/etc/ntp.conf=. Once an hour it will record a little information in =/etc/ntp.drift=. (=/etc/ntp.drift= contains what it needs to know if it loses contact with all your servers and needs to "go it alone"). Of course, you'll want to make sure that this command is run on bootup, after =ntpdate= is run (they can't run at the same time). Here's how to do that on various operating systems: | *Debian* | This is done automatically if one of the =ntp= packages has been installed and configured. | *<nop>FreeBSD 4.x* | Simply add these lines to the end of =/etc/rc.conf=: <verbatim> xntpd_enable="YES" xntpd_flags="-p /var/run/ntpd.pid -g -N high" </verbatim> | *Red Hat* | (Release 8.0) This is done automatically if the =ntp= package has been installed and configured. | *Solaris 9* | This is done automatically if a properly configured =/etc/inet/ntp.conf= exists. | *End of OS-specific items* | %SECTION1{name=STRATUM}% What about stratum 1, 2, 3 and all that? You don't need to specify that in the configuration file. If you list a mixture of stratum 1s, 2s, and 3s ntpd will do the right thing. Your stratum is determined dynamically based on what you've synced to. You don't need to worry about this. However, if you want to know more, there is info in the documentation. %SECTION1{name=CHECK}% Check your work. =ntpdc= is a command that lets you talk to your ntpd (just like =lp= has =lpc=, =ntpd= has =ntpdc=). It has a zillion features, but the one you really need to know is: <verbatim> ntpdc -c peers </verbatim> Here's a sample run: <verbatim> > ntpdc -c peers remote local st poll reach delay offset disp ======================================================================= =clock.example.o 5.0.0.0 16 64 0 0.00000 0.000000 0.00000 =timekeeper.samp 5.0.0.0 16 64 0 0.00000 0.000000 0.00000 =ntp1.example.co 5.0.0.0 16 64 0 0.00000 0.000000 0.00000 =tick.anotherexa 5.0.0.0 16 64 0 0.00000 0.000000 0.00000 </verbatim> Output like that (all zeros) means that we haven't synced with those two servers yet. When things get synced, the numbers will fill out like this: <verbatim> > ntpdc -c peers remote local st poll reach delay offset disp ======================================================================= *clock.example.o 64.46.24.66 3 64 377 0.00018 0.000329 0.00255 =timekeeper.samp 61.26.45.88 3 64 377 0.00017 0.002122 0.00342 =ntp1.example.co 10.0.1.210 2 1024 377 0.03294 -0.023926 0.12181 =tick.anotherexa 10.0.1.210 2 1024 377 0.04395 0.001855 0.12372 </verbatim> st -- the stratum of that server (calculated automatically) <BR> poll -- how often you poll that site (backs off dynamically) =ntpdc= can sh ow the status of other machines if you have the proper access set up. Just list the hostname on the command line: Let's see how the server at ntp-2.cso.uiuc.edu is doing: <verbatim> > ntpdc -c peers ntp-2.cso.uiuc.edu remote local st poll reach delay offset disp ======================================================================= +ntp-1.gw.uiuc.e 0.0.0.0 2 1024 172 0.00627 -0.000044 0.00761 +tick.usno.navy. 0.0.0.0 1 1024 373 0.09023 -0.023207 0.15714 *truechimer.cso. 0.0.0.0 1 1024 377 0.00401 -0.000054 0.00006 +ntp-0.gw.uiuc.e 0.0.0.0 2 512 332 0.01059 0.001216 0.00497 </verbatim> %SECTION1{name=NETWORK}% Running NTP on many machines in a network. If you have a lot of machines that need to be kept in sync, it is rude to point them all at public NTP servers. It's also a waste of your internet bandwidth. A much better solution is to set up either one or at least four NTP servers on your network that point to public NTP servers, then point all your other machines at these NTP servers. This greatly reduces the amount of load you put on the public NTP servers. At my company, we have four NTP servers: =ntp1.mycompany.com=, =ntp2.mycompany.com=, =ntp3.mycompany.com=, and =ntp4.mycompany.com=. Those are actually aliases ("CNAME" in DNS) that point to the four machines that I want everyone to use for NTP service. We do another trick that makes the aliases point to different hosts outside our firewall. That way the same configuration file works if a machine is connected inside or outside our firewall. These four NTP servers need to have a custom configuration, that includes each other: <verbatim> driftfile /etc/ntp.drift # public NTP servers we sync to: (use these 2 lines ONLY on ntp1 and ntp2!) driftfile /etc/ntp.drift server clock.example.org iburst server timekeeper.sample.com iburst server ntp1.example.co.uk iburst server tick.anotherexample.net iburst # Use these lines on all machines in mycompany.com: peer ntp1.mycompany.com peer ntp2.mycompany.com peer ntp3.mycompany.com peer ntp4.mycompany.com </verbatim> I find that it is easier to have the exact same file on both of these servers. That means that each of them will try to sync with themselves. Luckily, this is ok. NTP will realize that its talking to itself and do the right thing (ignore itself). All the other hosts have this =ntp.conf=: <verbatim> driftfile /etc/ntp.drift # Use these lines on all machines in mycompany.com: server ntp1.mycompany.com iburst server ntp2.mycompany.com iburst server ntp3.mycompany.com iburst server ntp4.mycompany.com iburst </verbatim> %SECTION1{name=RESOURCES}% Further resources * The NTP Public Support Project: http://support.ntp.org * The web page documenting the NTP software: http://www.eecis.udel.edu/~mills/ntp/html/index.html * The NTP FAQ: http://www.ntp.org/ntpfaq/NTP-a-faq.htm * An even shorter quickstart guide: http://www.eecis.udel.edu/~mills/ntp/html/quick.html * The (x)ntpd manual page that comes with your software distribution. -- %MAINWEB%.TomLimoncelli - 05 Jun 2003 %BR% -- %MAINWEB%.BradKnowles - 28 Aug 2003 %BR% -- %MAINWEB%.HarlanStenn - 04 Sep 2003 %BR% -- %MAINWEB%.DaleWorley - 09 Oct 2003 %BR% -- %MAINWEB%.BradKnowles - 30 Sep 2005
WebForm
NtpVersion
NtpFourOne
OperatingSystem
OsMacOS
OsVersion
10.3.9
This topic: Support
>
GettingStarted
Topic revision: r26 - 2007-12-21 - 16:07:02 -
SteveKostecke
Copyright &© 1999-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding the site?
Send feedback