This tutorial will help you install and configure NTP server using Chrony on RHEL 8 / CentOS 8. Are you new to RHEL 8?, check out Red Hat Enterprise Linux 8 (RHEL 8) New Features & Review. NTP (Network Time Protocol) is a network protocol that allows for clock synchronization between computer systems.
Chrony is a versatile implementation of the Network Time Protocol. It has two programs chrony
and chronyd
.
- chronyd is a daemon that can be started at boot time
chronyc
is a command-line interface program which can be used to monitorchronyd
’s performance and to change various operating parameters whilst it is running.
Installing Chrony NTP on RHEL 8 / CentOS 8
Set timezone. Replace Africa/Nairobi timezone with your correct value.
sudo timedatectl set-timezone Africa/Nairobi
Chrony can be installed on RHEL 8 / CentOS 8 from package manager.
sudo yum -y install chrony
After the installation, start and enable chronyd service.
sudo systemctl enable --now chronyd
The service status should show running
$ systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-08-16 10:24:20 UTC; 5min ago
Docs: man:chronyd(8)
man:chrony.conf(5)
Main PID: 631 (chronyd)
Tasks: 1 (limit: 10843)
Memory: 2.2M
CGroup: /system.slice/chronyd.service
└─631 /usr/sbin/chronyd
Aug 16 10:24:19 CentOS-8-64-minimal systemd[1]: Starting NTP client/server...
Aug 16 10:24:19 CentOS-8-64-minimal chronyd[631]: chronyd version 4.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +NTS +SECHASH +IPV6 +DEBUG)
Aug 16 10:24:19 CentOS-8-64-minimal chronyd[631]: Frequency -24.410 +/- 5.640 ppm read from /var/lib/chrony/drift
Aug 16 10:24:19 CentOS-8-64-minimal chronyd[631]: Using right/UTC timezone to obtain leap second data
Aug 16 10:24:20 CentOS-8-64-minimal systemd[1]: Started NTP client/server.
Aug 16 10:24:26 cent8.mylab.io chronyd[631]: Selected source 213.239.239.164 (ntp.hetzner.com)
Aug 16 10:24:26 cent8.mylab.io chronyd[631]: System clock TAI offset set to 37 seconds
Configuring Chrony NTP on RHEL 8 / CentOS 8
After the installation, you can make the changes on Chrony main configuration file /etc/chrony.conf
One main configuration change you can make is to set the time servers closest to you. Since I’m in Nairobi, I’ll set Africa NTP pool of servers.
sudo vi /etc/chrony.conf
Comment out the first pool line and add a list of NTP servers.
#pool 2.rhel.pool.ntp.org iburst
server 0.africa.pool.ntp.org iburst
server 1.africa.pool.ntp.org iburst
server 2.africa.pool.ntp.org iburst
server 3.africa.pool.ntp.org iburst
You can also add CentOS NTP servers if you don’t have ones close to you.
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
Set NTP synchronization.
sudo timedatectl set-ntp true
Restart chronyd
service after making the change.
sudo systemctl restart chronyd
You can also specify IP addresses or network address block that is allowed to access your NTP server.
# Allow NTP client access from local network.
allow 192.168.25.0/24
If you have active firewalld service, allow ntp port.
sudo firewall-cmd --add-service=ntp --permanent
sudo firewall-cmd --reload
Check if NTP server is working.
$ sudo chronyc sources
210 Number of sources = 3
MS Name/IP address Stratum Poll Reach LastRx Last sample
^+ ntp.dts.mg 2 7 377 127 +2102us[+1979us] +/- 98ms
^* 196.9.24.88 2 7 377 2 -11ms[ -11ms] +/- 103ms
^+ jhb-ntp.mweb.co.za 3 7 377 132 -76us[ +158us] +/- 103ms
[root@rhel8 ~]#
Configure NTP Client on CentOS 8 / RHEL 8
Now that you have Chrony NTP Server installed and configured, you can configure NTP client.
Set timezone.
sudo timedatectl set-timezone Africa/Nairobi
Install chrony and configure it as NTP client.
sudo yum -y install chrony
Edit the configuration file to set NTP server to point your newly configured NTP server.
$ sudo vi /etc/chrony.conf
server 192.168.25.3
Set NTP synchronization.
sudo timedatectl set-ntp true
Start and enable the service.
sudo systemctl enable --now chronyd
Verify the setting using the following command:
$ sudo chronyc sources
210 Number of sources = 3
MS Name/IP address Stratum Poll Reach LastRx Last sample
^+ 192.168.25.3 2 7 377 61 +12ms[ +12ms] +/- 100ms
That’s all. You now have NTP server working on RHEL 8 server. See how you can use the timedatectl command to synchronize the system clock with NTP server.
Want an easy to administer RHEL / CentOS server from a web UI?, check out:
More guides: