Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Setting Up NTP (Network Time Protocol) Server in RHEL/CentOS 7
Network Time Protocol (NTP) is a networking protocol used to synchronize the clocks of computers over a network. Setting up an NTP server in RHEL/CentOS 7 allows you to provide accurate time synchronization to client devices across your network infrastructure.
Prerequisites
Before configuring the NTP server, ensure you have root privileges and network connectivity to external NTP sources. The server should also have proper DNS resolution configured for accessing public NTP servers.
Install NTP Package
First, install the NTP package using the YUM package manager. This provides the necessary software components to run an NTP server on your RHEL/CentOS 7 system.
sudo yum install ntp
Verify the installation by checking if the NTP daemon is available:
rpm -qa | grep ntp
Configure NTP Server
Edit the main NTP configuration file located at /etc/ntp.conf. This file contains server definitions, access controls, and other NTP-specific settings.
sudo nano /etc/ntp.conf
Add or modify the server entries to specify your preferred time sources. For example:
server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst
The iburst option sends a burst of packets for faster initial synchronization.
Configure Firewall
NTP uses UDP port 123 for communication. Open this port in the firewall to allow NTP traffic from client devices.
sudo firewall-cmd --add-port=123/udp --permanent sudo firewall-cmd --reload
For systems using iptables instead of firewalld:
sudo iptables -A INPUT -p udp --dport 123 -j ACCEPT sudo service iptables save
Start and Enable NTP Service
Start the NTP daemon and configure it to start automatically at boot time:
sudo systemctl start ntpd sudo systemctl enable ntpd
Verify the service status:
sudo systemctl status ntpd
Verify NTP Synchronization
Check if your NTP server is properly synchronizing with upstream servers:
ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*0.centos.pool.n 192.168.1.1 2 u 64 64 377 1.234 -0.567 0.123
+1.centos.pool.n 10.0.0.1 2 u 32 64 377 2.345 +1.234 0.234
The asterisk (*) indicates the currently selected reference server, while plus (+) shows backup servers.
Client Configuration
To configure client machines to use your NTP server, modify their /etc/ntp.conf file:
server your_ntp_server_ip iburst
Replace your_ntp_server_ip with your NTP server's actual IP address.
Conclusion
Setting up an NTP server in RHEL/CentOS 7 involves installing the NTP package, configuring time sources, opening firewall ports, and enabling the service. Once configured, your NTP server will provide accurate time synchronization to client devices, ensuring consistent timekeeping across your network infrastructure.
