How to Configure ntpd on Ubuntu: Reliable Time Synchronization for Stable Systems

目次

1. Introduction: Why Time Synchronization Matters

Problems Caused by System Time Drift

On Linux systems such as Ubuntu, maintaining accurate system time is critically important. At first glance, a small clock discrepancy may seem trivial, but in server operations and application environments, even minor time drift can lead to serious issues.

For example, the following problems may occur:

  • Loss of log consistency
    If timestamps in system or application logs are misaligned, it becomes difficult to identify the root cause of incidents.
  • Malfunctioning cron jobs
    Scheduled tasks such as backups or batch jobs may not run at the correct time, causing unexpected behavior.
  • SSL certificate and security authentication failures
    HTTPS communications and SSH authentication rely on accurate system time. If the clock is incorrect, certificates may be judged as “expired” or “not yet valid,” resulting in connection errors.

These issues become especially serious when multiple servers must be synchronized across a network.

The Role and Importance of NTP

To prevent such problems, NTP (Network Time Protocol) is used. NTP communicates with time servers over the internet or a local network and automatically corrects the system clock.

On Ubuntu, several NTP-related tools are available, including ntpd, chrony, and systemd-timesyncd. In this article, we focus on ntpd (Network Time Protocol daemon) and explain in detail how to install and use it on Ubuntu.

For servers that run continuously over long periods or systems where log consistency is essential, ntpd is highly regarded for its stability.

In the next section, we begin by explaining what ntpd is, its core role, and the available options on Ubuntu.

2. What Is ntpd? Its Role and Alternatives on Ubuntu

Overview and Features of ntpd

ntpd (Network Time Protocol Daemon) is a background service that keeps system time accurate using NTP. It periodically communicates with NTP servers on the internet or local network and automatically adjusts the system clock.

A key feature of ntpd is its ability to perform “smooth synchronization,” gradually correcting time drift rather than making abrupt changes. This design prevents negative impacts on running systems and applications.

ntpd also supports advanced NTP features such as symmetric communication and authentication, making it suitable for enterprise environments.

Time Synchronization Tools Available on Ubuntu

Ubuntu provides several options for time synchronization:

  • ntpd (ntp package)
    Widely used in long-term operations and environments requiring detailed configuration. It offers high flexibility and stability and can synchronize accurately with public NTP servers.
  • chrony
    A modern alternative to ntpd with high accuracy and very fast initial synchronization. It works well on low-spec systems and virtual machines, and many distributions now use it by default.
  • systemd-timesyncd
    A lightweight time synchronization service enabled by default on Ubuntu 20.04 and later. It is simple and convenient but limited in functionality and not suitable for advanced configurations or running a local NTP server.

Why Choose ntpd?

The primary reason to choose ntpd on Ubuntu is its reliability and stability. It is especially suitable in the following scenarios:

  • Servers running continuously for long periods where time accuracy is critical
  • Environments that require building a local NTP server within a network
  • Enterprise use cases requiring authentication and fine-grained control

Because ntpd has a long operational history and broad compatibility, it offers peace of mind during deployment.

3. Installing and Initial Configuration of ntpd on Ubuntu

Installing ntpd

To use ntpd on Ubuntu, you must first install the ntp package. This can be done easily with the following commands:

sudo apt update
sudo apt install ntp

This installs ntpd and its related files. Depending on your Ubuntu version, chrony or systemd-timesyncd may be enabled by default. In such cases, it is recommended to disable or remove them in advance.

sudo systemctl stop systemd-timesyncd
sudo systemctl disable systemd-timesyncd

Enabling the Service and Verifying Startup

After installation, enable the ntpd service and verify that it is running:

sudo systemctl enable ntp
sudo systemctl start ntp
sudo systemctl status ntp

If the status shows active (running), ntpd is operating correctly.

Checking and Editing the Initial Configuration File

The ntpd configuration is defined in /etc/ntp.conf. By default, several NTP servers (usually from the pool.ntp.org network) are configured.

First, review the configuration file:

cat /etc/ntp.conf

If you want to specify servers located in Japan, you can edit the configuration as follows:

server ntp.nict.jp iburst

The iburst option improves synchronization speed during the initial connection and is recommended.

After making changes, restart ntpd to apply them:

sudo systemctl restart ntp

Verifying Automatic Time Synchronization

ntpd automatically synchronizes time after startup. To verify correct operation, use the following command:

ntpq -p

This command displays a list of connected NTP servers along with delay, offset, and other detailed information.

4. Configuring and Customizing NTP Servers

Selecting Recommended NTP Servers

One of the most important aspects of configuring ntpd is selecting which NTP servers to synchronize with. When connecting over the internet, specifying reliable NTP servers located geographically close—such as domestic servers—can provide more stable and accurate time synchronization.

