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?
-
1I take it you just want to see the time there and not actually change your computer's time to match it? – DerfK Jan 10 '11 at 20:37
-
1Yep, that's right. – John Bachir Jan 10 '11 at 20:50
4 Answers
-
Thanks! Maybe you can answer this question too http://serverfault.com/questions/220836/why-is-ntpd-not-updating-the-time-on-my-server – John Bachir Jan 10 '11 at 20:48
-
ntpq -p ntp.ubuntu.com
From man ntpq
:
...
-p Print a list of the peers known to the server as well as a summary of their state. This is equivalent to the peers interactive command.
...
Edit: The host is timing out right now. ntpq -p pool.ntp.org
will return a valid result.
- 24,204
- 8
- 77
- 99
-
2ntpdate is deprecated so it's best to get in habit of using ntpq instead. However I still use ntpdate all the time myself, old habits die hard. – Phil Hollenback Jan 10 '11 at 20:43
-
1@Phil Hollenback : ntpdate may be "deprecated", but it works. ntpq -p often does not. Possibly because ISPs are blocking it? Or because of the server configuration? – mivk Jan 02 '16 at 23:54
-
1@mivk *"Possibly because ISPs are blocking it"* This makes no sense. It's all the same NTP protocol. – Jonathon Reinhart Jan 13 '16 at 15:06
-
11@mivk @Jonathon actually, `ntpq -p` is not asking for time, it's asking for a list of peers and other vars. If the server has a `noquery` restriction it will timeout. – GnP Apr 21 '16 at 19:10
-
5`ntpq -p pool.ntp.org` times out from two of my machines, while there is no such problem with `ntpdate -q pool.ntp.org`. As said by GnP, `ntpq -p` does not do what the user expects. This incorrect answer should probably be removed. Moreover [`ntpq` cannot be installed under Debian without the associated ntp daemon](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=422347)! – vinc17 Nov 16 '16 at 13:05
-
`ntpq` is not an equivalent replacement for `ntpdate -q` - `sntp` is. While ntpq can return the same information as ntpdate (and much more) it uses a completely different protocol, and thus won't always be accessible (especially if the server software isn't ntpd). `sntp` (like `ntpdate` before it) use the ntp protocol, and will work with any ntp server. – pavon Oct 12 '21 at 22:26
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:
$ sntp -K/dev/null ntp.ubuntu.com
2021-10-12 16:01:48.425034 (+0700) -0.175372 +/- 0.128998 secs
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.
- 353
- 3
- 9