In today’s blog we wil guide on How to Install NTP server and Client on Rocky Linux using Chrony. Network Time Protocol, or NTP, is a networking protocol used on computer networks to synchronize time and clocks.
As an alternative to other programs like up, Chrony is an implementation of the Network Time Protocol, or NTP. Operating systems similar to Unix may run Chrony, which is licensed under the GNU GPL v2. Chrony is available for several Linux distributions and is the default NTP server software for some of them.
You can find instructions on how to install and utilize Chrony on the Rocky Linux server in this tutorial. Two distinct methods of using Chrony will be taught to you:
- NTP Server – Typically, this is the case if you wish to construct a local NTP server. Hence, clients will connect to the local computer running Chrony as NTP Server rather than the public NTP server on the internet.
- NTP Client – At this point, your computer or client’s time has to be synchronized with an NTP server.
Pre-Requisite
The two separate Rocky Linux servers that will be utilized as an NTP server and NTP client are assumed to exist for the purposes of this guide. Either the most recent version 9, or Rocky Linux v8, can be used. Additionally, on both machines, you will require a non-root user with sudo root rights. If you need support refer How to Install Rocky Linux
Hostname IP Address Used as
------------------------------------------------
ntp-server 192.168.255.126 NTP Server
ntp-client 192.168.255.129 NTP Client
Chrony Installation
One way that Unix-like operating systems implement NTP (Network Time Protocol) is using Chrony. The Chrony package may be found by default in the baseos Rocky Linux repository.
Use the dnf command shown below to install the Chrony package.
sudo dnf install chrony -y
Once the package is installed now enable and start the services
sudo systemctl enable chronyd
sudo systemctl start chronyd
Configuring Chrony as NTP
This step explains how to configure Chrony on the ROCKY Linux server as an NTP server. We will utilize the Rocky Linux server with the hostname “rocky8” and IP address “192.168.255.126” in this example.
Open ‘/etc/.chrony.conf‘ by running the following line in editor of your choice
sudo vim /etc/chrony.conf
You can choose the NTP server source that you wish to utilize on the server directive. The NTP server pool that is closest to you may be found at NTP Pool Project
We’ll utilize the NTP server pool from Asia for this example. Furthermore, we will make advantage of the extra option ‘iburst’, which enables the Chronyd service to refresh the clock for the first time soon after launch.
# list servers
server 0.asia.pool.ntp.org iburst
server 1.asia.pool.ntp.org iburst
server 2.asia.pool.ntp.org iburst
server 3.asia.pool.ntp.org iburst
Remove the comment from the ‘allow‘ directive and include the IP address subnet that is permitted to connect to the NTP server. All clients connected to the network “192.168.2555.0/24” in this example will have access to the NTP server.
# allowed clients
allow 192.168.255.0/24
Save the file and exit once editing is completed
Let us now restart the Chronyd services
sudo systemctl restart chronyd
Verify the sources of the NTP server pool
chronyc sources
Output
[user@ntp-server ~]$ chronyc sources
MS Name/IP address Stratum Poll Reach LastRx Last sample
=========================================================================
^* 192.168.255.126 2 9 377 47 -198us[ -167us] +/- 109ms
Allow the NTP services in the Firewall for the client to connect
sudo firewall-cmd --add-service=ntp --permanent
sudo firewall-cmd --reload
You have now set up and installed Chrony on the Rocky Linux server to function as an NTP server. Next, you may configure Chrony as an NTP client.
Configuring the NTP Client
You will now be able to configure Rocky Linux to use Chrony as an NTP client. In this example, you will configure the hostname ‘ntp-client‘ for the Chrony NTP client on the Rocky Linux computer.
Make sure the client’s computer has the Chrony package installed before you begin. Installing it may be done with the dnf command.
sudo dnf install chrony -y
Open the configuration file to edit the NTP servers
sudo vim /etc/chrony.conf
Replace the NTP server source on the server directive with the name of your NTP server. The IP address ‘192.168.255.126‘ is being used by the NTP server in this instance.
server 192.168.255.126 iburst prefer
Here ,
- iburst option allows the Chronyd service to make the first update of the clock shortly after the start.
- prefer option will prioritize the NTP Server source among other servers without prefer option.
Save the File and exit.
Restart the Chronyd services
sudo systemctl restart chronyd
Verify the current status of Chrony on the client
chronyc tracking
‘ntp-client‘ should be linked to the NTP server ‘192.168.255.126‘, and should have its time synced with it.
Output
[user@ntp-server ~]$ chronyc tracking
Reference ID : 0AAB0804 (192.168.255.126)
Stratum : 3
Ref time (UTC) : Sun Jan 21 14:47:58 2024
System time : 0.000118946 seconds fast of NTP time
Last offset : +0.000042455 seconds
RMS offset : 0.000098208 seconds
Frequency : 11.909 ppm fast
Residual freq : +0.007 ppm
Skew : 0.084 ppm
Root delay : 0.140833512 seconds
Root dispersion : 0.023049714 seconds
Update interval : 518.6 seconds
Leap status : Normal
The chronyc command below may also be used to confirm the NTP Server sources on the ‘ntp-client‘ system. The NTP Server ‘ntp.hwdomain.io‘ with IP address 192.168.255.126 is now the default and recommended NTP Server source, as you can see on the client computer.
chronyc sources
chronyc sources -v
Output
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current best, '+' = combined, '-' = not combined,
| / 'x' = may be in error, '~' = too variable, '?' = unusable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
========================================================================
^* 192.168.255.126 2 9 377 346 -140us[ -98us] +/- 101ms
Conclusion
The Rocky Linux server now has the Chrony NTP implementation software installed successfully. Additionally, you learnt how to utilize Chrony for both NTP Server and Client in its most basic form. Finally, you have also learnt how to check the NTP status using the chronyc command line.