htpdate
Synchronize system time using HTTP headers
TLDR
Synchronize date and time
Perform simulation of synchronization, without any action
Compensate the systematic clock drift
Set time immediate after the synchronization
SYNOPSIS
htpdate [-46adhqrsv] [-p port] host ...
PARAMETERS
-4
Force IPv4 DNS name resolution
-6
Force IPv6 DNS name resolution
-a
Gradually correct system clock (slew mode)
-d
Print debug diagnostics to stderr
-h
Display short help message
-p port
Use specified TCP port (default 80)
-q
Query mode: print time offset, do not set clock
-r
Use HTTP POST instead of HEAD requests
-s
Set system clock silently (no output)
-v
Increase verbosity
DESCRIPTION
htpdate is a simple, lightweight tool for synchronizing the Linux system clock using the Date: HTTP header from remote web servers. It sends HTTP HEAD requests (or POST with -r) to one or more specified hosts, parses the server's reported UTC time, estimates round-trip delay, and adjusts the local clock accordingly. This makes it ideal for firewalled networks where NTP (UDP port 123) is blocked, as it uses standard HTTP/HTTPS ports (80/443).
Unlike full NTP daemons, htpdate is not designed for high precision—accuracy is typically within 1-10 seconds due to TCP latency and server clock drift—but excels for initial setup, cron jobs, or embedded systems. It supports averaging multiple servers, incremental slewing (-a), IPv4/IPv6, and query-only mode for testing. System clock updates use adjtimex(2) or settimeofday(2).
Common hosts include google.com, nist.time.gov. Always verify server time reliability, as not all include accurate Date headers.
CAVEATS
Accuracy limited to seconds due to TCP latency and server drift; not a NTP replacement. Servers may omit or falsify Date: header. Requires writable RTC/clock privileges (often root). HTTPS unsupported natively.
USAGE EXAMPLES
htpdate http://www.google.com (basic sync)
htpdate -s http://nist.time.gov https://time.nist.gov (quiet, multi-server)
htpdate -q -v -a pool.ntp.org (test slew mode)
PRIVILEGES
Requires root for clock set (-s or default); use sudo. Non-root -q mode for queries only.
HISTORY
Written by Dirk Paehlke in 2002 as a Perl script, later ported to C. Included in Debian/Ubuntu (ntpclient package) and other distros for firewall-friendly time sync. Minimal maintenance since, focused on reliability in constrained setups.


