How can I compare an ntp server's time to my server's time?
772
I have ntpd running on a box. I want to see how the time on the box compares to the time retrieved from ntp.ubuntu.com. Is there an easy way to do this?
Actually, the command ntpq -c "rv 0 clock" ntp.ubuntu.com will return the time of the server in standard format : this is the result from ca.pool.ntp.org :
clock=d1b5aa9c.b8f9697a Wed, Jun 29 2011 9:43:56.722
There are a few different options for querying an ntp server now that ntpdate is deprecated. Which is preferred is often simply a matter of which is already installed (or easy to install) on your OS:
sntp
sntp is a tool from the ntp project, and is their recommended tool for querying remote servers:
The -K/dev/null is optional, and disables persisting information about the requests to a file. Normal users typically won't have access to this file, so without that option it will print some errors but will otherwise work.
chronyd
chronyd is an alternative ntp implementation and the default time server in recent RHEL and Ubuntu distributions.
$ chronyd -Q "server ntp.ubunutu.com iburst"
2021-10-27T21:55:49Z chronyd version 3.5 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG)
2021-10-27T21:55:49Z Disabled control of system clock
2021-10-27T21:55:53Z System clock wrong by -0.233053 seconds (ignored)
2021-10-27T21:55:53Z chronyd exiting
The -Q tells it to query the server and print results without setting the time (capital is important - lowercase will set the time!). By default it will query the servers configured in it's config file, but you can also give a config line as done above. server is used to specify a single NTP server to query, but pool and refclock could also be used. iburst configures it get an initial result more quickly.
You can use ntpdate to query a time server
ntpdate -q ntp.ubuntu.com
ntpq -p ntp.ubuntu.com
From
man ntpq
:Edit: The host is timing out right now.
ntpq -p pool.ntp.org
will return a valid result.Actually, the command
ntpq -c "rv 0 clock" ntp.ubuntu.com
will return the time of the server in standard format : this is the result from ca.pool.ntp.org :There are a few different options for querying an ntp server now that ntpdate is deprecated. Which is preferred is often simply a matter of which is already installed (or easy to install) on your OS:
sntp
sntp is a tool from the ntp project, and is their recommended tool for querying remote servers:
The
-K/dev/null
is optional, and disables persisting information about the requests to a file. Normal users typically won't have access to this file, so without that option it will print some errors but will otherwise work.chronyd
chronyd is an alternative ntp implementation and the default time server in recent RHEL and Ubuntu distributions.
The
-Q
tells it to query the server and print results without setting the time (capital is important - lowercase will set the time!). By default it will query the servers configured in it's config file, but you can also give a config line as done above.server
is used to specify a single NTP server to query, butpool
andrefclock
could also be used.iburst
configures it get an initial result more quickly.