In this tutorial, we will be discussing how to install and configure Chrony, an alternative NTP client and server for Unix-like systems. Chrony can synchronise the system clock faster with better time accuracy and it can be particularly useful for the systems which are not online all the time. Chrony is free, open source and supports GNU/Linux and BSD variants such as FreeBSD, NetBSD, macOS, and Solaris.
Chrony is available in the default repositories of most Linux distributions. If you're on Arch Linux, run the following command to install it:
$ sudo pacman -S chrony
On Debian, Ubuntu, Linux Mint:
$ sudo apt-get install chrony
$ sudo dnf install chrony
Once installed, start chronyd.service daemon if it is not started already:
$ sudo systemctl start chronyd.service
Make it to start automatically on every reboot using command:
$ sudo systemctl enable chronyd.service
To verify if the Chronyd.service has been started, run:
$ sudo systemctl status chronyd.service
If everything is OK, you will see an output something like 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 18.104.22.168 Oct 17 10:35:03 ubuntuserver chronyd: Source 22.214.171.124 replaced with 2403 Oct 17 10:35:03 ubuntuserver chronyd: Selected source 126.96.36.199 Oct 17 10:35:06 ubuntuserver chronyd: Selected source 188.8.131.52
As you can see, Chrony service is started and working!
The NTP clients needs to know which NTP servers it should contact to get the current time. We can specify the NTP servers in the server or pool directive in the NTP configuration file. Usually, the default configuration file is /etc/chrony/chrony.conf or /etc/chrony.conf depending upon the Linux distribution version. For better reliability, it is recommended to specify at least three servers.
The following lines are just an example taken from my 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 see in the above output, NTP Pool Project has been set as the default time server. For those wondering, NTP pool project is the cluster of time servers that provides NTP service for tens of millions clients across the world. It is the default time server for Ubuntu and most of the other major Linux distributions.
- the iburst option is used to speed up the initial synchronisation.
- the maxsources refers the maximum number of NTP sources.
Please make sure that the NTP servers you have chosen are well synchronised, stable and close to your location to improve the accuracy of the time with NTP sources.
Manage Chronyd from command line
Chrony has a command line utility named chronyc to control and monitor the chrony daemon (chronyd).
To check if chrony is synchronized, we can use the tracking command 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 verify the current time sources that chrony uses with 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
Chronyc utility can find the statistics of each sources, such as drift rate and offset estimation process, using sourcestats command.
$ 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 Internet, you need to notify Chrony that the system is not connected to the Internet. To do so, run:
$ sudo chronyc offline [sudo] password for sk: 200 OK
To verify the status of your 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 see, all my NTP sources are down at the moment.
Once you're connected to the Internet, just notify Chrony that your system is back online using command:
$ sudo chronyc online 200 OK
To view the status of 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 more detailed explanation of all options and parameters, refer the man pages.
$ man chronyc
$ man chronyd
And, that's all for now. Hope this was useful. In the subsequent tutorials, we will see how to setup a local NTP server using Chrony and configure the clients to use it to synchronise time.