Step-by-Step Set up NTP Server and Client on Rocky Linux 8

In this guide, we want to teach you to Set up NTP Server and Client on Rocky Linux 8.

Network Time Protocol (NTP) is a set of rules and conventions for synchronizing server clocks in a computer network. A client can request time information from an NTP server over a packet network.

NTP is a cost-effective and reliable method of delivering time information accurately within a few milliseconds of Coordinated Universal Time (UTC) that has been widely used in networks across the globe since the 1980s.

Steps to Set up NTP Server and Client on Rocky Linux 8

To set up NTP on your server, you need to log in as a non-root user with sudo privileges and set up a basic firewall. To do this, you can check our guide the Initial Server Setup with Rocky Linux 8.

Follow the steps below to Set up NTP Server and Client on Rocky Linux 8.

Install Chrony on Rocky Linux 8

You need to have Chrony installed on your server to Set up NTP Server and Client on Rocky Linux 8.

Chrony is a flexible Network Time Protocol implementation (NTP). It can sync the system clock with NTP servers, reference clocks (such as a GPS receiver), and manual input via wristwatch and keyboard.

Check the Current Time Zone on Rocky Linux

First of all, you need to check the current time zone of your server with the following command:

timedatectl

Example output:

Output
Time zone: America/New_York (EDT, -0400)

Then, update your local package index with the command below:

sudo dnf update -y

Install Chrony

Then, install Chrony on Rocky Linux 8 with the following command:

sudo dnf install chrony -y

Manage Chrony Service

Start and enable your Chrony service with the commands below:

# sudo systemctl start chronyd 
# sudo systemctl enable chronyd

To verify that your Chrony service is active and running on your server, run the command below:

sudo systemctl status chronyd
Output
chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor pre>
Active: active (running) since Mon 2022-04-11 06:59:56 EDT; 10min ago
Docs: man:chronyd(8)
man:chrony.conf(5)
Main PID: 23975 (chronyd)
Tasks: 1 (limit: 11409)
Memory: 1.6M
CGroup: /system.slice/chronyd.service
└─23975 /usr/sbin/chronyd

Now that you have NTP installed on your server, you need to make some configuration changes.

Configure NTP Server on Rocky Linux 8

The default configuration file for the NTP server is /etc/chrony.conf.

First, you need to open the file with your favorite text editor, here we use vi:

sudo vi /etc/chrony.conf

At the file, comment on the Pool line by adding the # from the beginning of the line.

Add a list of NTP servers close to your location. In my case in the US, you can use the All pool server on the ntppool website:

#pool 2.cloudlinux.pool.ntp.org iburst
server 0.us.pool.ntp.org
server 1.us.pool.ntp.org
server 2.us.pool.ntp.org
server 3.us.pool.ntp.org

Allow NTP Client Access

Also, you need to Allow NTP client access from the local network. To do this, edit the line below:

# Allow NTP client access from local network. 
allow 192.168.201.0/24 

When you are done, save and close the file.

In the next step, you need to set NTP synchronization with the following command:

sudo timedatectl set-ntp true

Restart your Chrony service to apply the changes:

sudo systemctl restart chronyd 

Now you can check whether your NTP server is working or not with the following command:

chronyc sources
Output
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^? ntp.xtom.com 2 6 1 4 +592us[ +592us] +/- 139ms
^? mail.fotiu.com 3 6 1 4 -15ms[ -15ms] +/- 140ms
^? 2605:6400:d814::ad18 2 6 1 4 -2515us[-2515us] +/- 111ms
^? ns1.backplanedns.org 2 6 1 7 +7127us[+7127us] +/- 140ms

Configure Firewall

At this point, you need to allow NTP service through the Rocky Linux 8 firewall:

sudo firewall-cmd --permanent --add-service=ntp --permanent

Reload the firewall to apply the changes:

sudo firewall-cmd --reload

Now that you have configured NTP on your server, you need to configure the NTP client.

Configure NTP Client on Rocky Linux 8

At this point, you need to install the NTP client on a client machine and configure it with the Chrony. Here our client machine is Rocky Linux.

First, you need to set the correct timezone on your client machine:

sudo timedatectl set-timezone America/New_York

Then, install Chrony on your client machine:

sudo dnf install chrony -y

Edit the configuration file /etc/chrony.conf and point to your NTP server.

sudo vi /etc/chrony.conf
#pool 2.fedora.pool.ntp.org iburst 
server your-server-ip-address

When you are done, save and close the file.

Restart your Chrony service to apply the changes:

sudo systemctl restart chronyd

Next, set NTP synchronization:

sudo timedatectl set-ntp true

Enable your Chrony service to start on boot:

sudo systemctl enable chronyd

Now verify your time synchronization:

chronyc sources
Output
MS Name/IP address Stratum Poll Reach LastRx Last sample 
=============================================================================== 
^* server-ip-address  4 6 37 29 +14us[ +30us] +/- 11ms

Finally, you can check on NTP clients. To do this, log in to your Rocky Linux 8 server and run the command below:

sudo chronyc clients
Output
Hostname NTP Drop Int IntL Last Cmd Drop Int Last
 =============================================================================== 
localhost 0 0 - - - 5 0 10 13 
client-machine-ip  19 0 6 - 67 0 0 - -

Conclusion

At this point, you learn to Set up NTP Server and Client on Rocky Linux 8. Hope you enjoy it.

You may like these articles:

Install and Configure NTP Server and Client on AlmaLinux 9

Install and Configure NTP Server and Client on Ubuntu 22.04

Configure NTP Server and Client on Centos 7

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!