LinuxCommandLibrary

htpdate

Synchronize system time using HTTP headers

TLDR

Synchronize date and time

$ sudo htpdate [host]
copy

Perform simulation of synchronization, without any action
$ htpdate -q [host]
copy

Compensate the systematic clock drift
$ sudo htpdate -x [host]
copy

Set time immediate after the synchronization
$ sudo htpdate -s [host]
copy

SYNOPSIS

htpdate [-dqv] [-p seconds] [-t seconds] [hostname...]

PARAMETERS

-d
    Enable debug mode, printing extra information about the process.

-q
    Be quiet; do not print any output unless an error occurs.

-v
    Be verbose; print more information.

-p seconds
    Adjust time by 'seconds' before setting it. Can be positive or negative. Defaults to 0.

-t seconds
    Set timeout to 'seconds'. The default timeout is 30 seconds.

hostname...
    One or more hostnames to query for the current time.

DESCRIPTION

htpdate is a utility to synchronize a computer's system time with the time obtained from HTTP headers of a web server. Instead of relying on NTP, it uses the 'Date:' header returned by web servers when making an HTTP request. This can be useful when direct access to NTP servers is restricted or unreliable.

htpdate is designed to be simple and lightweight. It fetches the date from the specified HTTP server and, if the difference between the server time and the local system time exceeds a certain threshold, it adjusts the system time. It supports specifying multiple servers, which it tries sequentially until it finds a server that provides a valid date.

It's important to note that while htpdate can be convenient, the time accuracy relies entirely on the accuracy of the web server's time. Web servers may not be synchronized to highly accurate time sources, so the results may not be as precise as those obtained with NTP.

CAVEATS

The accuracy of htpdate is limited by the accuracy of the web server's time. It should not be used where high time accuracy is required. Firewalls can also interfere with HTTP requests, preventing htpdate from working.

SECURITY CONSIDERATIONS

htpdate relies on the trustworthiness of the web servers it queries. A compromised web server could potentially provide incorrect time, leading to system time manipulation. Care should be taken when selecting servers to use with htpdate.

HISTORY

htpdate was created as a simpler alternative to NTP for situations where accessing NTP servers was problematic. It gained popularity in environments where network restrictions or limited resources made NTP impractical. While useful, it's been largely superseded by improved NTP implementations and the increased availability of reliable NTP servers.

SEE ALSO

ntpdate(8), date(1)

Copied to clipboard