AlmaLinuxRHEL Based

How To Install NTP on AlmaLinux 9

Install NTP on AlmaLinux 9

In this tutorial, we will show you how to install NTP on AlmaLinux 9. NTP is a networking protocol designed to synchronize the clocks of computers over a network. It operates using a hierarchical system of time sources, with each level or stratum representing the distance from the reference clock. Stratum 0 devices, such as atomic clocks or GPS receivers, serve as the most accurate time sources. Stratum 1 servers synchronize directly with Stratum 0 devices, while Stratum 2 servers synchronize with Stratum 1 servers, and so on.

NTP utilizes the User Datagram Protocol (UDP) on port 123 for communication between clients and servers. By exchanging time information and calculating the network delay, NTP clients can adjust their local clocks to match the accurate time provided by the NTP servers.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Network Time Protocol (NTP) on AlmaLinux 9. You can follow the same instructions for CentOS and Rocky Linux or RHEL-based.

Prerequisites

  • A server running one of the following operating systems: AlmaLinux 9.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • Basic familiarity with Linux command line operations.
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • You’ll need root or sudo privileges to configure NTP and make system-wide changes. Make sure you have the necessary permissions before starting the installation process.

Install NTP on AlmaLinux 9

Step 1. Update Your System.

Before configuring NTP, it is crucial to update your AlmaLinux 9 system to ensure you have the latest packages and security patches. Updating the system helps prevent potential compatibility issues and vulnerabilities. To update your system, follow these steps:

sudo dnf clean all
sudo dnf update

This command will download and install any available updates for your system.

Step 2. Setting the System Timezone.

To ensure accurate timekeeping, it is crucial to set the correct timezone on your AlmaLinux 9 system. Follow these steps to configure the timezone:

sudo timedatectl set-timezone America/New_York

Verify the current timezone settings by running:

sudo timedatectl

Look for the “Time zone” line in the output to confirm that the timezone has been set correctly.

Alternatively, you can check the system timezone by examining the /etc/localtime file. Ensure that it is a symbolic link pointing to the appropriate timezone file in the /usr/share/zoneinfo directory.

Step 3. Installing Chrony.

AlmaLinux 9 uses Chrony as the default NTP implementation. Chrony is a versatile NTP client and server that offers improved accuracy and stability compared to the traditional ntpd daemon. To install Chrony, follow these steps:

sudo dnf install chrony

Once the installation is complete, verify that the Chrony service is running by executing:

sudo systemctl status chronyd

The output should indicate that the Chrony service is active and running.

Chrony consists of two main components: chronyd, the daemon that runs in the background and synchronizes the system clock, and chronyc, the command-line interface for monitoring and controlling Chrony’s operation.

Step 4. Configuring Chrony.

The configuration file for Chrony is located at /etc/chrony.conf. This file contains various directives that control how Chrony operates. To configure Chrony, follow these steps:

sudo nano /etc/chrony.conf

Locate the server directives in the file. These directives specify the NTP servers that Chrony will synchronize with. By default, Chrony uses the NTP pool servers. You can either use these servers or specify your own trusted NTP servers. For example:

server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst

If you want to allow other systems on your network to synchronize with your Chrony server, add an allow directive followed by the network range. For example, to allow synchronization requests from the 192.168.0.0/24 network, add:

allow 192.168.0.0/24

Save the changes and exit the text editor.

After configuring Chrony, you need to start the Chrony service and enable it to automatically start at system boot. Use the following commands:

  • Start the Chrony service:
sudo systemctl start chronyd
  • Enable the Chrony service to start automatically at boot:
sudo systemctl enable chronyd
  • Verify the status of the Chrony service:
sudo systemctl status chronyd

The output should confirm that the service is active and running.

If you make any changes to the Chrony configuration file in the future, remember to restart the Chrony service for the changes to take effect:

sudo systemctl restart chronyd

Step 5. Configuring Firewall.

To allow NTP traffic through the firewall, you need to open the necessary ports. AlmaLinux 9 uses firewalld as the default firewall management tool. Follow these steps to configure the firewall:

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

Reload the firewall rules:

sudo firewall-cmd --reload

If you have a specific network range that should be allowed to access the NTP service, you can use a rich rule instead:

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.0.0/24" service name="ntp" accept'

To verify the firewall rules, use the following command:

sudo firewall-cmd --list-all

Step 6. Verifying NTP Synchronization.

After configuring Chrony and opening the necessary firewall ports, it’s essential to verify that NTP synchronization is working correctly. Chrony provides the chronyc command-line tool for monitoring and interacting with the Chrony daemon. Use the following commands to check the synchronization status:

Check the current synchronization status:

chronyc tracking

List the NTP sources:

chronyc sources

This command shows a list of the NTP servers that Chrony is currently synchronizing with, along with their stratum, poll interval, and other relevant details.

If you encounter any issues or discrepancies in the synchronization status, refer to the Chrony logs for troubleshooting. The logs are typically located in the /var/log/chrony directory.

Step 7. Managing and Monitoring Chrony.

Chrony provides various commands through the chronyc utility for managing and monitoring the NTP service. Here are a few useful commands:

Manually step the system clock:

sudo chronyc makestep

Display detailed NTP source information:

chronyc sourcestats

View the current time:

chronyc time

Check for any errors or warnings:

sudo journalctl -u chronyd

Congratulations! You have successfully installed NTP. Thanks for using this tutorial for installing the Network Time Protocol (NTP) on your AlmaLinux 9 system. For additional help or useful information, we recommend you check the official NTP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button