Network Time Protocol (NTP) is used to synchronize the clocks of computers on a network. In this tutorial, we will learn how to set up an NTP server on Rocky Linux using the Chrony package, a modern alternative to the traditional NTP on Rocky Linux.
How to Set up NTP Server on Rocky Linux
Prerequisites
Before you begin, ensure that you have:
- A Rocky Linux system installed and updated.
- Root or sudo access to the system.
Install Chrony on Rocky Linux
To install Chrony, run the following command:
sudo dnf install -y chrony
Configure Chrony on Rocky Linux
Once Chrony is installed, you will need to configure it. Open the configuration file with a text editor like nano:
sudo nano /etc/chrony.conf
Look for the pool
directive in the file, which specifies the NTP servers that Chrony will use for synchronization. By default, the configuration file uses public NTP servers. You can either leave the default settings or replace them with your preferred NTP servers.
For example, you can use the pool.ntp.org project’s time servers:
pool 0.rhel.pool.ntp.org iburst
pool 1.rhel.pool.ntp.org iburst
pool 2.rhel.pool.ntp.org iburst
pool 3.rhel.pool.ntp.org iburst
Save and exit the configuration file.
Start and Enable Chrony on Rocky Linux
Start the NTP service with the following command:
sudo systemctl enable chronyd
To enable the NTP service at boot, run:
sudo systemctl start chronyd
Allow NTP Through the Firewall on Rocky Linux
If you have the firewalld service running on your server, you will need to configure it to allow NTP traffic. Execute the following commands to allow NTP through the firewall:
sudo firewall-cmd --add-service=ntp --permanent
sudo firewall-cmd --reload
allow <IP_address>/<subnet_mask>
allow 192.168.1.0/24
Replace <IP_address>
and <subnet_mask>
with the appropriate values for your network. For example, to allow devices on the 192.168.1.0/24 network to synchronize their time:
Verify NTP Server Functionality
You can check the status of your NTP server by running the following command:
chronyc tracking
This command will display information about the current synchronization status, including the system time, last offset, and the reference ID of the NTP server being used.
Configure NTP Clients on Rocky Linux
Now that your NTP server is up and running, you can configure clients to synchronize time with it. Edit the /etc/ntp.conf
file on each client and replace the existing server
lines with the IP address or hostname of your NTP server:
server {your_ntp_server} iburst
Restart the NTP service on the clients to apply the changes:
sudo systemctl restart chronyd
That’s it! Your NTP server is now set up on Rocky Linux and ready to synchronize time with clients.
Conclusion
In this tutorial, we covered how to set up an NTP server on Rocky Linux and configure clients to synchronize with it. Keeping accurate time is essential for the proper functioning of many services and applications. Now that you have an NTP server running on your network, you can ensure that all devices maintain the correct time.
If you’re looking to further enhance your Rocky Linux server, check out these additional tutorials: