Linux online course

Configure an NTP Client on Linux

Learn to install and configure the legacy ntpd NTP client on Debian or Ubuntu, choose time servers, restart the service, and verify synchronization with ntpq.

Network Time Protocol (NTP) synchronizes a computer's system clock with authoritative or upstream time servers. An NTP client requests time from remote servers and disciplines its own clock; it does not provide time to other machines.

Accurate system time is important for ordered log entries, scheduled jobs, authentication systems, TLS certificate validation, monitoring alerts, backups, and distributed applications that exchange timestamps.

NTP Client Configuration Workflow

StepPurposeCommand or FileExpected Result

1. Check existing services — Find competing time daemons — systemctl status chrony systemd-timesyncd ntp — One intended synchronization service is selected.

2. Install ntpd — Install the daemon and utilities — sudo apt-get install ntp — The ntp package is installed.

3. Configure sources — Define upstream servers — /etc/ntp.conf — Pool or server entries are present.

4. Apply changes — Make ntpd reread its configuration — sudo service ntp reload — The daemon uses the revised settings.

5. Verify — Inspect peers and synchronization — ntpq -p — Reachable sources and, after polling, a selected source appear.

Install the NTP Daemon

The ntp package contains the legacy NTP daemon, commonly called ntpd, along with related utilities such as ntpq. Installing packages and managing services requires administrative privileges, normally provided through sudo.

sudo apt-get update
sudo apt-get install ntp

You can use the shorter modern form on Debian or Ubuntu systems:

sudo apt update
sudo apt install ntp

Before installing or starting ntpd, check whether another time service is already active. For example, chronyd and systemd-timesyncd may already be managing the clock. Two daemons can compete for control of time synchronization or required system resources, so stop or disable the unneeded service according to your operating policy before starting ntpd.

sudo systemctl status chrony
sudo systemctl status systemd-timesyncd
sudo systemctl status ntp

Edit /etc/ntp.conf

The primary configuration file for the legacy daemon is /etc/ntp.conf. Its pool and server directives identify upstream time sources.

Make a backup before editing:

sudo cp /etc/ntp.conf /etc/ntp.conf.backup

Open the file with a terminal text editor:

sudo nano /etc/ntp.conf

In nano, save with Ctrl+O, press Enter to confirm the filename, and exit with Ctrl+X. Preserve valid existing settings unless you have a reason to change them.

Choose Upstream NTP Servers

Use the distribution pool

A distribution commonly supplies default pool entries. An NTP pool is a DNS-based group of time servers. DNS can return different members of the group, giving the client several possible sources instead of depending on one fixed host.

pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst

The iburst option requests a short burst of initial queries so a newly started client can obtain useful measurements more quickly. Retaining the distribution's pool entries is suitable when they are allowed by your network and organization.

Use approved or internal servers

Organizations may require local, regional, or approved NTP sources. Replace or supplement pool entries with several reliable servers:

server ntp1.example.internal iburst
server ntp2.example.internal iburst
server ntp3.example.internal iburst

The names ending in .example.internal are placeholders. Substitute hostnames that your organization actually provides. Using multiple sources lets ntpd compare measurements and continue operating if one source fails.

Conceptually, server names a particular NTP source, while pool names a DNS-managed group from which several potential sources can be discovered. Hostnames require working DNS resolution. All sources also require network connectivity to NTP over UDP port 123.

Apply Configuration Changes

After saving /etc/ntp.conf, apply the changes. A reload asks the running service to reread its configuration without a full daemon restart:

sudo service ntp reload

If reload is unavailable or does not resolve the problem, restart the service. A restart stops and starts the daemon:

sudo service ntp restart

On a system using systemd, the equivalent restart command is:

sudo systemctl restart ntp

Check the service state if startup fails or if you want confirmation that the daemon is running:

sudo systemctl status ntp

Service names and management commands can vary between distributions and package versions. Use the service name reported by the installed package.

Verify Peers and Synchronization

Run ntpq -p to query the local daemon and display its configured upstream peers:

ntpq -p

A typical result resembles this terminal-style output:

     remote           refid      st t when poll reach   delay   offset  jitter
=============================================================================
*ntp1.example.net  .GPS.        2 u   32   64   377    12.4    -0.31    0.45
+ntp2.example.net  .PPS.        2 u   28   64   377    15.1     0.18    0.62
-ntp3.example.net  .ATOM.       3 u   30   64   377    21.7     1.24    1.10

The character at the beginning of a peer row is a selection marker. An asterisk (*) identifies the source currently selected for synchronization. A plus sign (+) indicates a usable candidate, while a minus sign (-) indicates a source that is reachable but less suitable than the selected candidates. Exact markers can vary as measurements change.

Key ntpq -p fields

FieldMeaningWhat healthy output usually indicates

remote — The configured upstream host or pool member — A source name or address is listed.

refid — The reference clock or upstream identity reported by that source — The source reports a meaningful reference rather than an unavailable value.

st or stratum — Distance from a reference clock; lower valid values generally indicate a source closer to the reference — A reachable source has a sensible finite stratum.

poll — Poll interval in seconds — The daemon is polling at an interval appropriate to its current state.

reach — A recent communication reachability register — A nonzero value, often increasing toward 377 in octal, shows recent successful responses.

delay — Estimated network round-trip delay, usually in milliseconds — The value is present and reasonably stable for the network.

offset — Measured difference between the local clock and the source — The value is present and generally small or converging.

jitter — Variation in successive timing measurements — A lower, stable value generally indicates consistent measurements.

A newly started client may need several polling intervals before it has enough samples to select a source and report stable values. Do not treat the absence of an asterisk immediately after startup as conclusive failure.

Time Synchronization Service Considerations

ServiceTypical configuration methodCoexistence guidance

ntpd/etc/ntp.conf, managed as the ntp service — Use it as the single active clock-synchronization daemon when following this lesson.

chronyd — Chrony-specific configuration and service management — Stop or disable it before using ntpd, unless your design explicitly supports another arrangement.

systemd-timesyncd — Systemd configuration and service management — Do not leave it competing with ntpd for clock synchronization.

Troubleshooting

No reachable peers or a reach value of zero

  • Check the server and pool lines in /etc/ntp.conf.
  • Verify DNS resolution when hostnames are configured.
  • Confirm that the machine has a route to the upstream servers.
  • Check local and network firewall rules. NTP uses UDP port 123, and outbound filtering can block synchronization.
  • Restart the service after correcting the configuration.

The service fails to start

  • Inspect the service status and system logs for the specific error.
  • Check whether chronyd or systemd-timesyncd is active.
  • Review recent edits for configuration syntax errors.
  • Confirm the installed package and service name if commands behave differently on the host.

Peers are listed but no source is selected

  • Allow additional polling intervals so the daemon can collect samples.
  • Review reachability, offset, jitter, and selection markers.
  • Use multiple reliable sources rather than one server.
  • Check whether the local clock is far from correct or whether the configured sources disagree substantially.

Time remains inaccurate

  • Confirm that the service was reloaded or restarted after editing the file.
  • Run ntpq -p and verify that a reachable source is selected.
  • Identify whether another time service is actually controlling the clock.
  • Be cautious when making large clock corrections: abrupt changes can affect scheduled tasks, log ordering, authentication, TLS validation, and other time-sensitive applications.

Exam-Relevant Notes

  • NTP means Network Time Protocol.
  • An NTP client obtains time from upstream servers and disciplines its local clock; it is not automatically an NTP server for other machines.
  • ntpd is the legacy daemon, ntp is the Debian or Ubuntu package, and /etc/ntp.conf is its primary configuration file.
  • pool refers to a DNS-based group of possible time servers; server refers to a specified time source.
  • ntpq -p displays peers. The leading * marks the current synchronization source.
  • NTP communication uses UDP port 123.
  • Run only one primary clock-synchronization implementation, such as ntpd, chronyd, or systemd-timesyncd.

For related Linux fundamentals, see Linux, Show the Full Path of Shell Commands, and Bourne Again Shell Bash.