- 1 1. Introduction: Why Time Synchronization Matters
- 2 2. What is ntpd? Its Role and Options in Ubuntu
- 3 3. Installing and Initial Setup of ntpd on Ubuntu
- 4 4. Configuring and Customizing NTP Servers
- 5 5. Verifying ntpd Operation and Troubleshooting
- 6 6. Comparison of ntpd with Other Time Synchronization Tools
- 7 7. Frequently Asked Questions (FAQ)
- 8 8. Conclusion: Improve System Reliability with Stable Time Synchronization
1. Introduction: Why Time Synchronization Matters
Problems Caused by System Clock Drift
In Linux systems, including Ubuntu, maintaining accurate time is crucial. While it might seem like a minor issue of clock inaccuracies, time drift can lead to critical problems in server operation and application execution environments.
For example, the following issues can occur:
- Inconsistent Logs
If the timestamps in system logs and application logs are misaligned, it becomes difficult to pinpoint the cause of problems during troubleshooting. - Malfunctioning cron Jobs
Scheduled tasks (like backups and batch processing) might not execute at the correct times, potentially running at unexpected moments. - SSL Certificate and Security Authentication Failures
Accurate time information is necessary for HTTPS communication and SSH authentication. If the system time is incorrect, certificates might be deemed “expired,” leading to connection errors.
These issues can have a particularly severe impact when operating multiple servers synchronized over a network.
The Role and Importance of NTP
To prevent such problems, NTP (Network Time Protocol) is used. NTP communicates with time servers on the internet or a local network to automatically correct the system’s time.
Ubuntu offers several NTP-related tools, including ntpd, chrony, and systemd-timesyncd. This article will focus on ntpd (Network Time Protocol daemon), providing a detailed explanation of its installation and utilization on Ubuntu.
Especially for servers intended for long-term operation and systems requiring log consistency, the stability of ntpd is highly regarded.
The next chapter will introduce what ntpd is, its basic roles, and the available options in Ubuntu.
2. What is ntpd? Its Role and Options in Ubuntu
Overview and Features of ntpd
ntpd
(Network Time Protocol Daemon) is a daemon program that uses NTP to maintain accurate system time. It periodically communicates with NTP servers on the internet or a local network and automatically adjusts the system clock.
A key feature of ntpd is its “smooth synchronization,” which gradually corrects time differences. This design avoids abrupt time changes that could negatively impact running systems and applications.
Furthermore, ntpd supports advanced NTP features such as symmetric active mode and authentication, making it a robust time synchronization service suitable for enterprise environments.
Time Synchronization Tools Available in Ubuntu
Ubuntu offers the following options for time synchronization:
- ntpd (ntp package)
Widely used in environments requiring long-term operation and detailed configuration. It offers excellent flexibility and stability, enabling high-precision time synchronization by connecting with public NTP servers. - chrony
An alternative to ntpd that has gained attention for its high accuracy and fast synchronization speed after startup. It works well in low-spec environments and virtual machines, and many modern distributions are adopting chrony as the default. - systemd-timesyncd
A lightweight time synchronization service enabled by default in Ubuntu 20.04 and later. It’s simple and easy to use, but its features are limited, making it unsuitable for advanced configurations or operating as a local NTP server.
Reasons for Choosing ntpd and Its Advantages
The primary reason for adopting ntpd in Ubuntu is its reliability and stability. It is a strong choice, especially in the following cases:
- When high time accuracy is required for long-running servers.
- When you want to build an NTP server within a local network.
- For enterprise applications requiring authentication and advanced control.
Furthermore, ntpd has the advantage of being compatible with many existing systems and having a proven track record, which reduces concerns during implementation.
3. Installing and Initial Setup of ntpd on Ubuntu
ntpd Installation Procedure
To use ntpd on Ubuntu, you first need to install the ntp
package. You can easily install it using the following steps:
sudo apt update
sudo apt install ntp
This command will automatically install ntpd
and its related files. Note that on some versions of Ubuntu, chrony
or systemd-timesyncd
might be enabled by default. In such cases, it is recommended to disable or remove them beforehand.
sudo systemctl stop systemd-timesyncd
sudo systemctl disable systemd-timesyncd
Enabling the Service and Verifying Startup
Once the installation is complete, enable the ntpd service and check its startup status.
sudo systemctl enable ntp
sudo systemctl start ntp
sudo systemctl status ntp
If the status
command shows “active (running),” it means ntpd has started successfully.
Checking and Editing the Initial Configuration File
The ntpd configuration is defined in the /etc/ntp.conf
file. The default configuration after installation includes several default NTP servers (usually from the pool.ntp.org series).
First, let’s check the contents of the configuration file.
cat /etc/ntp.conf
If you want to specify servers in the United States, you can edit it as follows:
server us.pool.ntp.org iburst
The iburst
option is recommended as it improves the synchronization speed during the initial connection.
After making changes to the configuration, restart the ntpd service to apply them.
sudo systemctl restart ntp
Verifying Automatic System Time Synchronization
After starting, ntpd automatically synchronizes the time with the server. To check if it’s working correctly, the following command is useful:
ntpq -p
This command allows you to view a list of connected NTP servers and detailed information such as delay and offset.
4. Configuring and Customizing NTP Servers
Selecting Recommended NTP Servers
An important aspect of ntpd configuration is selecting which NTP servers to synchronize with. When connecting via the internet, specifying reliable NTP servers in the United States can ensure more stable time synchronization.
Typical public NTP servers in the US include:
us.pool.ntp.org
(A pool of NTP servers in the United States)- You can also find regional pools like
north-america.pool.ntp.org
or specific state pools if needed.
These servers are operated based on high-precision atomic clocks and can be used for personal use without special permission.
You can configure synchronization with these servers by writing the following in /etc/ntp.conf
:
server us.pool.ntp.org iburst
server north-america.pool.ntp.org iburst
Detailed Configuration Items in ntp.conf
In addition to specifying NTP servers, /etc/ntp.conf
allows for fine-grained control of ntpd’s behavior. Here are some typical configuration items:
- restrict directive
Sets restrictions and permissions for connections from clients. For security reasons, unnecessary connections should be restricted. Example: Allowing connections from the local network
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
- driftfile
Specifies the file that records the system clock’s drift (subtle deviations). Usually, the default setting is fine.
driftfile /var/lib/ntp/ntp.drift

Building an NTP Server Within a Local Network
You can also use ntpd on Ubuntu to operate as an NTP server that distributes time to other devices within your local network. This configuration is effective in environments without internet access or where consistent time management across multiple devices is required.
Here’s an example of the configuration procedure:
- Add a
restrict
rule to/etc/ntp.conf
to allow local access:restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
- On client PCs, configure them to refer to this local NTP server:
server 192.168.1.10 iburst # Local IP of the NTP server
- Open the NTP server’s port (allow 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 the connection status with the server.
5. Verifying ntpd Operation and Troubleshooting
How to Check the Service Status
To verify that ntpd is running correctly, use the following command:
sudo systemctl status ntp
If it displays active (running)
, ntpd is operating normally. If it shows inactive
or failed
, there might be a configuration error or a dependency issue preventing it from starting.
To check the logs in detail, the following command is helpful:
journalctl -u ntp
This allows you to view the startup history and error messages of the ntpd service in chronological order.
Command to Check Synchronization Status (ntpq -p)
The ntpq -p
command is most commonly used to check if ntpd is properly synchronizingwith NTP servers.
ntpq -p
Example output:
remote refid st t when poll reach delay offset jitter
==============================================================================
*time.cloudflare. 172.64.250.202 2 u 57 64 377 0.876 -0.012 0.009
+ntp.ubuntu.com 170.247.169.130 2 u 49 64 377 1.234 +0.056 0.015
stratum2.ntp.br 162.229.5.20 2 u 51 64 377 105.234 -0.123 0.021
LOCAL(0) .LOCL. 10 l -- 64 0 0.000 0.000 0.000
The meanings of each column are as follows:
remote
: The name of the connected NTP serverst
: The server’s stratum (hierarchy level), where 1 is the most accurate (e.g., atomic clock)reach
: An 8-bit shift register indicating the success history of the last eight connection attemptsdelay
: The network round-trip delay in milliseconds (ms)offset
: The time difference between your system and the server in milliseconds (ms)jitter
: The statistical variance of the offset over several samples
The server with an asterisk (*
) at the beginning is the currently selected synchronization source.
Common Errors and Their Solutions
Here are some common errors you might encounter when implementing ntpd and their corresponding solutions:
1. Nothing displayed with ntpq -p
/ reach
is 0
- Cause: UDP port 123 might be blocked by a firewall or router.
- Solution: Check the firewall settings on both the server and the client to ensure that NTP traffic is allowed.
sudo ufw allow 123/udp
2. System clock not synchronized
is displayed
- Cause: ntpd might not be running, or it might be conflicting with another synchronization service (like systemd-timesyncd).
- Solution: Disable any unnecessary time synchronization services and restart ntpd.
sudo systemctl disable systemd-timesyncd
sudo systemctl restart ntp
3. Failed to resolve NTP server names
- Cause: DNS configuration issues or network problems.
- Solution: Check if name resolution is working (e.g., using
ping us.pool.ntp.org
) and correct the DNS server settings if necessary.
4. Time is significantly off but not synchronizing
- Cause: ntpd does not automatically adjust the time if the difference is too large (for safety reasons).
- Solution: Manually set the initial time and then restart ntpd.
sudo ntpd -gq # Perform an immediate synchronization once
sudo systemctl restart ntp
For Continuous Monitoring
In a production environment, it’s wise to set up a script to periodically log the output of ntpq -p
and create alerts for anomalies. Noticing sudden breaks in the logs or a consistently low reach
value can help in early detection of issues.
6. Comparison of ntpd with Other Time Synchronization Tools
Major Time Synchronization Tools Used in Ubuntu
Several tools are available for time synchronization in Ubuntu environments. Each has its own characteristics, and the choice depends on the intended use and system requirements. The three main tools are:
- ntpd (ntp package)
- chrony
- systemd-timesyncd
Understanding the differences between them will help you choose the optimal synchronization method for your environment.
Features of ntpd
- Pros
- Long-standing and stable with very high reliability.
- Rich in features and allows for detailed configuration (local NTP server setup, authentication, symmetric modes, etc.).
- Highly compatible with public NTP servers, with abundant troubleshooting information available.
- Cons
- Initial synchronization after startup can sometimes take a while.
- Adaptability to modern network environments (virtualization, variable networks) is somewhat lower.
Features of chrony
- Pros
- Fast initial synchronization, quickly correcting time differences after boot.
- High accuracy even in virtual machines and variable network environments (laptops, VPN usage).
- Autonomous learning capabilities (improves accuracy based on surrounding conditions), often providing better accuracy than ntpd.
- Cons
- Configuration for operating as a local NTP server is slightly more complex.
- Documentation and examples are fewer compared to ntpd.
Features of systemd-timesyncd
- Pros
- Enabled by default in Ubuntu 20.04 and later, very easy to install and manage.
- Minimal synchronization features with very low resource consumption.
- Well-integrated with systemd, making it easy to use with standard Ubuntu configurations.
- Cons
- Limited functionality, cannot be used for advanced manual configurations or as a local NTP server.
- Accuracy and logging features are basic, not suitable for large-scale systems.
Tool Comparison Table (Summary)
Feature | ntpd | chrony | systemd-timesyncd |
---|---|---|---|
Accuracy | High | Very High | Normal |
Initial Sync Speed | Can be slow | Very Fast | Normal |
Local NTP Server | ◎ | ○ (Slightly complex) | × (Not possible) |
Configuration Flexibility | High | Medium | Low |
Adaptability to Virtual Environments | △ | ◎ | ○ |
Proven Track Record & Information | ◎ | ○ | △ |
Recommended Use Cases | Servers, organizational uniformity | Virtual environments, laptops | Single PCs, beginners |
Recommendations by Usage Scenario
- Server Use (especially always-on environments)
→ ntpd or chrony are recommended. Stability and accuracy are important. - Cloud Environments, Virtual Machines, Laptops
→ chrony is the most flexible and accurate. - Simple Time Synchronization for a Single PC
→ systemd-timesyncd is sufficient.
7. Frequently Asked Questions (FAQ)
Q1. Is ntpd installed by default on Ubuntu 22.04?
A1.
No, ntpd
is not installed by default on Ubuntu 22.04. systemd-timesyncd
is enabled by default for basic time synchronization. To use ntpd
, you need to explicitly install the ntp
package.
sudo apt install ntp
After installation, it’s also recommended to disable systemd-timesyncd
to avoid conflicts.
Q2. ntpq -p
is not displaying correctly. What should I do?
A2.
Several reasons could cause this:
- Service not running: Check with
sudo systemctl status ntp
and start if necessary. - Communication with NTP server failing: Check if your firewall is blocking UDP port 123.
- Errors in the configuration file: Verify that there are no typos in
/etc/ntp.conf
.
First, check the basic operation with the following command:
ntpq -p
If the output is blank or the reach
value is 0
, there might be a problem communicating with external servers.
Q3. Should I choose ntpd or chrony?
A3.
The best tool depends on your usage environment:
- Long-running physical servers or building a local NTP server →
ntpd
is recommended for its stability. - Virtual environments, laptops, or variable network environments (Wi-Fi, etc.) →
chrony
offers higher accuracy and speed. - Simple time adjustment is sufficient →
systemd-timesyncd
can handle this easily.
Q4. What does the command ntpd -gq
do?
A4.ntpd -gq
is a command that performs a one-time synchronization with the NTP server and then exits immediately.
-g
: Allows significant time jumps to correct large discrepancies.-q
: Exits after synchronizing once (does not run as a daemon).
This command can be used to initially set the correct time if the system clock is significantly off and not being corrected by the regular ntpd
service.
Q5. Is there any benefit to specifying multiple NTP servers?
A5.
Yes, specifying multiple NTP servers provides redundancy and improves reliability. If one server fails or becomes unreachable, your system can still obtain time information from the other servers, ensuring stable synchronization.
Example configuration (/etc/ntp.conf
):
server us.pool.ntp.org iburst
server time.google.com iburst
server ntp.cloudflare.com iburst
8. Conclusion: Improve System Reliability with Stable Time Synchronization
Reaffirming the Advantages of ntpd
In Ubuntu systems, accurate time synchronization is not just a matter of convenience but a crucial element directly impacting security, troubleshooting, log management, and the accuracy of automated processes.
This article has comprehensively explained the basics of NTP (Network Time Protocol), the mechanism of time synchronization using ntpd
, installation methods, configuration customization, operation verification, and even comparisons with other tools.
Advice for Readers
The choice of which time synchronization tool to adopt in Ubuntu depends on the system’s purpose, configuration, and availability requirements.
However, the principle that “stable operation without accurate time is impossible” holds true for all environments.
- For server use and when log management is important → Properly configure
ntpd
orchrony
. - For simple use on a single PC →
systemd-timesyncd
offers an easy implementation.
The accuracy of time synchronization might go unnoticed in daily operations, but it will undoubtedly serve as a valuable reference point during troubleshooting.
We encourage you to use this article as a guide to set up the optimal time synchronization mechanism for your Ubuntu environment.