When dealing with virtual machines, clock drift becomes a significant concern due to the nature of virtualized hardware. The standard NTPD configuration often proves insufficient for maintaining precise time synchronization in such environments.
The primary parameters we need to adjust in /etc/ntp.conf
are:
# Force more frequent synchronization server ntp.example.com minpoll 4 maxpoll 4 iburst tinker panic 0
Let's examine each component in detail:
# The server directive with poll adjustments server 0.pool.ntp.org minpoll 4 maxpoll 4 iburst server 1.pool.ntp.org minpoll 4 maxpoll 4 iburst server 2.pool.ntp.org minpoll 4 maxpoll 4 iburst server 3.pool.ntp.org minpoll 4 maxpoll 4 iburst # Disable panic threshold tinker panic 0 # Reduce the minimum adjustment threshold tinker step 0.1 tinker stepout 1
For virtual environments, additional measures are often necessary:
# Enable kernel discipline disable kernel # Set tighter synchronization parameters tos maxdist 30 tos mindist 0.001 tos maxclock 100
After implementing these changes, verify with:
ntpq -pn ntpstat watch -n 1 ntptime
For extreme cases, consider switching to chrony which handles VM clock drift better:
pool ntp.example.com iburst maxsamples 8 makestep 1.0 3 driftfile /var/lib/chrony/drift rtcsync
Be aware that more frequent synchronization increases:
- Network traffic
- CPU usage
- Potential for NTP server abuse
When working with virtual machines, particularly in cloud environments, clock drift becomes a significant issue. The virtualized hardware clock tends to drift much faster than physical hardware - sometimes several milliseconds per minute. Standard NTPD configurations aren't designed to handle this aggressive drift pattern.
By default, ntpd:
- Uses a minpoll of 6 (64 seconds) and maxpoll of 10 (1024 seconds)
- Gradually adjusts the clock to avoid sudden jumps
- May ignore small time differences to maintain stability
The key configuration parameters we'll focus on:
# /etc/ntp.conf tinker panic 0 # Disable panic threshold tinker step 0.1 # Allow smaller time adjustments
To make ntpd adjust the system clock more aggressively:
# /etc/ntp.conf server ntp.example.com iburst minpoll 4 maxpoll 4 driftfile /var/lib/ntp/drift tinker allan 0 tinker dispersion 0.1 tinker step 0.01
For VMs, we need to combine NTPD with other tools:
# Install additional tools sudo apt-get install chrony # Chrony configuration (/etc/chrony/chrony.conf) makestep 0.1 3 local stratum 10
Check the adjustment frequency:
ntpq -p ntpstat grep adjust /var/log/syslog
Look for lines containing "time reset" or "step time" in your system logs to confirm the increased adjustment frequency.
For systems with systemd:
sudo timedatectl set-ntp false sudo timedatectl set-ntp true sudo systemctl restart ntp
This forces an immediate resync and can help when drift becomes excessive.