2

I would like to have a one-liner for updating the date via NTP getting the NTP-servers from the /etc/ntp.conf file. Especially because a manual command does not always work, because of firewall rules, not all servers in /etc/ntpd.conf being reachable.

service ntpd stop, ntpdate ntp1host, service ntpd start 

This would be the normal way to go. Is there a command that will allow me to force-update time via NTP without shutting down the daemon?

3
  • Why do you want to do this?
    – MattBianco
    Oct 2, 2014 at 11:20
  • 1
    If ntpd is running and functioning properly you should not need to update the time. Why do you think your ntpd is not working?
    – dfc
    Oct 2, 2014 at 16:21
  • Replace ntpdate <anyhost> with ntpd -g -q above so that you actually use ntpd's configuration to do the force update. Jun 26, 2015 at 19:24

2 Answers 2

3

This is a really, really bad idea. Let me (try to) explain.

The ntp daemon expects to control the system clock. When it starts it will jump the clock if permitted, so that the time approximates that offered by its remote time servers. Thereafter, it regularly compares local time generated by the system clock to that offered remotely, and tweaks the local clock faster or slower to keep it synchronised.

There are two levels of synchronisation:

  1. Keeping the clock accurate when compared to remote time servers
  2. Ensuring that over longer time periods the local clock can be sufficiently disciplined that even without Internet connectivity it will continue to keep approximately accurate time

If you jump the clock, or introduce a new slew by setting the clock (whether with ntpdate or manually) it will upset the long-term calculations for #2 and can potentially cause the clock to be disciplined so badly that it will lose or gain visibly significant time compared to reality. If this happens then the only real solution is to shut down ntp, delete the reference adjustment file, and hard reboot the server. Really.

If you really still want to proceed, you could try this:

ntpdate -u $(awk '$1=="server" {print $2}' /etc/ntp.conf)

But I do not recommend it under any circumstances while ntp is still running.

0

Humm... unfortunately it doesn't seems there is such feature.

This wiki page (https://support.ntp.org/bin/view/Dev/DeprecatingNtpdate) about the migration don't seem to document such feature (yet?).

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.