Representative NTP servers in Japan include:

  • ntp.nict.jp (National Institute of Information and Communications Technology)
  • ntp.jst.mfeed.ad.jp (JST / Mfeed)
  • ntp.ring.gr.jp (Internet Multi Feed)

These servers are operated based on high-precision atomic clocks and can be used for personal purposes without special registration.

You can configure synchronization with these servers by adding the following entries to /etc/ntp.conf:

server ntp.nict.jp iburst
server ntp.jst.mfeed.ad.jp iburst
server ntp.ring.gr.jp iburst

Detailed Configuration Options in ntp.conf

The /etc/ntp.conf file allows fine-grained control beyond simply specifying NTP servers. Below are some commonly used directives.

  • restrict directive
    Controls which clients are allowed or restricted from accessing the NTP service. For security reasons, unnecessary access should be limited. Example: allowing access from a local network.
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
  • driftfile
    Specifies the file used to record system clock drift. In most cases, the default setting is sufficient.
driftfile /var/lib/ntp/ntp.drift

Building a Local NTP Server Within a Network

By using ntpd on Ubuntu, you can also operate the system as a local NTP server that distributes time to other devices on an internal network. This configuration is useful in environments without internet access or where consistent time management across multiple systems is required.

An example setup procedure is as follows:

  1. Add a restrict rule to /etc/ntp.conf to allow local access: restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
  2. Configure client PCs to reference the local NTP server: server 192.168.0.10 iburst # Local IP of the NTP server
  3. Allow the NTP port on the server (permit UDP port 123 in the firewall): sudo ufw allow 123/udp

If communication is blocked, time synchronization will fail, and the ntpq command will not show a connection to the server.

5. Verifying Operation and Troubleshooting ntpd

Checking Service Status

To confirm whether ntpd is running correctly, use the following command:

sudo systemctl status ntp

If active (running) is displayed, ntpd is operating normally. If the status is inactive or failed, a configuration error or dependency issue may be preventing startup.

For detailed logs, the following command is useful:

journalctl -u ntp

This allows you to review startup history and error messages for the ntpd service in chronological order.

Checking Synchronization Status (ntpq -p)

The ntpq -p command is most commonly used to verify whether ntpd is synchronizing properly with NTP servers.

ntpq -p

Example output:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp.nict.jp     .NICT.           1 u   25   64  377    1.123   -0.345   0.024

The meaning of each column is as follows:

  • remote: Name of the connected NTP server
  • st: Server stratum (lower is more accurate; 1 indicates an atomic clock reference)
  • reach: Reachability register (8-bit history)
  • delay: Network delay (ms)
  • offset: Time offset (ms)
  • jitter: Variation in offset

A server marked with * is currently selected as the synchronization source.

Common Errors and How to Fix Them

Below are common issues encountered when deploying ntpd and their corresponding solutions.

1. No output from ntpq -p / reach remains 0

  • Cause: UDP port 123 may be blocked by a firewall or router
  • Solution: Verify firewall settings on both the server and client to ensure NTP traffic is allowed.
sudo ufw allow 123/udp

2. System clock not synchronized is displayed

  • Cause: ntpd is not running, or another synchronization service (such as systemd-timesyncd) is conflicting
  • Solution: Disable unnecessary time synchronization services and restart ntpd.
sudo systemctl disable systemd-timesyncd
sudo systemctl restart ntp

3. Failure to resolve NTP server names

  • Cause: DNS configuration issues or network problems
  • Solution: Check name resolution using commands like ping ntp.nict.jp and adjust DNS settings if necessary.

4. Time is significantly off and does not synchronize

  • Cause: For safety reasons, ntpd does not automatically correct very large time offsets
  • Solution: Manually correct the initial time, then restart ntpd.
sudo ntpd -gq  # Perform a one-time immediate synchronization
sudo systemctl restart ntp

For Continuous Monitoring

In production environments, it is recommended to periodically log the output of ntpq -p and set up alerts for anomalies. Detecting signs such as missing logs or a reach value consistently stuck at 0 enables early identification of failures.

6. Comparing ntpd with Other Time Synchronization Tools

Major Time Synchronization Tools on Ubuntu

Ubuntu offers multiple tools for time synchronization, each with distinct characteristics. Selecting the right tool depends on your system requirements and use case.

  • ntpd (ntp package)
  • chrony
  • systemd-timesyncd

Characteristics of ntpd

  • Advantages
  • Proven stability and reliability backed by long operational history
  • Rich feature set with fine-grained configuration options (local NTP servers, authentication, symmetric mode)
  • High compatibility with public NTP servers and extensive troubleshooting resources
  • Disadvantages
  • Initial synchronization after startup can be slow
  • Less adaptable to modern environments such as virtualization and highly variable networks

