How to Configure NTP Time Synchronization
Learn how to configure NTP time synchronization on Linux with a clear, step-by-step guide for DevOps beginners. Set up servers, verify sync, and troubleshoot common issues to keep system clocks accurate.
A few seconds' difference in system time can break logs, scheduled jobs, cryptographic validation, and more. This guide explains what NTP (Network Time Protocol) does, how to configure reliable time synchronization on Linux servers, and how to verify and troubleshoot it — with practical commands and examples.
How NTP works (brief, practical overview)
NTP synchronizes the clocks of networked computers to reference time servers using timestamps and algorithms that compensate for network delay and clock drift. Modern implementations (chrony, systemd-timesyncd, ntpd) either discipline the clock slowly (slew) or step it when the difference is large.
Example: query a public NTP pool from a server (using ntpq if available):
$ ntpq -pn
remote refid st t when poll reach delay offset jitter
==============================================================================
+time1.google.co .GOOG. 1 u 17 64 377 12.345 -0.012 0.010
*time2.google.co .GOOG. 1 u 16 64 377 11.987 0.005 0.008
Explanation:
- remote: server you're using.
- delay/offset/jitter: network delay and the clock offset relative to the server.
- A leading * on the left indicates the currently selected source.
Key takeaway: pick reliable servers (pool.ntp.org, vendor NTPs, or internal stratum 1) and use an appropriate client (chrony is recommended for most cases).
Configure NTP on Linux (chrony and systemd-timesyncd)
Many modern distros use chrony (recommended for servers and VMs) or systemd-timesyncd for lightweight setups. Below are basic install/configure/start examples.
chrony (recommended)
# Install (Debian/Ubuntu)
sudo apt update
sudo apt install -y chrony
# Configure: edit /etc/chrony/chrony.conf (example)
# Add or replace server lines:
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
# Start and enable
sudo systemctl enable --now chrony
# Check status
chronyc tracking
chronyc sources
Example chronyc output:
$ chronyc tracking
Reference ID : 1.2.3.4 (time1.example.org)
Stratum : 2
Leap status : Normal
System time : 0.000023 seconds slow of NTP time
Notes:
- "iburst" speeds up initial sync.
- chrony handles unstable networks and VMs better than older ntpd.
systemd-timesyncd (lightweight, good for desktops/containers)
# Enable and start (most modern systems have it installed)
sudo systemctl enable --now systemd-timesyncd
# Configure servers in /etc/systemd/timesyncd.conf
# Example:
[Time]
NTP=0.pool.ntp.org 1.pool.ntp.org
FallbackNTP=2.pool.ntp.org
# Check status
timedatectl timesync-status
timedatectl status
Example:
$ timedatectl timesync-status
Server: 1.pool.ntp.org (203.0.113.1)
Poll: 64s
Leap: normal
When to choose which:
- Use chrony for servers, VMs, and environments where network connectivity is intermittent.
- Use systemd-timesyncd for simple clients and lightweight containers.
- Avoid running multiple time daemons simultaneously (disable one before enabling another).
Verifying synchronization and troubleshooting
After configuration, verify time is synchronized and troubleshoot common issues like firewall blocks and conflicting services.
Basic checks:
# Is the service running?
sudo systemctl status chrony
sudo systemctl status systemd-timesyncd
# Show synchronization status (chrony)
chronyc tracking
chronyc sources
# Show NTP peers (ntpd)
ntpq -pn
# Check system clock
timedatectl status
date --utc
Firewall troubleshooting (example: open UDP 123):
# On systems using ufw
sudo ufw allow out 123/udp
sudo ufw allow in 123/udp # usually not needed for clients
# On systems using firewalld
sudo firewall-cmd --permanent --add-port=123/udp
sudo firewall-cmd --reload
Diagnose common network issues:
# Ping the NTP server
ping 0.pool.ntp.org
# Check UDP connectivity to port 123 with nmap
nmap -sU -p 123 0.pool.ntp.org
Commands reference table
| Command | Purpose |
|---|---|
| sudo apt install chrony | Install chrony on Debian/Ubuntu |
| sudo systemctl enable --now chrony | Start and enable chrony |
| chronyc tracking | Show chrony synchronization status |
| chronyc sources | List chrony sources and state |
| timedatectl status | Show system time and NTP status |
| timedatectl timesync-status | Show timesync server (systemd) |
| ntpq -pn | List NTP peers (ntpd) |
| sudo ufw allow out 123/udp | Allow NTP UDP out via ufw |
| sudo firewall-cmd --add-port=123/udp --permanent | Open NTP port in firewalld |
Troubleshooting tips:
- If no servers are reachable, check DNS resolution and UDP connectivity.
If multiple NTP services are running, stop and disable one to avoid conflicts:
sudo systemctl stop ntp
sudo systemctl disable ntp
If your offset is several seconds, chrony will usually slew the clock; very large offsets might be stepped at service start. To force a manual step:
sudo chronyc makestep
Common Pitfalls
- Running multiple time services at once (chrony, ntpd, systemd-timesyncd): this causes conflicts and unpredictable behavior — enable only one.
- Firewall blocking UDP 123: NTP uses UDP; forgetting to allow it (egress/inbound on local NTP servers) prevents synchronization.
- Using unreliable servers or only a single server: always configure multiple, geographically appropriate servers (use pool.ntp.org or an internal stratum 1 cluster).
Next Steps
- Monitor time stability: add a small monitoring check for offset (chronyc tracking) into your monitoring system.
- Harden NTP: restrict access to local clients if acting as a server, and consider using authentication (hardware/time sources) in sensitive environments.
- Document and automate: codify your NTP config (Ansible, Puppet, or shell scripts) so each host uses the same, tested servers and settings.
This tutorial gives you the practical commands and checks to get reliable time on Linux systems. Start with chrony on servers, verify with chronyc/timedatectl, and remember to open UDP 123 in firewalls and avoid multiple daemons.
👉 Explore more IT books and guides at dargslan.com.