How to Check NTP Status in Linux

Cover Image for How to Check NTP Status in Linux

Having accurate time on your Linux systems is important for everything from scheduled tasks to logging and analysis. The Network Time Protocol (NTP) is commonly used to synchronize time between servers and desktop computers.

In this beginner's guide, I'll explain the basics of NTP and show you how to check if it's working properly on your Linux machines.

What is NTP?

NTP is an Internet protocol used to synchronize the clocks of computers to some time reference. The reference clock can be a radio or atomic clock attached to a time server on the Internet. Using NTP, you can synchronize all the systems on your network to the same time source.

Some key advantages of using NTP include:

  • Accuracy - NTP typically keeps time accurate within 10-50 milliseconds on LANs and up to 100ms over the Internet.

  • Avoidance of drift - System clocks drift over time. NTP adjustments prevent long-term drift.

  • Easier log correlation - Common time on all systems allows for easier cross-system log analysis.

Now that you know why NTP is important, let's look at how to verify if NTP is working as expected on your Linux systems.

Check NTP Service Status

The first step is to check if the NTP service daemon itself is running. This background process manages the periodic time synchronization.

systemctl Status ntpd

On Systemd-based Linux distros like Ubuntu, RHEL, CentOS, etc you can check ntpd status with:

$ sudo systemctl status ntpd

This shows whether the ntpd service is running or not. If it's running properly, you'll see the main process ID and details that indicate an active status. If it wasn't running, you'd instead see an inactive or failed status.

So the service status gives you the first signal on whether NTP is actively running or not.

Check With ntpstat

Many Linux distributions ship with the ntpstat command that provides NTP status in a human-friendly way.

For example:

$ ntpstat
unsynchronised
  time server re-starting
   polling server every 8 s

This tells you directly if system time is synchronized to an NTP server or not.

If your distro doesn't have ntpstat, don't worry, keep reading for more NTP status commands coming up.

Verify NTP Sync With ntpq

The ntpq command lets you query the status of ntpd. It's available on pretty much all Linux distros.

ntpq -p

To check the general NTP sync status, use ntpq -p:

$ ntpq -p

Look for the asterisk (*) which indicates the primary system time source based on NTP daemon tracking. If you see a dot (.) instead, it implies no clocks are currently synchronized.

ntpq -c assoc

To query details about a particular NTP server, use -c assoc along with the host IP:

$ ntpq -c assoc <server_ip>

This shows the full tracking and performance stats for an individual NTP system you've configured. Metrics like reachability and delay values indicate how stable the connection is.

Check NTP Logs

If you want to inspect the NTP client activity in detail, check the system logs.

Journalctl

On Systemd distros, use journalctl to access logs:

$ sudo journalctl -fu ntpd

Look for mode changes (like going from step to synchronized), jump messages on large time skews, and other indicators of proper or faulty behavior.

/var/log

On other distros, grep traditional logs like /var/log/syslog:

$ grep ntpd /var/log/syslog

Logging is an easy way to review historical sync performance and troubleshoot issues.

Tune the Configuration

If you determine NTP sync is unstable or inaccurate, there are a number of tuning parameters you can adjust.

A few key settings to check include:

  • Server configuration - Are public Internet servers used? Does your network have local NTP sources? Redundancy and proper upstream time sources are vital.

  • ACLs - Allow/restrict access controls to lock down which hosts can query the NTP daemon.

  • Drift file - Persist last offset variance to improve between restarts.

  • Statistics logging - Enable stats writing for baseline analysis.

  • External clock - If very high accuracy is required, connect to GPS or atomic clock hardware.

Be careful and make gradual tweaks. Monitor status and logs to determine the effects of any ntp.conf changes.

Summary

Now you know the tools and techniques used to monitor NTP time synchronization status on Linux. Accurate consistent time is vital for modern server operations and deployments. Keep your Linux boxes in sync with these NTP troubleshooting tips.


Also read -

How to Check NTP Version in Linux

A Beginner's Guide to Using nslookup on Linux

Mounting NFS Shares from a Linux Server on Windows 2012