⏱️ Why NTP Matters on Linux #
Accurate system time is a foundational requirement for modern Linux environments. Network Time Protocol (NTP) ensures clocks remain synchronized across servers and clients, which is critical for:
- Distributed systems and clustering
- Database consistency and replication
- Log correlation and auditing
- Authentication mechanisms (Kerberos, TLS, certificates)
This guide walks through installing, configuring, and validating NTP on Linux, covering both public NTP sources (Aliyun) and a private on-premises NTP server.
🌐 Using Aliyun Public NTP Servers #
Public NTP servers are ideal for most internet-connected systems. Below is an example configuration using Aliyun NTP servers.
Example: /etc/ntp.conf
#
# Aliyun Public NTP Servers
server ntp1.aliyun.com prefer
server ntp2.aliyun.com
server ntp3.aliyun.com
server ntp4.aliyun.com
# Security restrictions
restrict default nomodify notrap nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict -4 default kod notrap nomodify nopeer noquery
# Allow local network synchronization
restrict 192.168.122.0 mask 255.255.255.0 nomodify notrap
# Broadcast settings
broadcast 224.0.1.1
# Drift file configuration
filegen driftfile /var/lib/ntp/driftAfter saving the file, restart the service:
systemctl restart ntpd🧰 Preparing the Environment #
The following examples assume:
- Operating system: CentOS 7.x
- NTP server IP:
192.168.1.111 - NTP client IP:
192.168.1.179
Before configuration:
- Open UDP port 123 on firewalls
- Disable SELinux or configure appropriate policies
🖥️ Installing and Configuring an NTP Server #
1️⃣ Install NTP #
yum install ntp -y2️⃣ Configure /etc/ntp.conf
#
cp /etc/ntp.conf{,.bak}
vim /etc/ntp.confserver 127.127.1.0 # Local clock as time source
fudge 127.127.1.0 stratum 10 # Define stratum level
restrict 127.0.0.1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
driftfile /var/lib/ntp/drift
logfile /var/log/ntp/ntp.logThis configuration is suitable for isolated or internal networks where an upstream internet time source is unavailable.
3️⃣ Create Required Directories #
mkdir -p /var/lib/ntp
mkdir -p /var/log/ntp
touch /var/log/ntp/ntp.log4️⃣ Start and Enable the Service #
systemctl start ntpd
systemctl enable ntpd5️⃣ Verify Server Synchronization #
ntpstatExample output:
synchronised to local net at stratum 6
time correct to within 11 ms
polling server every 64 sCheck peer status:
ntpq -premote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 5 l 13 64 377 0.000 0.000 0.000💻 Installing and Configuring an NTP Client #
1️⃣ Install Required Packages #
yum install ntp ntpdate -y2️⃣ Configure Client /etc/ntp.conf
#
cp /etc/ntp.conf{,.bak}
vim /etc/ntp.confserver 192.168.1.111 # Local NTP server
restrict 127.0.0.1
logfile /var/log/ntp/ntp.log3️⃣ Create Log Directory #
mkdir -p /var/log/ntp
touch /var/log/ntp/ntp.log4️⃣ Perform Initial Time Sync #
ntpdate 192.168.1.111This step avoids large time offsets that may prevent ntpd from syncing.
5️⃣ Start the NTP Daemon #
systemctl start ntpd6️⃣ Verify Client Synchronization #
ntpstatExample during startup:
unsynchronised
time server re-starting
polling server every 8 sCheck peer status:
ntpq -premote refid st t when poll reach delay offset jitter
==============================================================================
192.168.1.111 LOCAL(0) 6 u 11 64 1 0.502 0.009 0.000Once the reach value stabilizes, synchronization is complete.
✅ Summary #
By following this guide, you can deploy a reliable and maintainable NTP infrastructure on Linux, whether:
- Synchronizing directly from Aliyun public NTP servers, or
- Operating a private NTP server for internal environments
Proper time synchronization ensures:
- Accurate and trustworthy logs
- Stable distributed systems
- Secure authentication and cryptographic operations
In production Linux systems, NTP is not optional—it is foundational.