Share your love
Set up NTP Server and Client on Rocky Linux 9

In this guide, we want to teach you to Set up or Install and Configure NTP Server and Client on Rocky Linux 9.
Network Time Protocol (NTP) is a protocol that allows the synchronization of system clocks (from desktops to servers). Having synchronized clocks is not only convenient but required for many distributed applications. Therefore the firewall policy must allow the NTP service if the time comes from an external server.
Steps To Set up NTP Server and Client on Rocky Linux 9
To complete this guide, you must log in to your server as a non-root user and set up a basic firewall. To do this, you can follow our guide on Initial Server Setup with Rocky Linux 9.
Install Chrony on Rocky Linux 9
To install NTP on your Rocky Linux server, you must have Chrony installed on your server. Chrony is an implementation of the Network Time Protocol and is useful in a number of ways.
First, you need to check your current time zone by using the command below:
timedatectl
Example output:
Output
Time zone: America/New_York (EDT, -0400)
Next, update your local package index with the following command:
sudo dnf update -y
Then, use the following command to install Chrony on Rocky Linux 9:
sudo dnf install chrony -y
Manage Chrony Service
At this point, you need to start and enable Chrony to start on the boot system:
# sudo systemctl start chronyd
# sudo systemctl enable chronyd
To verify that your Chrony service is active and running on your Rocky Linux 9, run the command below:
sudo systemctl status chronyd
Output
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor p>
Active: active (running) since Mon 2022-09-26 05:07:23 EDT; 8min ago
Docs: man:chronyd(8)
man:chrony.conf(5)
Main PID: 562 (chronyd)
Tasks: 1 (limit: 23609)
Memory: 2.2M
CPU: 66ms
CGroup: /system.slice/chronyd.service
└─562 /usr/sbin/chronyd -F 2
...
Now let’s see how to configure the NTP server.
Configure NTP Server on Rocky Linux 9
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 editor:
sudo vi /etc/chrony.conf
At the file, comment on the Pool line by adding the # from the beginning of the line.
Then, add a list of NTP servers close to your location. In my case 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
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
Check NTP Server Status
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
===============================================================================
^? connected.by.freedominte> 2 6 1 8 +1183us[+1183us] +/- 25ms
^? time.richiemcintosh.com 2 6 1 8 +1575us[+1575us] +/- 83ms
^? washington.homemail.org 2 6 1 10 +15ms[ +15ms] +/- 95ms
^? clock.isc.org 3 6 1 11 +4859us[+4859us] +/- 152ms
Configure Firewall for NTP
At this point, you need to allow NTP service through the Rocky Linux 9 firewall:
sudo firewall-cmd --permanent --add-service=ntp --permanent
Reload the firewall to apply the changes:
sudo firewall-cmd --reload
Now let’s see how to configure the NTP client.
Configure NTP Client on Rocky Linux 9
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 9.
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
Check NTP Client Status
Finally, you can check on NTP clients. To do this, log in to your Rocky Linux 9 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 - -
That’s it, you are done.
Conclusion
At this point, you have learned to Set up or Install and Configure NTP Server and Client on Rocky Linux 9.
Hope you enjoy it.
You may be like these articles:
Install Caddy Web Server on Rocky Linux 9