LinuxCommandLibrary

ntpd

Synchronize system clock with NTP servers

TLDR

Start the daemon

$ sudo ntpd
copy

Synchronize system time with remote servers a single time (quit after synchronizing)
$ sudo ntpd --quit
copy

Synchronize a single time allowing "Big" adjustments
$ sudo ntpd --panicgate --quit
copy

SYNOPSIS

ntpd [options]
ntpd [-c config_file] [-f drift_file] [-gq] [-d]

PARAMETERS

-c
    Specifies an alternate NTP configuration file path instead of the default /etc/ntp.conf.

-f
    Specifies an alternate NTP drift file path to store clock frequency offset.

-g
    Performs an initial clock synchronization, even if the offset is large, then exits if -q is also specified.

-q
    Queries servers and sets the time, then exits. Useful for one-time synchronization.

-d
    Enables debugging mode. Output is sent to standard error, and the daemon does not fork.

-n
    Prevents ntpd from forking into the background. It runs in the foreground.

-u [:group]
    Specifies the user and optional group to which ntpd should switch after initialization for security.

DESCRIPTION

ntpd is the reference implementation of the Network Time Protocol (NTP), a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks.
It runs as a daemon, continuously adjusting the system clock to synchronize with remote NTP servers, ensuring highly accurate timekeeping.

Accurate system time is critical for a multitude of reasons, including correct logging, secure authentication (e.g., Kerberos), data consistency in distributed systems, and proper functioning of cron jobs and certificate validation. ntpd achieves this by using complex algorithms to select the best time sources, minimize network latency effects (jitter), and precisely compensate for local clock drift.

Typically, ntpd is configured via the /etc/ntp.conf file, which specifies NTP servers, access restrictions, and logging options. It can operate in various modes: as a client requesting time from servers, as a server providing time to clients, or as both. It can also manage a local clock source (e.g., GPS receiver) and operate in a peer-to-peer fashion. ntpd is fundamental for maintaining time accuracy across networks, from small local area networks to the global internet.

CAVEATS

ntpd typically requires root privileges to bind to privileged ports (UDP 123) and to adjust the system clock.
While robust, configuring ntpd for optimal performance and security can be complex, especially with access restrictions.
On modern Linux systems, chronyd (from the chrony project) is often recommended as an alternative to ntpd due to its faster synchronization times, better performance on intermittently connected systems, and lower resource consumption.

CONFIGURATION FILE (<I>/ETC/NTP.CONF</I>)

The primary configuration for ntpd is read from /etc/ntp.conf (or a path specified by -c). This file defines NTP servers to query, access restrictions, logging options, and other operational parameters. Key directives include server (to specify upstream time sources), restrict (for access control), driftfile (to store clock frequency offset), and logfile (for logging daemon activity).

DRIFT FILE

The drift file (typically /var/lib/ntp/ntp.drift or /var/lib/ntp/drift/ntp.drift) is used by ntpd to store the estimated frequency offset of the local system clock. This allows the daemon to quickly correct for clock drift even when not synchronized with an NTP server, reducing initial synchronization time and improving accuracy.

SECURITY CONSIDERATIONS

NTP services can be exploited in denial-of-service (DoS) attacks, particularly amplification attacks. It is crucial to properly configure restrict directives in ntp.conf to limit access to your NTP server, preventing unauthorized queries and abuse. Public NTP servers should follow best practices for security hardening.

HISTORY

The Network Time Protocol (NTP) and its reference implementation, ntpd, were developed by David L. Mills at the University of Delaware, beginning in the early 1980s. NTP has evolved through several versions (NTPv1, v2, v3, and the current NTPv4), becoming a cornerstone of internet infrastructure for precise timekeeping. ntpd has been the standard daemon for NTP synchronization on Unix-like systems for decades, providing a robust and highly accurate method for maintaining system clocks. Its long history underscores its fundamental role in ensuring consistent time across distributed systems and the global internet.

SEE ALSO

ntpq(1), ntpdate(8), ntpstat(8), chronyd(8), timedatectl(1), hwclock(8)

Copied to clipboard