How to Install and Configure NTP on Linux

Soban Malik
4 min readFeb 6, 2024

--

NTP, the Network Time Protocol, is used to keep computer clocks accurate by synchronizing them over the Internet or a local network, or by following an accurate hardware receiver that interprets GPS, DCF-77, NIST, or similar time signals.

NTP is available for most Linux distributions, indeed, many install NTP automatically in a default installation or ntpd(d for daemon background process).

If NTP is not present on your host system, it can be easily downloaded and installed. You will need root permissions to install the application. Installation also varies slightly depending on which Linux distribution you use:

Steps to configure and install NTP

sudo hostnamect

The hostnamectl command provides a proper API used to control the Linux system hostname and change its related settings. also helps to change the hostname without actually locating and editing the /etc/hostname file on a given system.

  Sudo apt update && sudo apt upgrade
  sudo apt-get install ntp   # for Debian/Ubuntu
sudo yum install ntp # for CentOS/RHEL
sudo dnf install ntp # for Fedora

Check ntp

dpkg -- get-selections ntp

Modify ntp.conf

Sudo nano /etc/ntpsec/ntp.conf
/var/lib/ntpsec/ntp.drift
leapfile /usr/share/zoneinfo/leap-seconds.list
statsdir /var/log/ntpsec/

drift file

The drift file is /var/lib/ntpsec/ntp.drift. This is fairly standard. For RH/Fedora, it’s /var/lib/ntp/drift.

The units for the drift file are “PPM”, or “parts per million”. Your clock will drift due to fluctuations in the frequency oscillating the quartz crystal on your motherboard. A fluctuation of just 0.001% (0.00001, or 10 PPM) means losing or gaining about 1 second per day. NTP has finer-grained control than that, so we look at errors of margin using 0.0001% (0.000001, or 1 PPM). Thus:

· 1 PPM = 1 part per million = 1 microsecond per second = 3.6ms per hour = 86.4ms per day

Thus, my drift file shows the value of “2.643” which means my clock is off by 2.643 parts per million, which means it’s currently off at 228.3552ms per day

Find keyword

https://www.ntppool.org/en/

go the the ntp site and search the region if you are in Asia then select Asia and these servers instead of the default servers

Enable NTP on Boot

systemctl enable ntp.service

Restart NTP service

systemctl restart ntp.service

Check it.

systemctl status ntp.service
OR
ntpq -pn

The command provides a list of configured peers and their associated synchronization performance characteristics.

The first character in the peer list is a tally code that indicates the status of synchronization. If the character is an asterisk (*), then the peer is currently being used for synchronization. This indicates that the local system clock is synchronized to the peer.

Tally code typical values:

‘*‘ – the peer has been declared the system peer and is used for synchronization.

‘+‘ – the peer is in tolerance and used in the combining algorithm. The peer may be used in the event of the system peer being discarded. Other characters generally indicate that the clock has been discarded by the selection algorithm.

Other fields in the peer list are as follows:

Remote – identifies the address of the peer.

Refid – indicates the synchronization source of the peer. Typically GPS or GNSS indicate a stratum 1 hardware clock. However, it may also be an address if the peer is a lower stratum in the NTP hierarchy. Stratum 1 is the highest level, and 15 is the lowest.

Type – the peer type – local, unicast, multicast or broadcast. Most peers are accessed in unicast mode.

When – when the last packet was received in seconds.

Poll – the period at which the peer is polled in seconds.

Reach – an octal representation of the synchronization flags.

Delay – the polling round trip delay in milliseconds.

Offset – the current offset, or time difference, between the peer and local system time.

Jitter – a measurement of variance of timing packets from the peer in milliseconds. This is an indication of clock quality. A lower jitter indicates a higher-quality clock.

--

--