APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS














(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



Network Time Protocol

Tue Aug 10 21:59:53 2004



Referencing: /Blog/B953.html

Your computer's internal clock is unlikely to keep perfect time. If you need it to be more accurate, the network time protocol daemon (ntpd) is the tool for that.

Historically, we've had ntpd and ntpdate. The ntpdate was for just quickly finding out the current time and updating the system with that. Typically, you'd run it at boot or perhaps once or twice a day from cron. Many systems still have this; you just point it at an appropriate server:


ntpdate clock2.redhat.com
ntpdate time.apple.com
 

With modern ntpd, you could use -q for the same effect:

ntpd -q clock2.redhat.com
 

If you aren't always connected to the internet, or your desire for accuracy is fairly relaxed, running ntpdate once a day or so is probably enough to keep you happy and on time, but ntpd is the better choice.

The man page for ntpdate on my OS X says "After a suitable period of mourning, the ntpdate utility is to be retired from this distribution."

If your time keeping needs are more precise, you want to run ntpd all the time, and let it figure out how often it needs to adjust things. If you are being that concerned about accurate time, you'll want to carefully select your time server too, because arbitrarily picking a popular server as we did above could lead to inaccurate time just because of network delays. The "ntptrace" command tells you where things are:

# ntptrace time.apple.com
time0.apple.com: stratum 2, offset -0.100057, synch distance 0.03278
17.254.0.49: stratum 1, offset -0.100085, synch distance 0.00548, refid 'GPS'
# ntptrace clock2.redhat.com
clock2.redhat.com: stratum 1, offset -0.100989, synch distance 0.00041, refid 'CDMA'
 

Notice a difference there? The "time.apple.com" is a Stratum 2 server, that talks to a Stratum 1 server to get its own time. In general, Stratum 1 servers aren't publicly available, or at least require some prearrangement. That's not always true, but if you look around the web you'll see that you are asked not to use Stratum 1 servers unless you really need to.

For many of us, one time server is enough. But people really worried about time will select multiple servers, so that a glitch at one won't throw them off. You put these servers into /etc/ntp.conf - here's mine from my iBook:

server time.apple.com minpoll 12 maxpoll 17
 

That's my entire file, but there are many more possible configuration parameters. Checking http://www.time.gov/timezone.cgi?Eastern/d/-5, I found my system was close enough that I couldn't tell any difference. That time isn't necessarily critically accurate either, but if your time is far off from that, something is probably wrong

On this machine, ntpd is started pointing at a "drift" file:

ntpd -f /var/run/ntp.drift -p /var/run/ntpd.pid
 

so that it knows how much this clock tended to drift from reality.when it last ran. Ordinarily, ntpd will adjust your time very slowly toward "reality" - this is so your programs don't suddenly gain or lose many seconds. You can tell it to just set the correct time instantly, and that is often done at first boot before settling down to small adjustments.





If ntpd is running on one server, you can point other network machines at it instead of at a public time server. This is more apt to keep everyone very much on the same page and of course cuts down on internet traffic too.

Unless you add restrictions to your /etc/ntp.conf file, or block ntpd at your firewall, ntpd will happily provide time information to anyone who asks - probably want to restrict this unless you intended to set up a public time server. By the way, "man ntp.conf" will tell you more about ntpd than "man ntpd" does.




Click here to add your comments





Wed Sep 2 01:39:07 2009: Subject: Additional NTP info   DB
http://www.dblevels.com
gravatar
A white paper on troubleshooting NTP and timing links in general may be found at http://www.dblevels.com . It is ad-free and contains references!



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar

cartoon


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server




pavatar.jpg
More:
       - Administration
       - Basics
       - Blog




Related Posts

Unix time, UTC, TAI and all that.

The Limits of Security



Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress