Maintaining accurate system time is crucial for many system processes and services in a Linux environment. Network Time Protocol (NTP) is a protocol used to synchronize computer clock times in a network of computers. This article will guide you through the process of forcing a clock update using NTP on Ubuntu.
To force a clock update using NTP on Ubuntu, you can use the
ntpdate command with the desired NTP server, or stop the NTP service, use the
ntpd command with the
-gq options, and then restart the NTP service. Alternatively, for Ubuntu 18.04 and newer, you can use the
systemd-timesyncd service to force a clock update. If you require a secure method, you can use
tlsdate with a trusted server.
NTP stands for Network Time Protocol. It’s a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks. NTP is intended to synchronize all participating computers to within a few milliseconds of Coordinated Universal Time (UTC). Learn more about NTP
Before you can force a clock update, you need to ensure that NTP is installed on your Ubuntu system. You can install it using the following command:
sudo apt-get install ntp
Forcing a Clock Update Using NTP
There are several ways to force a clock update using NTP on Ubuntu. We will discuss the most common methods.
ntpdate command is a simple and straightforward way to force an immediate clock update. Here’s how you can use it:
sudo ntpdate -s time.nist.gov
In this command,
time.nist.gov is the NTP server used to fetch the current time. The
-s option tells
ntpdate to set the system time immediately.
Another method involves using the
ntpd command. Here’s the sequence of commands to execute:
sudo service ntp stop
sudo ntpd -gq
sudo service ntp start
In this sequence, the NTP service is first stopped. Then, the
ntpd -gq command is executed. The
-g option tells
ntpd to correct the time regardless of the offset (difference between the server time and the system time), and the
-q option tells
ntpd to quit immediately after setting the time. Finally, the NTP service is restarted.
For Ubuntu 18.04 and newer, you can use the
systemd-timesyncd service to force a clock update:
sudo systemctl restart systemd-timesyncd.service
This command restarts the
systemd-timesyncd service, which is responsible for time synchronization. Upon restart, the service will update the system time.
tlsdate for Secure Time Sync
If you require a secure method of updating the system time, you can use
sudo tlsdate -V -n -H encrypted.google.com
tlsdate command uses Transport Layer Security (TLS) to securely connect to a remote server and extract the remote time. The
-V option enables verbose mode,
tlsdate from attempting to set the system clock, and
-H specifies the host to connect to.
Keeping your system clock accurate is crucial for many system processes and services. This guide has shown you how to force a clock update using NTP on Ubuntu. Choose the method that suits your system and requirements, and remember to replace the NTP server with a reliable server of your choice.
NTP continuously updates the system clock by periodically synchronizing it with the NTP server. The frequency of updates depends on the configuration and network conditions, but it typically occurs every few minutes.
Yes, you can use any reliable NTP server to update the system clock. In the examples provided, we used "time.nist.gov" as an example, but you can replace it with the NTP server of your choice.
You can check the current system time using the
date command. Simply open a terminal and type
date to display the current date and time.
In most cases, the NTP service automatically keeps the system clock synchronized. However, there may be situations where a manual update is required, such as when the system time is significantly off or when troubleshooting time-related issues.
Yes, you can automate the clock update process by configuring the NTP service to run at system startup and periodically synchronize the system time. This ensures that the clock is always accurate without the need for manual intervention.