NTP stands for Network Time Protocol and is used for clock synchronization across multiple computers. An NTP server is responsible for keeping a set of computers in sync with each other. On a local network, the server should be able to keep all client systems to within a single millisecond of each other.
Such a configuration would be necessary if, for example, the systems needed to start or stop a task in unison at a precise time. In this article, we’ll show you how to configure an NTP server on AlmaLinux and how to configure a client system to sync its system time with said server. This can be done from a fresh AlmaLinux installation or on a system that has migrated from CentOS to AlmaLinux.
In this tutorial you will learn:
- How to install and configure chrony NTP server
- How to open firewall to incoming NTP requests
- How to connect to an NTP server from a client machine
Category | Requirements, Conventions or Software Version Used |
---|---|
System | AlmaLinux |
Software | chrony |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Configure NTP server
As an example, we will show the step by step instructions to setup an NTP server for network 192.168.1.0/24
. Of course, feel free to change this network to represent your own environment.
- Chrony is the default NTP client as well as NTP server on RHEL and AlmaLinux. To begin, we will install the chrony NTP server daemon. You can do so by opening a terminal and entering the following command:
# dnf install chrony
- Enable the chrony service to start automatically upon system boot.
# systemctl enable chronyd
- Since chrony can act as either an NTP server or client, we need to make a change to the
/etc/chrony.conf
configuration file. Adding the following line will instruct it to act as an NTP server for the192.168.1.0/24
network.allow 192.168.1.0/24
Add as many
allow
lines as you need for other IP addresses or networks. - Restart chrony NTP daemon to apply the changes.
# systemctl restart chronyd
- If you have firewalld enabled on AlmaLinux, you’ll need to allow the port for NTP in order to accept incoming requests.
# firewall-cmd --permanent --add-service=ntp # firewall-cmd --reload
Configure NTP client
Once your time server has been configured, we can move on to configuring our client machine(s) to time sync with our new chrony NTP server. Note that in this example, our NTP server is located at the 192.168.1.150
IP address.
- Install the chrony NTP package and enable it to start automatically at boot.
# dnf install chrony # systemctl enable chronyd
- Configure chrony as an NTP client by adding the following line to
/etc/chrony.conf
.server 192.168.1.150
Of course, substitute our example IP address with the actual IP of your NTP server.
- Restart chrony NTP daemon to apply the changes.
# systemctl restart chronyd
- Verify that the client is utilizing our NTP server by running the following command.
# chronyc sources 210 Number of sources = 6 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* almatime.localdomain 3 6 377 11 -1310us[ -755us] +/- 54ms
By default the chrony NTP client will perform a time synchronization every 64 seconds.
- Back on our NTP server, we can see a list of connected clients with the following command.
# chronyc clients Hostname NTP Drop Int IntL Last Cmd Drop Int Last =============================================================================== ntp-client.localdomain 6 0 10 - 12 0 0 - -
Closing Thoughts
In this article, we learned about the Network Time Protocol (NTP) and how to setup our own NTP server on AlmaLinux. We also saw how to configure a client machine (or multiple machines, as is usually the case) to connect to the NTP server for time synchronization.