Linux rdate: check a time server and set the system clock

rdate is a command that fetches time from a remote time server to check it or adjust the system clock once. However, the meaning of options differs for each implementation with the same name, so you should check the manual of the installed program first. For continuous time synchronization, it is better to use a time synchronization service like chrony.

Difference between rdate and time synchronization

rdate is a tool that sends a request to a remote server when executed. Even if it sets the clock once, the command itself does not keep running to correct deviations. If you operate services sensitive to time, such as logs, scheduled tasks, or certificate verification, you need to check the status of continuous synchronization.

The examples below use OpenRdate as documented in the Ubuntu 24.04 rdate manual. The same options may mean different things in other implementations, so do not apply these examples unchanged.

Installation and Implementation Check

On Ubuntu, if you can access the package repository, install it as follows. If it says the package is not found, check the distribution version and the repository you are using.

sudo apt update
sudo apt install rdate

After installation, open the manual to check the options of the actual program. The exit key in the manual is q.

command -v rdate
man rdate

In OpenRdate, -p means it outputs the server time without changing the clock, and -s means it does not output it. In other rdate implementations, -s might mean it sets the clock. Therefore, do not guess the behavior just by the option name. In particular, with OpenRdate, running without -p can attempt to set the clock.

Check Server Time Only

The default communication method of OpenRdate is TCP port 37 of the RFC 868 time protocol. You cannot assume that a typical NTP (Network Time Protocol) server also provides RFC 868. The following example queries the NTP server of the Physikalisch-Technische Bundesanstalt (PTB) in Germany using the -n option of OpenRdate and the Simple Network Time Protocol (SNTP). Check the server usage policy and network accessibility, and if necessary, replace it with the NTP server specified by your organization.

rdate -n -p ptbtime1.ptb.de

When a normal response is received, the remote time is displayed, and the local system clock is not changed. SNTP uses UDP port 123. The OpenRdate manual notes that leap-second correction may sometimes be needed with an NTP server; if accuracy matters, check the manual’s -c option and the time source’s requirements. If there is no response, check the server address, DNS, firewall, and whether the server's service is running. You must first verify the protocol that the server actually supports, as being named a time server does not mean it supports all protocols.

Check before adjusting the clock once

If the system time suddenly shifts forward or backward, it can affect the order of logs, scheduled tasks, authentication, and running services. For systems in operation, review the reliability of the time source and the impact of changes, and ensure an appropriate time for modifications. Also, verify the current operational policy to avoid repeatedly altering a clock that is already managed by chrony or other synchronization services.

In OpenRdate, the following command attempts to set the system clock to the time of the SNTP server without -p. Administrator privileges are required, and before execution, check the server response and current time using the above query command. This example is for OpenRdate.

date
timedatectl
sudo rdate -n ptbtime1.ptb.de
date
timedatectl

If a command fails, check for errors and do not assume it succeeded. date and timedatectl help verify the local time and time zone. Just because the time zone displayed on the screen differs does not mean the clock's reference time is necessarily incorrect. Time changes cannot be easily reverted like a query, so instead of blindly resetting to previous values, synchronize with a reliable time source according to operational procedures.

Verify continuous synchronization

Running rdate just once does not configure continuous synchronization. In a systemd environment, you can check the synchronization service and clock status with the following command.

timedatectl status

That NTP service shows as active and System clock synchronized shows as synchronized are different statuses. Even if the service is running, if it cannot reach a server, it may not be synchronized. Displayed items may vary depending on the system and version.

On systems using chrony, you can check the status and time sources with chronyc tracking and chronyc sources -v. If you cannot use the commands, check the installation, service status, and the distribution's settings. In Red Hat's chrony time synchronization documentation you can see how to verify sources and synchronization status.