33

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?

2
  • 1
    I 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
  • 1
    Yep, that's right. Jan 10 '11 at 20:50
19

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.

6
  • 2
    ntpdate 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. 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 2 '16 at 23:54
  • 1
    @mivk "Possibly because ISPs are blocking it" This makes no sense. It's all the same NTP protocol. 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!
    – vinc17
    Nov 16 '16 at 13:05
37

You can use ntpdate to query a time server

ntpdate -q ntp.ubuntu.com

2
12

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
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.