34

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
  • 2
    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, 2011 at 20:37
  • 2
    Yep, that's right. Jan 10, 2011 at 20:50

4 Answers 4

20

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
  • 3
    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, 2011 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, 2016 at 23:54
  • 2
    @mivk "Possibly because ISPs are blocking it" This makes no sense. It's all the same NTP protocol. Jan 13, 2016 at 15:06
  • 12
    @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, 2016 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, 2016 at 13:05
38

You can use ntpdate to query a time server

ntpdate -q ntp.ubuntu.com

2
13

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
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .