3

I often get large offsets when checking ntpd using ntpq -p, I generally restart the ntp daemon and it fixes the issue. I wanted to know if i can try the ntpdate <ntp-server-name> instead of restarting ntpd. Since this is a production box wanted to be sure before implementing it.

2
  • 1
    Having a large offset regularly is not normal and if configured correctly, ntpd should prevent this.
    – Sven
    Apr 10, 2018 at 11:21
  • Large offsets can be generated by ntpd itself via the kernel clock discipline if the clock is unexpectedly reset while it's running. For example, by using ntpdate or even date --set ... Apr 11, 2018 at 12:25

3 Answers 3

3

ntpdate and ntpd are different tools, but one of them helps another.

ntpdate is used to synchronize the system clock at once immediately. It takes time from a ntpd server, which has synchronized status (stratum 1 - 4).

ntpd service sets system clock softly. It can spend several hours to eliminate the lag of system clock for several minutes. All this time it has synchronized status stratum 16 - it means the system clock isn't synchronized. The service restart command service ntpd restart is used only to apply changes in its configuration file.

ntpdate is usually used to synchronize the system clock of personal computer at startup. ntpd service is usually used to synchronize the system clock of server all-time.

2
  • ntpd is often set to step the clock at system startup. Its biggest advantage over ntpdate is that it understands about clock drift and compensates for that over time. Apr 11, 2018 at 7:32
  • Please. Look for default ubuntu desktop dhcp-client config /etc/dhcp/dhclient-exit-hooks.d/ntpdate and dhcp option DHCP option 42 Network Time Protocol Servers. Apr 11, 2018 at 9:13
2

No. Citing man ntpdate:

ntpdate will decline to set the date if an NTP server daemon (e.g., ntpd) is running on the same host. When running ntpdate on a regular basis from cron as an alternative to running a daemon, doing so once every hour or two will result in precise enough timekeeping to avoid stepping the clock.

1

On various commonly-used Linux distributions (including CentOS, Debian, and Ubuntu), ntpd is started with the -g flag by default, which means it will perform a large clock step on the first adjustment if needed. So for the majority of cases, ntpdate shouldn't be needed, and restarting ntpd would be preferred.

But, as Sven commented, if ntpd has been running for a while and you still end up with a large offset, then something's wrong with your NTP setup or your network (or both).

So rather than restarting ntpd or running ntpdate, try diagnosing why you end up in this situation in the first place.

Some common issues:

  1. Not including enough peers - you should have at least 4. Read through the whole BCP draft if you have the time.
  2. Using the server with the public NTP pool instead of the newer pool directive - you should use the latter if your ntpd supports it.
  3. Using peers which are too far away or poorly connected - try to select close-by, reliable peers. Even better, augment your external peers with a local reference clock for your network. (A BeagleBone, Raspberry Pi, or LeoNTP with a GPS receiver might be a good choice, depending on your environment.)
  4. There might be other reasons why your server is struggling to keep good time, such as a kernel bug or poor hardware clock. Enabling loopstats, peerstats, and sysstats in your ntp.conf should help to track this down.

Post your configuration and the output from ntpq -np and hopefully we should be able to help you work this out.

You must log in to answer this question.

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