The Network Time Protocol (NTP) is a protocol used to synchronize the clocks of computers over a network. NTP uses a hierarchical architecture of time sources, which can be either local or external. In this guide, we will show you how to install and configure an NTP client on CentOS/RHEL to synchronize the clock with an NTP server.
Step 1: Install NTP
The first step is to install the NTP package. You can do this by running the following command as root:
yum install ntp
This will download and install the NTP package and its dependencies.
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * addons: ftp.oss.eznetsols.org * base: ftp.oss.eznetsols.org * epel: ftp.cuhk.edu.hk * extras: ftp.oss.eznetsols.org * updates: ftp.oss.eznetsols.org Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package ntp.x86_64 0:4.2.2p1-9.el5.centos.2.1 set to be updated --> Finished Dependency Resolution Dependencies Resolved ===================================================================================== Package Arch Version Repository Size ===================================================================================== Installing: ntp x86_64 4.2.2p1-9.el5.centos.2.1 base 1.3 M Transaction Summary ===================================================================================== Install 1 Package(s) Upgrade 0 Package(s) Total download size: 1.3 M Is this ok [y/N]: y Downloading Packages: ntp-4.2.2p1-9.el5.centos.2.1.x86_64.rpm | 1.3 MB 00:04 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing : ntp 1/1 Installed: ntp.x86_64 0:4.2.2p1-9.el5.centos.2.1 Complete!
Step 2: Configure NTP
After installing NTP, you need to configure it to synchronize the clock with an NTP server. The NTP configuration file is located at /etc/ntp.conf. You can edit this file with a text editor to add the NTP server you want to synchronize with.
# vi /etc/ntp.conf
Find the lines that specify the NTP servers and add the IP address or hostname of the NTP server you want to use.
server 0.centos.pool.ntp.org //set this to your primary NTP server - Line 17 server 1.centos.pool.ntp.org //set this to your Secondary NTP server (Optional) - Line 18 server 2.centos.pool.ntp.org //set this to your tertiary NTP server (Optional) - Line 19
For example, to synchronize with the NTP server at IP address 192.0.2.1, add the following line:
Save the file and exit the text editor.
Step 3: Start NTP
After configuring NTP, you need to start the NTP service. You can do this by running the following command as root:
systemctl start ntpd
This will start the NTP service and synchronize the clock with the NTP server you specified in the configuration file.
Step 4: Enable NTP at boot
To ensure that NTP starts automatically at boot time, you need to enable the NTP service. You can do this by running the following command as root:
systemctl enable ntpd
This will create a symbolic link in the /etc/systemd/system/multi-user.target.wants/ directory to the NTP service unit file.
Step 5: Verify NTP synchronization
After starting NTP, you can verify that the clock is synchronized with the NTP server by running the following command:
This will display a list of NTP servers and their status. The “*” symbol indicates the NTP server that the client is synchronized with.
- yum install – installs packages
- systemctl start – starts a systemd service
- systemctl enable – enables a systemd service to start at boot
- ntpq -p – displays NTP server status
In this guide, we have shown you how to install and configure an NTP client on CentOS/RHEL to synchronize the clock with an NTP server. By synchronizing the clock with an NTP server, you can ensure that the time on your server is accurate, which is important for various applications such as logging and authentication. Remember to verify that NTP synchronization is working correctly by using the ntpq command.