2

From man ntpdate on a CentOS 7.2 server:

   Disclaimer:  The functionality of this program is now available in the
   ntpd program. See the -q command line option in  the  ntpd  -  Network
   Time  Protocol (NTP) daemon page. After a suitable period of mourning,
   the ntpdate program is to be retired from this distribution

From man ntpd:

   -q      Exit the ntpd just after the first time the clock is set. This
           behavior  mimics  that  of the ntpdate program, which is to be
           retired. The -g and -x options can be used with  this  option.
           Note: The kernel time discipline is disabled with this option.

This mimics the usual functionality of the ntpdate command. However, ntpdate has its own -q flag as well:

   -q      Query only - don't set the clock.

I don't see any way in the ntpd man page to perform this functionality.

Since ntpdate will eventually be retired, what is the future-compatible, preferred way to get the functionality that ntpdate -q currently provides?

3
  • Also, ntpdate appears to have been removed by default from Ubuntu between 14.04 and 16.04.
    – Wildcard
    Commented Oct 2, 2018 at 20:49
  • .What does the ntpd --version print? What OS?, please.
    – user232326
    Commented Oct 3, 2018 at 6:54
  • ping: Have you got an answer that works ?
    – user232326
    Commented Oct 6, 2018 at 2:38

2 Answers 2

2

query remote server

If what you want is to query a remote ntp server use:

# sntp 0.debian.pool.ntp.org
sntp [email protected] Sun Feb 25 21:22:25 UTC 2018 (1)
2018-10-03 04:34:02.687911 (+0400) -0.002893 +/- 0.063203 0.debian.pool.ntp.org 186.118.171.89 s3 no-leap

set ntpd time

If what you want is to set the server time:

With a recent version of ntpd:

# ntpd --version
ntpd [email protected] Sun Feb 25 21:22:55 UTC 2018 (1)

The -q option will read as this in the manual:

-q Exit the ntpd just after the first time the clock is set. This behavior mimics that of the ntpdate program, which is to be retired. The -g and -x options can be used with this option. Note: The kernel time discipline is disabled with this option.

So, after stopping the ntp daemon (service ntpd stop or systemctl stop ntp depending on your system) use this command:

# ntpd -gq

The -gq tells the ntp daemon to correct the time regardless of the offset (g) and exit immediately (q) after setting the time.

Then, restart the ntpd and check that it is working:

# ntpq -pn
4
  • Thanks, but this answers a different question. ntpdate -q does not set the time. That’s what I’m asking to mimic.
    – Wildcard
    Commented Oct 3, 2018 at 7:02
  • Is the first option sntp what you are searching for?
    – user232326
    Commented Oct 3, 2018 at 8:40
  • sntp looks about right, but it isn't available from default repositories on CentOS/RHEL or Ubuntu. So I'm sticking with ntpdate for now and I'll worry about the future deprecation/retirement when it comes.
    – Wildcard
    Commented Oct 6, 2018 at 2:44
  • @Wildcard Also found this forums.fedoraforum.org/showthread.php?260785-ntpdate-deprecated
    – user232326
    Commented Oct 6, 2018 at 4:04
1

ntpdate has been deprecated in CentOS for a very long time, but I have no idea when it's actually going to go away. With that said, you might want to take a look at the sntp package:

# sntp time.google.com
 3 Oct 01:11:30 sntp[6844]: Started sntp
2018-10-03 01:11:30.209781 (+0000) -0.000086 +/- 0.000366 secs
2018-10-03 01:11:30.221572 (+0000) -0.000130 +/- 0.000259 secs

NOTE: the two results are because both IPv4 and IPv6 addresses were queried by default.

You must log in to answer this question.

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