In this article, we will discuss how to install and configure Chrony, an alternative NTP client and server for Unix-like systems. Chrony can synchronize the system clock faster with better time accuracy, and it can be especially useful for systems that are offline all the time. Chrony is free, open source and supports GNU / Linux and BSD flavors such as FreeBSD, NetBSD, macOS, and Solaris.
Chrony is available by default in the repositories for most Linux distributions. If you are on Arch Linux, run the following command:
$ sudo pacman -S chrony
$ sudo apt-get install chrony
$ sudo dnf install chrony
After installation, start the daemon chronyd.serviceif it is not already running:
$ sudo systemctl start chronyd.service
Configure it to start automatically on every reboot using the command:
$ sudo systemctl enable chronyd.service
To check if the Chronyd.service service is running, run:
$ sudo systemctl status chronyd.service
If everything is ok, you will see the output as shown below.
● chrony.service - chrony, an NTP client/server Loaded: loaded (/lib/systemd/system/chrony.service; enabled; vendor preset: ena Active: active (running) since Wed 2018-10-17 10:34:53 UTC; 3min 15s ago Docs: man:chronyd(8) man:chronyc(1) man:chrony.conf(5) Main PID: 2482 (chronyd) Tasks: 1 (limit: 2320) CGroup: /system.slice/chrony.service └─2482 /usr/sbin/chronyd Oct 17 10:34:53 ubuntuserver systemd: Starting chrony, an NTP client/server... Oct 17 10:34:53 ubuntuserver chronyd: chronyd version 3.2 starting (+CMDMON Oct 17 10:34:53 ubuntuserver chronyd: Initial frequency -268.088 ppm Oct 17 10:34:53 ubuntuserver systemd: Started chrony, an NTP client/server. Oct 17 10:35:03 ubuntuserver chronyd: Selected source 126.96.36.199 Oct 17 10:35:03 ubuntuserver chronyd: Source 188.8.131.52 replaced with 2403 Oct 17 10:35:03 ubuntuserver chronyd: Selected source 184.108.40.206 Oct 17 10:35:06 ubuntuserver chronyd: Selected source 220.127.116.11
As you can see, the Chrony service is up and running!
NTP clients need to know which NTP servers it needs to contact to get the current time. We can specify NTP servers in the directive server or pool in the NTP config file. Usually the default config file is: /etc/chrony/chrony.conf or /etc/chrony.conf depending on the version of the Linux distribution. To improve reliability, it is recommended to specify at least three servers.
The following lines are just an example taken from Ubuntu 18.04 LTS server.
[...] # About using servers from the NTP Pool Project in general see (LP: #104525). # Approved by Ubuntu Technical Board on 2011-02-08. # See http://www.pool.ntp.org/join.html for more information. pool ntp.ubuntu.com iburst maxsources 4 pool 0.ubuntu.pool.ntp.org iburst maxsources 1 pool 1.ubuntu.pool.ntp.org iburst maxsources 1 pool 2.ubuntu.pool.ntp.org iburst maxsources 2 [...]
As you can see from the above, NTP Pool Project was set as the default time server. For those wondering, the NTP pool project is a cluster of temporary servers that provides NTP service to tens of millions of clients around the world. This is the default time server for Ubuntu and most other major Linux distributions.
- parameter iburst used to speed up initial synchronization.
- to maxsources the maximum number of NTP sources applies.
Make sure the NTP servers you choose are well synchronized, stable, and close to your location to improve time accuracy with NTP sources.
Controlling Chronyd from the command line
Chrony has a command line utility named chronyc to control and monitor the daemon chrony (chronyd).
To check sync chrony, we can use the command tracking, as shown below.
$ chronyc tracking Reference ID : 6A0ABAC8 (t1.time.sg3.yahoo.com) Stratum : 3 Ref time (UTC) : Wed Oct 17 11:48:51 2018 System time : 0.000984587 seconds slow of NTP time Last offset : -0.000912981 seconds RMS offset : 0.007983995 seconds Frequency : 23.704 ppm slow Residual freq : +0.006 ppm Skew : 1.734 ppm Root delay : 0.089718960 seconds Root dispersion : 0.008760406 seconds Update interval : 515.1 seconds Leap status : Normal
We can check the current time sources used with the chrony command:
$ chronyc sources 210 Number of sources = 8 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^- chilipepper.canonical.com 2 10 377 296 +102ms[ +104ms] +/- 279ms ^- golem.canonical.com 2 10 377 302 +105ms[ +107ms] +/- 290ms ^+ pugot.canonical.com 2 10 377 297 +36ms[ +38ms] +/- 238ms ^- alphyn.canonical.com 2 10 377 279 -43ms[ -42ms] +/- 238ms ^- dadns.cdnetworks.co.kr 2 10 377 1070 +40ms[ +42ms] +/- 314ms ^* t1.time.sg3.yahoo.com 2 10 377 169 -13ms[ -11ms] +/- 80ms ^+ sin1.m-d.net 2 10 275 567 -9633us[-7826us] +/- 115ms ^- ns2.pulsation.fr 2 10 377 311 -75ms[ -73ms] +/- 250ms
The Chronyc utility can find statistics for each source, such as drift rate and displacement estimation process, using the command sourcestats…
$ chronyc sourcestats 210 Number of sources = 8 Name/IP Address NP NR Span Frequency Freq Skew Offset Std Dev ============================================================================== chilipepper.canonical.com 32 16 89m +6.293 14.345 +30ms 24ms golem.canonical.com 32 17 89m +0.312 18.887 +20ms 33ms pugot.canonical.com 32 18 89m +0.281 11.237 +3307us 23ms alphyn.canonical.com 31 20 88m -4.087 8.910 -58ms 17ms dadns.cdnetworks.co.kr 29 16 76m -1.094 9.895 -83ms 14ms t1.time.sg3.yahoo.com 32 16 91m +0.153 1.952 +2835us 4044us sin1.m-d.net 29 13 83m +0.049 6.060 -8466us 9940us ns2.pulsation.fr 32 17 88m +0.784 9.834 -62ms 22ms
If your system is not connected to the Internet, you need to notify Chrony that the system is not connected to the Internet. To do this, run:
$ sudo chronyc offline [sudo] password for sk: 200 OK
To check the status of NTP sources, simply run:
$ chronyc activity 200 OK 0 sources online 8 sources offline 0 sources doing burst (return to online) 0 sources doing burst (return to offline) 0 sources with unknown address
As you can see, all my NTP sources are currently unavailable.
Once you are connected to the Internet, simply tell Chrony that your system is back online using the command:
$ sudo chronyc online 200 OK
To view the status of the NTP source (s), run:
$ chronyc activity 200 OK 8 sources online 0 sources offline 0 sources doing burst (return to online) 0 sources doing burst (return to offline) 0 sources with unknown address
For a more detailed explanation of all parameters and parameters, see the man pages.
$ man chronyc
$ man chronyd
And that’s all for now. We hope this was helpful. In subsequent tutorials, we will see how to set up a local NTP server using Chrony and configure clients to use it for time synchronization.
Stay up to date!