Characteristics of chrony

  • Advantages
  • Very fast initial synchronization, even immediately after boot
  • High accuracy in virtualized or variable network environments (laptops, VPNs)
  • Adaptive learning improves accuracy over time, sometimes outperforming ntpd
  • Disadvantages
  • Slightly more complex configuration when used as a local NTP server
  • Less documentation and fewer real-world examples compared to ntpd

Characteristics of systemd-timesyncd

  • Advantages
  • Enabled by default on Ubuntu 20.04 and later, extremely easy to manage
  • Minimal resource consumption with basic synchronization functionality
  • Well integrated with systemd and suitable for standard Ubuntu setups
  • Disadvantages
  • Limited features; advanced configuration and local NTP server operation are not supported
  • Accuracy and logging capabilities are basic, making it unsuitable for large-scale systems

Comparison Table

Featurentpdchronysystemd-timesyncd
AccuracyHighVery HighModerate
Initial Sync SpeedSometimes SlowVery FastModerate
Local NTP ServerExcellentGood (More Complex)Not Supported
Configuration FlexibilityHighMediumLow
Virtual Environment SupportLimitedExcellentGood
Operational History & ResourcesExcellentGoodLimited
Recommended Use CasesServers, Organization-wide SyncVirtual Environments, LaptopsSingle PCs, Beginners

Recommended Tools by Use Case

  • Server environments (especially always-on systems)
    ntpd or chrony for stability and accuracy.
  • Cloud environments, virtual machines, laptops
    chrony offers the most flexibility and precision.
  • Single PCs with basic synchronization needs
    systemd-timesyncd is sufficient.

7. Frequently Asked Questions (FAQ)

Q1. Is ntpd installed by default on Ubuntu 22.04?

A1.
No. On Ubuntu 22.04, ntpd is not installed by default. Instead, systemd-timesyncd is enabled for basic time synchronization. To use ntpd, you must explicitly install the ntp package.

sudo apt install ntp

After installation, disabling systemd-timesyncd helps avoid conflicts.

Q2. Why does ntpq -p not display any results?

A2.
Several causes are possible:

  • The service is not running: Check with sudo systemctl status ntp and start it if necessary
  • No communication with NTP servers: Ensure that UDP port 123 is not blocked by a firewall
  • Configuration errors: Verify that /etc/ntp.conf contains no mistakes

Start by running the following command to check basic operation:

ntpq -p

If the output is empty or reach remains 0, external server communication is likely failing.

Q3. Should I choose ntpd or chrony?

A3.
The optimal choice depends on your environment:

  • Long-running physical servers or local NTP server setupsntpd is recommended for stability
  • Virtual environments, laptops, or variable networks (Wi-Fi)chrony provides better accuracy and faster sync
  • Simple time synchronization onlysystemd-timesyncd is sufficient

Q4. What does the ntpd -gq command do?

A4.
ntpd -gq performs a one-time synchronization with an NTP server and then exits.

  • -g: Allows correction even if the time offset is large
  • -q: Synchronizes once and quits (does not run as a daemon)

This command is useful when the system time is significantly incorrect and normal ntpd operation will not adjust it automatically.

Q5. Is there a benefit to specifying multiple NTP servers?

A5.
Yes. Specifying multiple NTP servers improves redundancy and reliability. If one server becomes unavailable, the system can continue synchronizing with others.

Example configuration in /etc/ntp.conf:

server ntp.nict.jp iburst
server ntp.jst.mfeed.ad.jp iburst
server ntp.ring.gr.jp iburst

8. Conclusion: Improving System Reliability Through Stable Time Synchronization

Revisiting the Value of ntpd

On Ubuntu systems, accurate time synchronization is not merely a convenience—it directly impacts security, troubleshooting, log management, and the correctness of automated processes.

This article has provided a comprehensive overview of NTP fundamentals, how time synchronization works with ntpd, installation and configuration steps, customization options, verification and troubleshooting methods, and comparisons with alternative tools.

Advice for Readers

The choice of time synchronization tool on Ubuntu depends on system purpose, architecture, and availability requirements.
However, the principle remains universal: without accurate time, stable system operation is impossible.

  • Server environments and log-intensive systems → Carefully configure ntpd or chrony
  • Single systems with simple requirements → Use systemd-timesyncd for quick setup

Although time synchronization issues are often unnoticed in daily operations, they become a critical differentiator when troubleshooting incidents.

Use this guide to build a time synchronization setup that best suits your Ubuntu environment.

侍エンジニア塾