Installing Chrony on Ubuntu to manage NTP

For good reason, Chrony has been the default NTP implementation on RHEL/CentOS/Fedora for the last several releases. Let’s install and configure it.

Check your current NTP status:

timedatectl status

Notice that the time zone hasn’t been set and the system is still using the default NTP implementation:

Local time: Tue 2020-05-26 03:42:36 UTC
Universal time: Tue 2020-05-26 03:42:36 UTC
RTC time: Tue 2020-05-26 03:42:36
Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
systemd-timesyncd.service active: yes
RTC in local TZ: no

Show the available timezones:

timedatectl list-timezones

timedatectl list-timezones | grep -i america

Set your timezone:

timedatectl set-timezone America/New_York

Verify the timezone has been set:

timedatectl status

Local time: Mon 2020-05-25 23:45:15 EDT
Universal time: Tue 2020-05-26 03:45:15 UTC
RTC time: Tue 2020-05-26 03:45:15
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
systemd-timesyncd.service active: yes
RTC in local TZ: no
ls -ld /etc/localtime
lrwxrwxrwx 1 root root 38 May 25 23:45 /etc/localtime -> ../usr/share/zoneinfo/America/New_York

Check the timesyncd service status before installing Chrony:

systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-05-24 21:09:04 EDT; 1 day 2h ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 557 (systemd-timesyn)
Status: "Synchronized to time server 91.189.89.198:123 (ntp.ubuntu.com)."
Tasks: 2 (limit: 4660)
CGroup: /system.slice/systemd-timesyncd.service
└─557 /lib/systemd/systemd-timesyncd

Install Chrony:

apt-get install chrony

Verify Chrony is running:

systemctl status chronyd
chrony.service - chrony, an NTP client/server
Loaded: loaded (/lib/systemd/system/chrony.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2020-05-25 23:57:19 EDT; 3min 1s ago
Docs: man:chronyd(8)
man:chronyc(1)
man:chrony.conf(5)
Main PID: 3862 (chronyd)
Tasks: 1 (limit: 4660)
CGroup: /system.slice/chrony.service
└─3862 /usr/sbin/chronyd

Verify the timesyncd service was stopped by Chrony:

systemctl status systemd-timesyncd.service

The service is enabled and loaded, but inactive:

systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Mon 2020-05-25 23:57:19 EDT; 43s ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 557 (code=exited, status=0/SUCCESS)
Status: "Idle."

Disable timesyncd for good:

systemctl disable systemd-timesyncd.service

Verify one more time timesyncd is gone for good:

systemctl status systemd-timesyncd.service

The timesyncd service is dead and disabled:

systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; disabled; vendor preset: enabled)
Active: inactive (dead) since Mon 2020-05-25 23:57:19 EDT; 1min 42s ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 557 (code=exited, status=0/SUCCESS)
Status: "Idle."

If you wish, you can specify the NTP servers you want Chrony to use:

vim /etc/chrony/chrony.conf
...
# 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
...

A great resource for fast and reliable NTP servers is the NTP Pool Project.


Restart services to apply the new settings:

systemctl restart systemd-timedated.service
systemctl restart chrony

Verify Chrony is talking to the NTP servers:

chronyc sources
210 Number of sources = 8
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^- pugot.canonical.com 2 6 33 37 -135us[ -135us] +/- 79ms
^+ alphyn.canonical.com 2 6 17 39 +403us[ +403us] +/- 69ms
^- golem.canonical.com 2 6 17 40 +1473us[+1473us] +/- 71ms
^+ chilipepper.canonical.com 2 6 17 40 -1415us[-1415us] +/- 80ms
^- t2.time.gq1.yahoo.com 2 6 17 40 -2210us[-2210us] +/- 44ms
^+ nu.binary.net 2 6 17 40 -718us[ -718us] +/- 47ms
^* jonasled.de 2 6 17 41 +1354us[ -27us] +/- 86ms
^+ h199-182-204-197.ip4.unm> 2 6 35 37 +557us[ +557us] +/- 50ms