$ date

Mon Jun 06 23:44:18 UTC 2016


NTP

The Network Time Protocol. Most likely, your device uses NTP to sync its time with some big servers to get accurate time.

Any network connected device, at least.

If it wouldn't have accurate time, even completely wrong time, there would be quite a lot of issues, like not yet valid certificates and such. Nobody likes issues.

That's NTP in a nutshell. Now be brave, and say "Thank you for saving the internet, NTP".

There are a couple clients (and servers) for Linux, *BSD and other UNIX likes.

This post should be a little help choosing.

ntpdate

Ah, yes! Not even a daemon, just a single-shot time magician.

It is in the Network Time Protocol program suite.

usage: ntpdate [-46bBdqsuv] [-a key#] [-e delay] [-k file] [-p samples] [-o version#] [-t timeo] server ...

The TL;DR is: ntpdate -u your.fancy.ntp more.servers.here.

Does the job, but since it isn't a daemon, it doesn't keep the time up to date on it's own.

ntpd

Another program from the Network Time Protocol program suite. This time, the reference daemon.

Even though it is mainly used for time servers themselves, when the world is due to explode at 8pm and you want to make sure you don't forget to put your 3D glasses on, you can use it as a client too.

Slamming something like the below in the /etc/ntp.conf should work, but you should really really really read the rest of the post before you decide to use it. Like, really really.

# NTPd config.
# Taken from http://blog.i0i0.me/

# Restrict daemon connections to localhost.
restrict default nomodify nopeer noquery
restrict 127.0.0.1 mask 255.0.0.0

# Use self as fallback, in case network isn't there yet.
server 127.127.1.0
fudge  127.127.1.0 stratum 10

# Servers to sync up to: In this case, from ntp.org pool.
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org

chrony

My personal favourite. A client/server daemon, like ntpd, but easier to configure and a bit better for more rough situations, unlike ntpd which definitly wants machines which run 24/7 and have a permanent network connection.

Configuring it pretty easy, but to really use it, you should read the docs over at chrony.tuxfamily.org.

Simple client (Put it in /etc/chrony/chrony.conf):

# Chrony config

# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift

# In first three updates step the system clock instead of slew
# if the adjustment is larger than 1 second.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Use the ntp.org pool with ibursts.
pool pool.ntp.org iburst

For a server, simply use the above, but add an allow directive. More in the documentation.

Verdict

ntpdate is pretty good for one shot type of scenarios or where you sync it via cron or other custom things. I think busybox even ships with it?

ntpd is what I would use for a NTP server on a dedicated server, hosted in a datacenter. As an NTP client? Eeeeeh.

chrony is what I use for local NTP servers and clients in pretty much any case: It is easy to configure and just works.

$ cd ..